Hi,
I would like to make a loop were I create 20 new variables (stretching 2001-2020) using two constrictions with if. Bellow I make an example of how I would do it manually variable by variable. How can I do this more efficient?
gen newvariable1 = 0
replace new variable1 = 1 if variable==1 & year2001
gen newvariable2 = 0
replace new variable2 = 1 if variable==1 & year2002
gen newvariable3 = 0
replace new variable3 = 1 if variable==1 & year2003
gen newvariable4 = 0
replace new variable4 = 1 if variable==1 & year2004
gen newvariable5 = 0
replace new variable5 = 1 if variable==1 & year2005
/David
0 Response to Using loop for generate and replace
Post a Comment