I am working across multiple datasets and have a list of about thirty labels that need to be renamed to slightly different label names (e.g. yesno to yes_no_dnk_nr, edul to school_list, roofl to roof_list). The variables that are associated with each label vary slightly across each dataset.
For example, in one dataset I have about thirty variables that use the label yesno and I would like to rename the label to yes_no_dnk_nr. In another dataset, I may have fifty variables that use the label yesno and want to also rename these to yes_no_dk_nr. The variables are not always the same across datasets so creating a foreach loop by listing all of the variables in each dataset would be inefficient.
Is there a simple way to identify all variables that are associated with the label yesno and then just rename the label name to yes_no_dk_nr?
I am using Stata 14. I have looked at labvalclone but the examples I have found relabel the label to the variable name rather than renaming a list of variables to a standardized label name (below)
foreach var of varlist `r(varlist)'{
2. labvalclone "`:val lab `var''" "`var'"
3. la val `var' `var'
4. }
Thank you!
Linnea
For example, in one dataset I have about thirty variables that use the label yesno and I would like to rename the label to yes_no_dnk_nr. In another dataset, I may have fifty variables that use the label yesno and want to also rename these to yes_no_dk_nr. The variables are not always the same across datasets so creating a foreach loop by listing all of the variables in each dataset would be inefficient.
Is there a simple way to identify all variables that are associated with the label yesno and then just rename the label name to yes_no_dk_nr?
I am using Stata 14. I have looked at labvalclone but the examples I have found relabel the label to the variable name rather than renaming a list of variables to a standardized label name (below)
foreach var of varlist `r(varlist)'{
2. labvalclone "`:val lab `var''" "`var'"
3. la val `var' `var'
4. }
Thank you!
Linnea
Comment