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
How to generate a dummy variable in the dataset as attached in this post?I want to generate a dummy variable. When the name for the position of "GS" is the same for the posi…
Splitting data within one variableHello! I have a variable with data entry as follows for each observation: XXX-XXXXX-X-X. Is there a…
error for displaying a large numberHello, To merge, I needed to make a specific identifier for each row. As you can see below, for eac…
Pseudo out-of-sample forecast using loopsHello, I have tried running a code given to me to predict a pseudo out-of-sample forecast using a lo…
stripplot: Getting rid of "graphs by ___ " note in lower leftI'm using the latest version stripplot (ran ssc install stripplot today) with both the over and by o…
Subscribe to:
Post Comments (Atom)
0 Response to Using loop for generate and replace
Post a Comment