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]

st: if in loop not working


From   Paula Smith <paulas@srl.cam.ac.uk>
To   statalist@hsphsun2.harvard.edu
Subject   st: if in loop not working
Date   Mon, 23 Apr 2012 14:43:16 +0100

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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index