Hello All,
I would like to ask your help with my Stata problem. I am trying to do a nested foreach in a single Stata command, for example:
foreach x in x1 x2 x3{
foreach y in y1 y2 y3{
gen dummy_`y'=(`x'==1&`y'==1)
}
}
where: x1 x2 x3 are dummies =1 if they experienced economic shock in 2014 or 2015;
y1 y2 y3 are dummies for worse-off condition (after experiencing these shocks, their household condition worsen)
Essentially, what I aim to find are observations where they experienced economic shocks either in 2014 or 2015 (x1 | x2 | x3=1), and they became worse off (y1 | y2 | y3=1).
When I ran the command above, it says that "variable dummy_y1 already defined"
Any assistance greatly appreciated.
Many thanks in advance,
Christian
I would like to ask your help with my Stata problem. I am trying to do a nested foreach in a single Stata command, for example:
foreach x in x1 x2 x3{
foreach y in y1 y2 y3{
gen dummy_`y'=(`x'==1&`y'==1)
}
}
where: x1 x2 x3 are dummies =1 if they experienced economic shock in 2014 or 2015;
y1 y2 y3 are dummies for worse-off condition (after experiencing these shocks, their household condition worsen)
Essentially, what I aim to find are observations where they experienced economic shocks either in 2014 or 2015 (x1 | x2 | x3=1), and they became worse off (y1 | y2 | y3=1).
When I ran the command above, it says that "variable dummy_y1 already defined"
Any assistance greatly appreciated.
Many thanks in advance,
Christian
Comment