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: double loops with "forvalues"
From
xueliansharon <[email protected]>
To
[email protected]
Subject
st: double loops with "forvalues"
Date
Sat, 16 Jun 2012 15:11:07 -0700 (PDT)
Dear all,
I want to do a double looping, the commands are as follows:
forvalues i=1944/1955 {
forvalues j=2106/2117 {
gen fa`i'=f`i' if fr==1
replace fa`i'=f`j' if fr==0
}
}
The purpose is to generate 12 new variables (fa1944, fa1945, fa1946, ...,
fa1955) with the following characteristics:
fa1944=f1944 if fr==1; fa1944=f2106 if fr==0
fa1945=f1945 if fr==1; fa1945=f2107 if fr==0
fa1946=f1946 if fr==1; fa1946=f2108 if fr==0
...
fa1955=f1955 if fr==1; fa1955=f2117 if fr==0
However, whenever I run this program, Stata always returns an error message
as "fa1944 already defined". Could you please tell me how I should modify
the program?
Thank you very much!
Best,
Xuelian
--
View this message in context: http://statalist.1588530.n2.nabble.com/double-loops-with-forvalues-tp7580205.html
Sent from the Statalist mailing list archive at Nabble.com.
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/