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/