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
What is the difference between "stack" and "pca" ?From my understanding, it seems that pca and stack syntaxes are all about suppressing two or more va…
2SLS: Interpretation of ResultsHi - I am working with panel data (US industrials, 2000-2019) and am researching the impact of firm …
What fixed effects I should add when using triple difference in firm level?In my difference-in-difference setting (double diff), I examine the impact of anticorruption laws on…
Trying to open shapefile but Stata looks for .dbf fileHello, I am trying to open a shapefile under the name "pga.shp" that I downloaded from the US Geolo…
Is there any package for stacked event-by-event estimates ?I am reading a paper of Cengiz, 2019 about using stacked event-by-event estimates for the Difference…
Subscribe to:
Post Comments (Atom)
0 Response to loop variables with * wildcard
Post a Comment