Announcement

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

  • Converting to string with values equal to previous numeric labels

    For all the variables in a dataset that have value labels, I would like to make those variables strings with the new values equal to the old value labels.

    As an example for one variable (though I would like to do for entire dataset at once), I have:

    Code:
    clear
    input byte gender 
    1 
    2 
    end
    
    label define gender 1 "male" 2 "female"
    label values gender gender
    and I want:

    Code:
    clear
    input str6 gender 
    "male"
    "female"  
    end
    How can I make this transformation?

    I was hoping the tostring option usedisplayformat would do this but it appears to just bypass all numeric variables with value labels.


    Thanks so much,
    Reese (Stata 14.0)

  • #2
    -decode- is more appropriate here:

    Code:
    clear
    input byte gender 
    1 
    2 
    end
    
    label define gender 1 "male" 2 "female"
    label values gender gender
    decode gender,gen(gender2)
    list,noobs nolab
    
      +------------------+
      | gender   gender2 |
      |------------------|
      |      1      male |
      |      2    female |
      +------------------+

    Comment


    • #3
      Thanks Ali! That's great

      Comment

      Working...
      X