I have a list of variables that I want to loop through:
yr2008_q110atte
yr2009_q112atte
yr2010_q112atte
yr2011_q110atte
yr2012_q110atte
As you can see, they all start with "yr" and ends with "atte", although the question number in each year is different.
So, I write the loop below:
foreach i in 2008 2009 2010 2011 2012{
tab yr`i'_*atte yr`i'_age_grp
gen yr`i'_atte = . if yr`i'*atte == 1
gen yr`i'_atte = 1 if yr`i'*atte == 1
replace yr`i'_atte = 0 if yr`i'*atte == 1
}
The first line of tabulating variables works, but starting from the second line within the loop, the yr`i'*atte condition doesn't work, as stata returns "yr2008 ambiguous abbreviation".
Any clue on how to resolve this? Thank you!
Related Posts with loop variables with * wildcard
Creating a gamma distribution function to estimate likelihoodsI have created a dataset from the following: set obs 10 gen goals=_n-1 gen alpha=1.4 gen beta=1 I …
Generating a variable based on other variableDear Profs and colleagues, I am going to generate a variable that shows how many export varieties f…
Why are my variables being omitted by Stata?I'm doing a random effects model. I have a dummy per treatment, which would be "Message", "MessageTa…
Ordered Probit: discontinuous region with missing values encountered when estimating Marginal effectDear Statalist I am using ordered probit model. While calculating the marginal effect it showing th…
Ordered logistic regression with panel data and an interaction term between two binary independent variablesHi Users, I have a panel data set covering the years 2011-18 but mainly focusing on 2015-16. I am a…
Subscribe to:
Post Comments (Atom)
0 Response to loop variables with * wildcard
Post a Comment