Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: nested loop with string values
From
Claudia Rangel <[email protected]>
To
[email protected]
Subject
st: nested loop with string values
Date
Mon, 16 Dec 2013 23:45:47 -0800
Dear Stata list members
apologies for the newbie question, but I have spent two days reading
and my first attempt at a nested loop is still not working.
I have a long list of variables (i.e. ecymacnia13 ecymacnib13
ecymacnic13 ecymadnia13 ecymadnib13 ecymadnic13), which basically
identify age groups "a b...f" and income groups "a b c...j".
I am trying to generate one variable holding the income values
according to the age group for each observation on the dataset (in
variable ageflgecy: a (<34) b (35-54) c(45-64)...), and hopefully
reducing the 5 X 10 variables to just 10 income variables.
I was able to create a similar loop but the variable names contain
numbers instead of strings for the age and income groups.
This is one of my latest attempts:
tokenize "a b c d e f g h i j"
forval i =1/10 {
gen ecymani``j''13 =.
forval i =1/6{
replace ecymani``j''13 = ecyma`i'ni`j'13 if ageflgecy ==`i'
}
}
Thanks for any suggestion.
Claudia
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/