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
Survey data - using command svyHello, I´m using a survey data (example below). I´m trying to understand the number of individuals …
Reshape Long HelpI'm normally pretty competent when it comes to reshaping data. However, I am running into trouble he…
Multiple linear regression with specific to general approachHello everyone, I want to regress a multiple linear regression with specific-to-general approach. D…
Calculation of the "T" statistic for High minus (-) Low double sort portfolioI have a double sort portfolio results based on two variables (X and Y). I would like to calculate t…
Non-Inferiority between two groups with no differenceThe statistical analysis I am wanting to run is for a non-inferiority study design, where treatment …
Subscribe to:
Post Comments (Atom)
0 Response to Multiple conditions within loop
Post a Comment