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]
RE: st: Loop
From
"Patel, Monil (DOC)" <[email protected]>
To
"[email protected]" <[email protected]>
Subject
RE: st: Loop
Date
Mon, 7 Jan 2013 14:26:21 +0000
Thanks Nick!
It works.
Again thanks for your input.
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
Sent: Monday, January 07, 2013 9:17 AM
To: [email protected]
Subject: Re: st: Loop
This doesn't look much like a loop problem to me. Try
gen nc2 = movemo + 12 * (moveyr - 2006) if adtype == 1
gen mdate = ym(moveyr, movemo) if adtype == 1
format mdate %tm
Note the typo in your
local counter=`coutner'+1
Nick
On Mon, Jan 7, 2013 at 2:04 PM, Patel, Monil (DOC) <[email protected]> wrote:
> 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.
*
* 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/
*
* 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/