Hello, Stata Users!
My question might seem too simple, but I am struggling with generating new variables subject to 2 conditions. When I ran the following code, I am getting variables that satisfy only the first condition, i.e. stata is not giving the value of 0 for the second condition, but I need both conditions to be met:
foreach i of numlist 2/11 {
if b4_`i'==2 & b4_`i-1'==2 {
gen sis_bro`i'=1}
else if b4_`i'==2 & b4_`i-1'==1 {
replace sis_bro`i'=0}}
}
PS: I am generating new dummy variables within families where 1=female having a sister; 0=female having a brother. I already have b4_* variables indicating the gender of kids within families.
Would appreciate any help!
My question might seem too simple, but I am struggling with generating new variables subject to 2 conditions. When I ran the following code, I am getting variables that satisfy only the first condition, i.e. stata is not giving the value of 0 for the second condition, but I need both conditions to be met:
foreach i of numlist 2/11 {
if b4_`i'==2 & b4_`i-1'==2 {
gen sis_bro`i'=1}
else if b4_`i'==2 & b4_`i-1'==1 {
replace sis_bro`i'=0}}
}
PS: I am generating new dummy variables within families where 1=female having a sister; 0=female having a brother. I already have b4_* variables indicating the gender of kids within families.
Would appreciate any help!
Comment