Statalist


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

Re: st: generate sum by categorical variable


From   Nick Cox <n.j.cox@stata.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: generate sum by categorical variable
Date   Tue, 23 Sep 2008 12:36:34 -0500

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

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

Shehzad Ali wrote:

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