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
Related Posts with Using loop for generate and replace
Combining Datasets and Reformatting DataHello everyone. I have a number of datasets (excel files) with data formatted as SheetName: Year1,…
log forvalueswhile Code: forvalues i = 10(10)200 { works great, and increments i linearly, is it possible to eas…
Multiple individuals per household id number: how to get household information from individual observationsI am working in a dataset that has both household and individual level variables. We have a total of…
Plotting Gamma function simultaneouslyAny possibility one could plot two different gamma distributions at the same time. …
dropping observation with a conHello all, I would like to drop certain observations from my database and I am not sure how to do so…
Subscribe to:
Post Comments (Atom)
0 Response to Using loop for generate and replace
Post a Comment