Hi!
I'm working with a household data set, to which I imported several individual-level variables (e.g. sex, age, ethnicity) from a corresponding data set. I reshaped the data from long to wide so that within each household ID the individual variables became sex1, sex2, sex3 etc so that I could run analyses on a household level.
I'm currently trying to create a household level ethnicity variable to essentially say if all household members = 2 then the household is a 2. This is my code thus far: (q1018 is the variable for ethnicity)
gen hhold_ethn=0
replace hhold_ethn =. if q10181==.| q10182==.| q10183==.| q10184==.| q10185==.
replace hhold_ethn =1 if q10181==1| q10182==1| q10183==1| q10184==1| q10185==1
replace hhold_ethn =2 if q10181==2| q10182==2| q10183==2| q10184==2| q10185==2
replace hhold_ethn =3 if q10181==3| q10182==3| q10183==3| q10184==3| q10185==3
replace hhold_ethn =4 if q10181==4| q10182==4| q10183==4| q10184==4| q10185==4
replace hhold_ethn =8 if q10181==8| q10182==8| q10183==8| q10184==8| q10185==8
replace hhold_ethn =87 if q10181==87| q10182==87| q10183==87| q10184==87| q10185==87
For most households they are all the same ethnicity, the prob is that I want to code households where for example q10181=1 and q10183=3 - as "mixed" and unfortunately, the code above doesn't seem to be taking that into account and just assigning the mixed households as one number or the other.
Any help on figuring this out (I've no doubt there is a very simple solution) would be greatly appreciated!
Cheers,
Maddie
I'm working with a household data set, to which I imported several individual-level variables (e.g. sex, age, ethnicity) from a corresponding data set. I reshaped the data from long to wide so that within each household ID the individual variables became sex1, sex2, sex3 etc so that I could run analyses on a household level.
I'm currently trying to create a household level ethnicity variable to essentially say if all household members = 2 then the household is a 2. This is my code thus far: (q1018 is the variable for ethnicity)
gen hhold_ethn=0
replace hhold_ethn =. if q10181==.| q10182==.| q10183==.| q10184==.| q10185==.
replace hhold_ethn =1 if q10181==1| q10182==1| q10183==1| q10184==1| q10185==1
replace hhold_ethn =2 if q10181==2| q10182==2| q10183==2| q10184==2| q10185==2
replace hhold_ethn =3 if q10181==3| q10182==3| q10183==3| q10184==3| q10185==3
replace hhold_ethn =4 if q10181==4| q10182==4| q10183==4| q10184==4| q10185==4
replace hhold_ethn =8 if q10181==8| q10182==8| q10183==8| q10184==8| q10185==8
replace hhold_ethn =87 if q10181==87| q10182==87| q10183==87| q10184==87| q10185==87
For most households they are all the same ethnicity, the prob is that I want to code households where for example q10181=1 and q10183=3 - as "mixed" and unfortunately, the code above doesn't seem to be taking that into account and just assigning the mixed households as one number or the other.
Any help on figuring this out (I've no doubt there is a very simple solution) would be greatly appreciated!
Cheers,
Maddie
Comment