Hi Maarten,
You did kindly answer to this query before, i meant to confirm if i
want to calculate the cumulative value for first 6 visits only, would
the command be:
bys id (visitn) : gen cumulad = ///
sum(pillmissed)/sum(pillspres) * 100, if visitn>=1&visitn<=6
Thank you in advance and best regards
ziad
On Wed, Jan 30, 2008 at 12:04 AM, Maarten buis <[email protected]> wrote:
> --- Ziad El-Khatib <[email protected]> wrote:
> > Question how to calculate variable representing cumulative value
> > 'cumulad'
> >
> > = [(total n pillmissed per patient at all visits) / (total n
> > pillspres at all visits)] * 100
>
> The trick is to combine -bys- with the -sum- function. -bys id
> (visitn)- does whatever folows the : for each person separetely and the
> (visitn) ensures that within each person the cases are ordered by
> visitn. The -sum- function gives you the cumulative sum. So combining
> the two gives you:
>
> *-------------- begin example ------------------
> drop _all
> input long id visitn pillspres pillmissed
>
> 1001 1 30 2
> 1001 2 20 5
> 1001 6 50 1
> end
>
> bys id (visitn) : gen cumulad = ///
> sum(pillmissed)/sum(pillspres) * 100
>
> list
> *--------------- end example --------------------
> (For more on how to use examples I sent to the Statalist, see
> http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )
>
> Hope this helps,
> Maarten
>
> -----------------------------------------
> Maarten L. Buis
> Department of Social Research Methodology
> Vrije Universiteit Amsterdam
> Boelelaan 1081
> 1081 HV Amsterdam
> The Netherlands
>
> visiting address:
> Buitenveldertselaan 3 (Metropolitan), room Z434
>
> +31 20 5986715
>
> http://home.fsw.vu.nl/m.buis/
> -----------------------------------------
>
>
>
> ___________________________________________________________
> Support the World Aids Awareness campaign this month 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
*
* 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/