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: if in loop not working


From   Scott Merryman <[email protected]>
To   [email protected]
Subject   Re: st: if in loop not working
Date   Mon, 23 Apr 2012 09:17:02 -0500

It would appear that the local macro `s1' has not been defined, so the line:

  replace s = `s`t'' if agecat == `t'

evaluates to

  replace s = if agecat == `t'

Scott

On Mon, Apr 23, 2012 at 8:43 AM, Paula Smith <[email protected]> wrote:
> Hi,
>
> I'm having trouble with this bit of code and am wondering if anyone can help
> me. The 'if' within the loop if causing the program to stall and I'm getting
> an 'if not found' error.
>
> gen t = 20 if agecat == 1
> replace t = 5 if agecat >= 2 & agecat <= 11
> replace t = 10 if agecat == 12
> gen s = .
> gen r = .
> gen q = .
> gen p = .
>
> qui forvalues t = 1/12 {
>    replace s = `s`t'' if agecat == `t'
>    replace r = `r`t'' if agecat == `t'
>    replace q = `q`t'' if agecat == `t'
>    replace p = `p`t'' if agecat == `t'
> }
> *
> *   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/

*
*   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/


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