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
Running Stata on Raspberry Pi 4B (a guide)I know this is more of a ‘geek’ idea but in case you can’t always take your laptop with you (like me…
Variable creation based on same variableHi. I need help creating a variable based on the same variable data from a different row. Basically …
* Tests of endogeneityDear all, I will please like to know which result is usually reported for test of endogeneity after…
Identifying negative and positive charge amounts across sequential idsHi. I have a problem with my medical claims data. Claims are identified by a “clmnbr” which can iden…
Plotting local variablesHi all, so my problem is the following. I am creating this difference: valore_aggiunto_`k'[1]- valo…
Subscribe to:
Post Comments (Atom)
0 Response to loop variables with * wildcard
Post a Comment