<>
To echo Nick`s comment, consider one of the most popular segments at the
beginning of Stata ado-files:
*************
quietly count if `touse'
if `r(N)' == 0 {
error 2000
}
*************
Can you see why this -if- works and your`s does not? This one compares a
scalar value against a reference, and acts accordingly, while you tried to
compare against a vector of values. The need for your construct is obviated
by the -replace- command which implicity operates on vectors ...
HTH
Martin
-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Nick Cox
Gesendet: Sonntag, 8. März 2009 19:22
An: [email protected]
Betreff: RE: st: event history analysis for multiple response and repeated
events
In addition to Martin Weiss' suggestions, this is just to underline that
if <condition> {
}
_never_ defines a loop in Stata, as it only ever defines a block of
statements to be executed once if and only if <condition> is true
(meaning, non-zero). Whatever some alternative software you may be used
to does, that's not the Stata way.
Nick
[email protected]
fernando andrade
i am new using stata, i am having problems with this simple loop uisng
if.
gen grade=.
if cnt==484{
replace grade = 1 if SC04Q01 == 1 & SC04Q02 == 1 & SC04Q03 == 1 &
SC04Q04 == 1 & SC04Q05 == 1 & SC04Q06 == 1 & SC04Q07 == 0 & SC04Q08 ==
0 & SC04Q09 == 0 & SC04Q10 == 0 &/// SC04Q11 == 0 & SC04Q12 == 0
replace grade = 2 if SC04Q01 == 0 & SC04Q02 == 0 & SC04Q03 == 0 &
SC04Q04 == 0 & SC04Q05 == 0 & SC04Q06 == 0 & SC04Q07 == 1 & SC04Q08 ==
1 & SC04Q09 == 1 & SC04Q10 == 0 &/// SC04Q11 == 0 & SC04Q12 == 0
replace grade = 3 if SC04Q01 == 0 & SC04Q02 == 0 & SC04Q03 == 0 &
SC04Q04 == 0 & SC04Q05 == 0 & SC04Q06 == 0 & SC04Q07 == 0 & SC04Q08 ==
0 & SC04Q09 == 0 & SC04Q10 == 1 &/// SC04Q11 == 1 & SC04Q12 == 1
}
the replace commands work well without the loop, it makes the
transformations in all the data set.
but i want to restrict the transformations to only those who have a
value of 484 in cnt.
any ideas why the loop is not working
*
* 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/