Announcement

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

  • How to create dummy variables

    Hello,

    I have a dataset with a variable i_sex. This variable takes the value of 1 for men and 2 for women. Oi want to create another variable i_sex2 where the value for male is zero and the value for female is one.
    can you help me with this?
    thank you I’m advance.
    nest regards

  • #2
    You could try something like the following.
    Code:
    generate byte i_sex2 = i_sex - 1

    Comment


    • #3
      Don't call the new variable i_sex2 unless you keep a spectacular job with variable and value labels. Since it is 1 = F and 0 = M, might as well call the new variable sex_f or female.

      Comment


      • #4
        Naming an indicator (some people say "dummy") for the category coded 1 is really good advice. Indeed, Stata's auto dataset has been doing that with foreign long since.

        Being clear about the direction of coding always beats the opposite. I have heard too horror stories of speakers who can't remember which way gender is coded.

        Comment

        Working...
        X