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
Escape character in shell commandI have a long command in a shell escape that includes semicolons. If use -#delimit ;- to allow for a…
import (nonstandard) data with incorrect formats?Dear All, I have this dataset in PDF format (the files are here Array , Array ) as follows. Array Ar…
Problem with graph export using globalsHi, I am using globals to store my file paths - all the globals are stored in a master dofile that …
interpretation of coefficient of independent variable which is measured as a % of GDPI am doing a ols regression analysis using Gini index as the dependent variable and remittance measu…
Difference-in-difference regression interpretationGood afternoon, I know there have been previous posts regarding this topic, however I first wanted …
Subscribe to:
Post Comments (Atom)
0 Response to Multiple conditions within loop
Post a Comment