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
Metan 3 variable input, possible to standardize output?Hi all, I am doing some meta-analysis. Most of my data are in six-variable format - and Metan's def…
Grouping variables to create a master variable - possible? *Bangs Head*Hello all! My colleague and I have been banging our heads over this. I have a dataset that I am wor…
Can I use distrate for clustered data?Hello, I have data with number of health conditions entered as binary variables 1 (Yes) or 0 (No), e…
Loop renaming from labelsmy variables are named B, C, D, E,... EY (because i imported from excel), and they have labels such …
Adding a list of variables to each observationHow do I add a list of variables from a “using” file to every observation (for a list of entities) i…
Subscribe to:
Post Comments (Atom)
0 Response to Using loop for generate and replace
Post a Comment