Statalist


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

Re: st: generate sum by categorical variable


From   "Eva Poen" <eva.poen@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: generate sum by categorical variable
Date   Tue, 23 Sep 2008 17:49:07 +0100

Shehzad,

egen total_weeks = total(weeks), by(stratum)

HTH,
Eva

2008/9/23 Shehzad Ali <sia500@york.ac.uk>:
> Hi,
>
> I have an individual patient level data with two variables of interest, one
> is the number of weeks spent by each patient in the study (values between 1
> and 52) and other being stratum they belong to (values between 1 and 3). I
> want to generate a new variable (total_weeks) that summarises the total
> number of weeks spent by each stratum. So the new variable will have 3
> values only, one for each stratum. I can obviously use -sum- and -r(sum) to
> generate separate variables by strata but I was wondering there must be a
> quicker way of doing it in one line. Can you advise please?
>
> Thank you,
>
> Shehzad
*
*   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