Statalist


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

RE: st: help with bys


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: help with bys
Date   Thu, 28 Aug 2008 21:49:17 +0100

Note that -egen, sum()- is now documented as -egen, total()- following
the great renaming of Stata 9. -egen, sum()- will still work. 

Nick 
n.j.cox@durham.ac.uk 

Austin Nichols

You might try
egen nvisits = sum(visit>=0 &visit<999), by(studyid)
or am I misunderstanding the desideratum?

On Thu, Aug 28, 2008 at 1:01 PM, Ziad El-Khatib <ziad.khatib@gmail.com>
wrote:

> I am dealing with cohort data for patients followed over different
> visits, before starting treatment (coded -1) then on different time
> points coded as 0, 2, 4, 8, 12, 20, 24, 36, 52, 78 and 104, also
> number 999 will be used if it was an unexpected visit to clinic.
>
> Not all patients came to all visits, so I am using -bys- command
> (pasted below) to calculate total number of visits, excluding codes -1
> and 999.
> The command below is still calculating all visits by living . value if
> visit=-1 or visit=999
>
> bys studyid: gen nvisits = _N if visit>=0 &visit<999

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



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