Hi
I am relatively new to Stata and have the following question.
I am working with DHS surveys in Stata. I have merged DHS data from 2000, 2005 and 2011. I am trying to generate variables for types of toilet facility with have numeric codes, which differ from each survey year. Thus I have to create dummies for type of toilet facility for each year and then combine them at the end to make one variable.
When I try to generate the first dummy, it works fine:
gen improved_flush_2005=1 if v116>=11&v116<=15&year==2005
replace improved_flush_2005=0 if v116>=16&year==2005
And n=9,181 which is the number of observations in 2005.
However, when I try to run the following code, the number of observations increases to 32,000, which is for the whole dataset, which is not what I want. See:
gen unimproved_toilet_facility_2005=1 if v116==21|v116==23&year==2005
replace unimproved_toilet_facility_2005=0 if v116!=21|v116!=23&year==2005
I have been reading online and I am a little confused on the responses, as it seems that the 'if' qualifier only picks up the first variable.
I would greatly appreciate it if anyone was able to provide me with some direction, as usually I do not have any issue with generating variables.
Best,
Jane
I am relatively new to Stata and have the following question.
I am working with DHS surveys in Stata. I have merged DHS data from 2000, 2005 and 2011. I am trying to generate variables for types of toilet facility with have numeric codes, which differ from each survey year. Thus I have to create dummies for type of toilet facility for each year and then combine them at the end to make one variable.
When I try to generate the first dummy, it works fine:
gen improved_flush_2005=1 if v116>=11&v116<=15&year==2005
replace improved_flush_2005=0 if v116>=16&year==2005
And n=9,181 which is the number of observations in 2005.
However, when I try to run the following code, the number of observations increases to 32,000, which is for the whole dataset, which is not what I want. See:
gen unimproved_toilet_facility_2005=1 if v116==21|v116==23&year==2005
replace unimproved_toilet_facility_2005=0 if v116!=21|v116!=23&year==2005
I have been reading online and I am a little confused on the responses, as it seems that the 'if' qualifier only picks up the first variable.
I would greatly appreciate it if anyone was able to provide me with some direction, as usually I do not have any issue with generating variables.
Best,
Jane
Comment