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!
Related Posts with Multiple conditions within loop
Homogeneity test (Hsiao test) on panel data balanced with many missing valuesDear all, I'm new on Stata community and I'm using stata 12. I'm trying to determine whether governa…
Significance levels of combined coefficientsDear Stata users, My regression looks as follows: y = x0 x1 x2 x3 x4 x5 Where x4 = x3 * dummy (ind…
Omit range of values on the x-axis in a histogramHi, I'm trying to plot a histogram of a variable for Spanish data. Since Spain was a dictatorship be…
geodist - calculating distanceHi Statalists, I have data with id (i.e. addresses), year (i.e. 2006, 2007 and 2008), devision (i.e…
How to plot regression in an intervalHi all, can any of you tell me if the below representation of regression analysis is possible in ST…
Subscribe to:
Post Comments (Atom)
0 Response to Multiple conditions within loop
Post a Comment