-1

In my dataset I currently have the labels Male and Female within my gender variable.

As I am going to be running a regression model I would like to change this so Male and Female are recoded to appear as 0 and 1. However, I am not sure how to do this!

Any help greatly appreciated

SouthernSoul
  • 11
  • 1
  • 1

2 Answers2

0

You need to so something like this:

recode gender (X = 0) (Y = 1), gen(gender_dummy)

where X and Y are the values you want to recode. You can issue a label list to find out what the coding is.

dimitriy
  • 9,077
  • 2
  • 25
  • 50
0

You stated that your gender variable is numeric, with labels. To determine the numeric values, tabulate without labels

tab gender, nolabel

Let's assume the output reveals that gender variable is coded as male==1 and female==2. To recode that as 0 and 1, I would create a new dichotomous variable called female where female==1 and male==0.

gen female=.                     
replace female=1 if gender==2     
replace female=0 if gender==1     

If you then want to add labels to the new female variable you can do that by defining a new label and assigning it to the variable:

label define FEMALE 1 "female" 0 "male" 
label values female FEMALE

You can then test this by tabulating with and without labels:

tab female
tab female, nolabel

If you no longer want the original gender variable, you can drop it:

drop gender

You can then rename the new female variable to gender, if you'd like, but it's generally recommend that you name dichotomous variables after whatever value is coded as 1, so I'd leave it as female.

rename female gender
coip
  • 1,312
  • 16
  • 30
  • 1
    You can compress three lines into one with `gen female = gender - 1` – Nick Cox Feb 01 '15 at 00:23
  • That is a good point and it works perfectly if gender is coded as 1 for males and 2 for females (as I state in my example above), but it's not clear that is the case for the original question asker, Southern Soul. So, the reason I didn't do it that way is because I wanted to show Southern Soul how to do it using the replace command, just in case gender was coded differently (say, if males were coded as 5 and females 9--strange, I know, but just an example). – coip Feb 01 '15 at 20:22