Hi,
I have a list of variables that look as follows: max_1 max_2 max_3. All the numbers in the variables correspond to a certain colour e.g. 1==blue, 2==yellow, 3==orange.
What I want to do is:
gen blue=1 if max_1!=.
gen yellow=1 if max_2!=.
gen orange=1 if max_3!=.
and so on.
I have tried to do this with a loop as follows:
local colours "blue yellow orange"
foreach colour of local colours{
forvalues i = 1(1)3{
preserve
gen `colour'_present = 1 if max_`i'!=.
restore
}
}
however, this does not work because it keeps on looping. Is there a way around this/ or to achieve the same result?
Thanks
Related Posts with Foreach and forevalues loop
Games-Howell-Test for postestimation of anova - available in Stata?Hello everybody, I conducted an anova for 11 groups with unequal variance and assume, that I need to…
PPML estimation difficultiesHello everyone, I am currently working on my bachelor thesis and I am writing here to get some insig…
incorporating full information maximum likelihood function into the multiple regressionHi everyone, I am trying to handle missing values in a multiple regression model described below. I …
Probit regression Margins and log independent variableDear Statlist users, I am using a probit regression with an independent variable transformed into n…
Descriptive tableHello, I need some help creating a simple descriptive table. My data looks as follows: Array I w…
Subscribe to:
Post Comments (Atom)
0 Response to Foreach and forevalues loop
Post a Comment