Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Subtotals


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Subtotals
Date   Wed, 28 Aug 2002 11:28:35 +0100

Chris.Fergusson@sth.nhs.uk

> I run a do file which creates a table similar to the following
> 
> year total age0 ......
> 1991 123   3
> 1991  57    4
> 1991  29    3
>    .      .      .
>    .      .      .
>    .      .      .
> 1991 109    4
> 1992 129    6
> 1992  84     2
>    .      .      .
>    .      .      .
>    .      .      .
> 2000   97    5
> 
> I wist to convert this table into another table totalling 
> all columns for
> each year i.e.
> 
> Year Total Age0
> 1991 1026   23
> 1992 1247   37
> 1993 1067   19
>    .       .       .
>    .       .       .
>    .       .       .
> 2000   957    27
> 

One solution is to -collapse- the data, but that destroys 
your data structure. One solution to _that_ is to 

. preserve 
. collapse ...
. restore 

and the help for -collapse- would let you fill in the dots. 

A solution I would prefer would be 

. table year, c(sum total sum age0)

This does not create the new variables you mentioned. 
I guess that you only want those as a means to an 
end. If not, use -egen, sum()-. 

Nick 
n.j.cox@durham.ac.uk 
*
*   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/



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