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 divide column totals with an output that includes 95%CIDear all, I have a dataset with two continuous variables. I had calculated the total of each column …
To convert 'blue digit ' column into 'black digit' column (string to normal variable)Hi. I am using a data set which contains more than 600,000 observations on household expenditure. T…
Graph label while using "ciplot" commandDear All, Here is my data. It is in wide form (survey data). For instance I will use Vitamin D vari…
coefplot rdrobust combinationDear STATAlists, I am trying to add on x-axes ticks and labels in order to have for each line one t…
Time seriesI use ID as a symbol for the company I use, each company has more than 1 event with different dates.…
Subscribe to:
Post Comments (Atom)
0 Response to Using loop for generate and replace
Post a Comment