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
I'm converting a date but the new date variable is all missing valuesI'm using Stata 14.2. i have a dataset with dates in a string variable e.g. 01-Apr-2018. I have used…
Difference between areg and xtset for firmxyear fixed effectDear all, I would like to find the effect of bank liquidity risk (my independent variable) on loan…
How to tell Stata not to ignore missing values in bysort: egen mean commandDear Stata-Listers, I am posting a question for the first time, so I hope I'm doing it correctly. …
How to deal with I(1) and I(0) variables in econometric analysisDear Users, I am working on a balanced panel with 50 countries observed over 19 years. My main depe…
Why weak association and wide confidence intervals?Dear All, I am interested to examine the effect of IPV (Intimate Partner Violence) on my proxy outco…
Subscribe to:
Post Comments (Atom)
0 Response to Using loop for generate and replace
Post a Comment