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

RE: st: question about tables


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: question about tables
Date   Thu, 24 Jul 2003 09:36:32 +0100

Rodrigo Briceno 

> >I have a dataset that has the following structure 
> (variables are region,
> >district and persons of corresponding age in each district 
> and region):
> >
> >Region Distr  Age01  02  03.....35
> >   1     D01    23    35  45
> >   1     D02    32    30  15
> >   2     D01    28    30  15
> >   2     D02    27    30  15
> >   3     D01    21    30  15
> >   3     D02    24    30  15....
> >
> >Why kind of command can I use to tell Stata that I want a 
> table like this:
> >
> >Distr  Age01 02  03....35
> >D01    72    95  75
> >D02    73    90  45....
> >
> >Where the data are summarized according to the number 
> assigned to the
> >district and totalizing persons for each age.

Philip Ryan
 
> gen int id =_n                                              
>            /* 
> see help datatypes for your best choice of storage type */
> reshape long Age, i(id)  j(age_group, string)               
> /* string 
> option needed since age groups are "01" not "1" etc */
> table Distr age_group, c(sum Age)
> 

< Footnote with good advice about variable names > 

Alternatively, 

preserve 
collapse (sum) Age*, by(District)
list 
restore 

Nick 
[email protected] 

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index