Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Re: Loop syntax


From   Janet Hill <[email protected]>
To   [email protected]
Subject   Re: st: Re: Loop syntax
Date   Wed, 26 Mar 2008 21:10:40 +0000 (GMT)

Vladimir, Nick, Rajesh & Johannes,
Many thanks for your advice. It is so nice to use a list like this where you are not castigated for your ignorance - especially when I missed an earlier thread.
Janet



----- Original Message ----
From: Vladimir Vakhitov <[email protected]>
To: [email protected]
Sent: Wednesday, 26 March, 2008 6:10:47 PM
Subject: Re: st: Re: Loop syntax

Janet,

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'

However, I think the other solutions proposed here are better, and I
just wanted to make a comment on the proper syntax of your command.

Vladimir.



2008/3/26, Janet Hill <[email protected]>:
> I have some results on 236 patients and each patient has 57 recordings stored in a single variable t. I am trying to count how many of these patients have a score of t>0.. I tried the following code:
>
>  gen tcount=0
>  forvalues i=1/236{
>     forvalues j=1/57{
>     if patient==`i' & t>0 {
>     then tcount==tcount+1
>     continue
>  }
>  }
>  }
>
>  but the value of tcount never changes from 0.
>
>  Could somebody please explain the correct syntax.
>  Thanks,
>  Janet
>
>
>
>
>       ___________________________________________________________
>  Rise to the challenge for Sport Relief with Yahoo! For Good
>
>  http://uk.promotions.yahoo.com/forgood/
>
>
>  *
>  *   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/
>


-- 
__________________
Volodymyr Vakhitov
[email protected]
*
*   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/





      __________________________________________________________
Sent from Yahoo! Mail.
More Ways to Keep in Touch. http://uk.docs.yahoo.com/nowyoucan.html


*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index