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

  • Preserving value labels while recoding?

    I am recoding value labels from numeric to missing values. So a 9 value in some variables is recoded to .a. A 10 value in some variables is recoded to .b etc.

    I have found several commands to do this from mvdecode to replace, but none that preserve the value label. Currently all my 10 values have the label "Don't Know/Refused." I want to keep this label, but still recode the 10 value to .b. I don't want to rewrite all the labels for my variables since there are many of them, each with specific labels.

    How could I either: (1) Recode the values for a variable while preserving the value label. Or (2) Label all .a, .b etc. missing values with the same label?
    Last edited by Daniel Ram; 10 Oct 2019, 11:08. Reason: label

  • #2
    You can do something like this.

    foreach x in lblname1 lblname2 lblname3 {
          label define `x' .b "Don't know refused" , modify
    so that the existing value label definitions are left as they were and you are consistently adding a new value label.

    What's key here -- although it's widely puzzling the first time you meet it -- is that Stata separates the definition of value labels and their association with variables.

    If it is easier you can

    loop over variables
    ---- look up its value labels
    ---- define a new value label

    Note that there is no harm in issuing the same definition twice or more.


    • #3
      Also, see elabel from SSC and the examples here.

      Last edited by daniel klein; 11 Oct 2019, 06:44.