[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: generate sum by categorical variable
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/