Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: if in loop not working


From   Scott Merryman <scott.merryman@gmail.com>
To   statalist@hsphsun2.harvard.edu
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 <paulas@srl.cam.ac.uk> 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index