Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Renaming/replacing label names

    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

  • #2
    No user written additions needed, but if you are interested, you may have a look at labelrename (SJ) and labren (labutil2, SSC) besides already mentioned labvalclone. The former two will automate the steps shown below.

    Here is the principle

    Code:
    label copy yesno yes_no_dkn_nr
    ds , has(vallabel yesno)
    label values `r(varlist)' yes_no_dkn_nr
    label drop yesno
    Best
    Daniel

    Comment

    Working...
    X