Bookmark and Share

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   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Loop
Date   Mon, 7 Jan 2013 14:17:28 +0000

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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index