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
ttest two group mean-comparasion test: How big should be the difference between the variances to considering unequal test?I am testing the association of some antibodies with different symptoms. This is the same group of p…
Multilevel Modelling - Variance PartitioningDear Stata-listers, I hope you are all doing well. Before I ask my question, let me provide a brie…
Command to list households with multiple heads/without heads in a survey dataBelow is a extract data from a survey conducted for various households within a community, please wh…
Deleting rows with NAsDear Statalists, I would like to delete rows where are only 7 real values and the rest is NA, does a…
-teffects- detecting "non-integers", from a variable that has only positive valuesHello, I am using teffects to analyze the effect of individual patient variables on hospital length …
Subscribe to:
Post Comments (Atom)
0 Response to Using loop for generate and replace
Post a Comment