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
Generating a new variable from one variable and part of anotherHello, I am looking to create a variable for the total health expenditure for females. I currently h…
Stata shows "wrong" valueHey, I have a dta file with several variables. The properties of the variables in the dta file are …
Using predicted variables from principal component analysis (PCA) for an exploratory factor analysis (EFA)Hello everybody, as described in my topic, I want to use predicted variables from PCA for an EFA. …
In a fixed effects logit regression does Stata only drop observations that have no variation in the outcome variable? Or also the controls?I have a 3 wave panel of children's height and weight and parents employment or unemployment (binary…
Difficulty in stata codesI have three dta files for three sectors of an economy (and these are the only three sectors that co…
Subscribe to:
Post Comments (Atom)
0 Response to Using loop for generate and replace
Post a Comment