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 new group variable in Panel DataHi everyone! I was wondering if someone could lend a hand. I have panel data on firms board of dir…
Pairing geographic information of companies industry wise and year wise to compute distanceHi, I have unbalanced panel data set of around 2000 companies over 40 years. I have to calculate av…
Saving residuals after xtmixedDear all, I can't find out how to store the estimated correlation after xtmixed. I run: xtmixed y …
Syntax for Multilevel Latent Profile Analysis - Creating teacher profilesDear Statalisters, I want to identify profiles of (early childhood) teachers in our data based on 5…
looping by a specific variableHi everyone. I generated the following Code: egen firmlevel=group(CompanyID AnnualReportYear) And…
Subscribe to:
Post Comments (Atom)
0 Response to loop variables with * wildcard
Post a Comment