RE: st: Re: Loop syntax

 From "Rajesh Tharyan" To Subject RE: st: Re: Loop syntax Date Wed, 26 Mar 2008 16:29:56 -0000

```Hi,

I suppose you want to count for each patient how many t's are greater than
zero ?? The proposed solution

. count if t >0 & t<.
(saved in r(N))

works only if there is one observation per patient.

The following will give you how many t>0 for each patient

tabstat  patient if t>0, statistics( count ) by(patient) columns(variables)

hope this helps
Rajesh

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Johannes Geyer
Sent: 26 March 2008 16:05
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: Re: Loop syntax

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
}

I think a loop is unnecessary here  - you just want to count, right? There
are many solutions, e.g.

count if t >0 & t<.

(saved in r(N))

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/

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