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
xtpoisson fe, Hausman and Goodness of FitHi everyone! I am currently working on my Masters' thesis, I'm working with Poisson Fixed Effects b…
SVYSET Specification for 2-Level HLM ModelHello, Good morning, sorry this is a repost of my previously unanswered question -- I am adding exp…
Changing the colour of individual markers in twoway scatter graphHello Specifically I am using serrbar which I understand has the same options as graph twoway. I ha…
Merging two datasetsHi, I have to merge two datasets for my dissertation project. I am looking at police numbers and cri…
Including squared variables in logistic regression change direction of relationship. Why?Hello everyone, I have a logistic regression with an extensive set of control variables. My depende…
Subscribe to:
Post Comments (Atom)
0 Response to Multiple conditions within loop
Post a Comment