Announcement

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

  • Camila Plaza
    started a topic Relabeling encoded string variables

    Relabeling encoded string variables

    hi everyone,
    I am having some issues with my string variables. I have a gender string variable which has three options: "0", "M", "W"
    (M = male, W= female, 0 = missing)
    I encoded the variable so that I could get rid of the string and create a Dummy using:

    encode geschlecht, gen(gender)

    Once I do that, however it automatically gives me the labels

    (No of Observations)
    1 (= "0") 4,349
    2 (= "M") 125,466
    3 (= "W") 135,793

    Once i drop the "0" and change them to missing I have the following

    (No of Observations)
    2 (= "M") 125,466
    3 (= "W") 135,793

    and I try to recode gender so that Males have the code 0 and Females the code 1 using
    recode gender (2=0) (3=1)

    it works but then my issue is that the labels don't budge. So instead I have something like this:

    0 125,466
    0 135,793

    I want to achieve the following:

    (No of Observations)
    0 (= "M") 125,466
    1 (= "W") 135,793

    please help!

  • Nick Cox
    replied
    You can fix this with recode, but it's perhaps more helpful long run to explain to you and others how encode could have been used.


    Code:
    label def female 1 "W" 0 "M" 
    encode geschlecht, gen(female) label(female)
    So, just tell encode what you want the new values and labels to be. Note that here I used female as variable name to indicate which gender is 1; this is really good practice and makes explanations easier. If you think about it, you will see that Stata's auto data uses the same principle.

    The other values in the original will be encoded too; you can just ignore them if that is what you want (but also watch out for ethical issues here).

    Leave a comment:

Working...
X