Announcement

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

  • Replace value while keeping original label

    Hi everyone,

    I would like to replace the value of X1 (SN1) by X2 (SN2) while keeping the original value label of X1 (SN1).
    For example:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long SN1 float SN2
      1   1
      1   1
     61 121
    129  10
     83 490
    end
    label values SN1 SN1
    label def 
    SN1
    1 "__NA__", modify label def
    SN1
    61 "Frank Steinmeier", modify label def
    SN1
    83 "Helene Fischer", modify label def
    SN1
    129 "Merz", modify
    here I would like to : replace SN1 = 121 if SN1 == 61 while keeping the label "Frank Steinmeier". Ultimately I would like to do it for all values automatically. Replacing SN1 by SN2 while keeping the value labels of SN1.

    Many Thank for all ideas.

    Best, Jay

  • #2
    You don't have to replace the values of SN1 with the values of SN2, you can simply copy the value labels of SN1 to SN2 like this.
    Code:
    labmask SN2, values(SN1) decode

    Comment


    • #3
      labmask is community-contributed software, either from SJ or SSC (as part of the labutil package). I agree that this is the most convincing tool here.

      Best
      Daniel

      Comment

      Working...
      X