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

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: Re: Loop syntax |

Date |
Wed, 26 Mar 2008 17:00:33 -0000 |

That -sum()- is better as -total()-. The old -egen- function -sum()- is still there, but no longer documented. -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox Sent: 26 March 2008 16:15 To: statalist@hsphsun2.harvard.edu Subject: RE: st: Re: Loop syntax You can count occurrences of t > 0 separately by patient. egen tcount = sum(t > 0), by(patient) Then counting patients, not recordings, is possible e.g. by tagging, say egen tag = tag(patient) count if tag & tcount For much more detail, see the thread started on 18 March by Daniel McNeil. Bill Gould gave the first principles answer, while I gave an -egen- answer. They are complementary. Nick Johannes Geyer 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)) * * 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/

**References**:**st: Re: Loop syntax***From:*Janet Hill <janethill73@yahoo.co.uk>

**Re: st: Re: Loop syntax***From:*Johannes Geyer <JGeyer@diw.de>

**RE: st: Re: Loop syntax***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

- Prev by Date:
**st: RE: Obs per Group for xtregar** - Next by Date:
**Re: st: Re: Loop syntax** - Previous by thread:
**RE: st: Re: Loop syntax** - Next by thread:
**RE: st: Re: Loop syntax** - Index(es):

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