> gen tcount=0
> forvalues i=1/236{
> forvalues j=1/57{
> if patient==`i' & t>0 {
> then tcount==tcount+1
> continue
> }
> }
> }
One question was, why this loop did not work. Vladimir gave the following
answer:
> Talking just on a syntax matter, -then tcount==tcount+1- is incorrect.
> If you need just a number at the end, announce a local first before
> the loop and then increment this local within the loop:
> local tcount=0
> forvalues <...> {
> if <...> {
> local ++tcount
> }
> }
< di `tcount'
I understand that this (a local) is more efficient than creating a
variable but I cannot see the mistake. I guess the loop does not work as
it is expected because "if" is used as a command and not as a qualifier:
http://www.stata.com/support/faqs/lang/ifqualifier.html .
The loop would look like this if you used "if" as a qualifier:
local tcount=0
forvalues i=1/236{
forvalues j=1/57{
local ++tcount if patient==`i' & t>0
continue
}
}
}
--
@Nick: What is the difference between -total()- and -sum()- that makes the
latter better than the other?
Johannes
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/