# recode a categorical variable

#### belfagor71

##### New Member
Hi there!

I am working with secondary data and I would like to recode some of the variables.
For example I have the variable male where 0 = female and 1 = male. Since I have many other categorical variables, it gets sometimes confusing to always read 0 and 1. Because of that, I would like to recode this variable as 0 =female and 1 = male.
I have looked on internet and I tried several commands but it seems not to work.
For example:

recode male (0 = female) (1 = male)
unknown el female in rule

Or, as I read somewhere else, I tried:

I first created a new variable
. generate male2 =.
(445943 missing values generated)

and then tried to code it

replace male2 = male if(male == 1)

but while it seems to work for male does not work for female

. replace male2 = female if (male ==0)

Any guess?

Thanks a lot!

belfagor

#### divishoot

##### New Member
well it's been a while since you posted this q but it might still be relevant so...
gen male2=(male==1)
this should create a new binary var which will have 1 for male and 0 for females.

if you don't want to have a new var then try
replace male=male+1
replace male=0 if male==2
this will turn fem's to 0 and males to 1

#### bukharin

##### RoboStataRaptor
It sounds like you want to label the variable's values rather than recode it:

Code:
label define male 0 "Female" 1 "Male"
label values male male