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: Loop
From
"Patel, Monil (DOC)" <[email protected]>
To
"[email protected]" <[email protected]>
Subject
st: Loop
Date
Mon, 7 Jan 2013 14:04:49 +0000
Dear All:
I am trying to loop the following:
gen nc1=1 if (movemo==1 & moveyr==2006) & adtype==1
replace nc1=2 if (movemo==2 & moveyr==2006) & adtype==1
replace nc1=3 if (movemo==3 & moveyr==2006) & adtype==1
replace nc1=4 if (movemo==4 & moveyr==2006) & adtype==1 .......
replace nc1=82 if (movemo==10 & moveyr==2012) & adtype==1
replace nc1=83 if (movemo==11 & moveyr==2012) & adtype==1
using this loop
gen nc=0
local counter=0
local month=0
local year=2006
while `counter'<=83{
while `year'<=2012{
while`month'<=12{
replace nc=`counter' if (movemo==`month' & moveye==`year') & adtype==1
local month =`month' +1
local year= `year' +1
local counter=`coutner'+1
}
}
}
The loop does seem to run. Any input is appreciated.
Thanks
Monil
*
* 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/