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

From |
Michael McCulloch <mm@pinest.org> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: tabulation of means, by group |

Date |
Mon, 28 Jul 2008 07:37:02 -0700 |

Thanks Svend.

The column headers are just what I need! However, I apologize I submitted my table query with only one row for simplicity. How would your approach be modified to have multiple rows? In my example below, I've added variables sex and race (black/white). So I'd like to have

row 1: mean

row 2: % female in each column

row 3: % black in each column

Many thanks...

clear

set obs 100

set seed 12358

gen age =30 + int(20*uniform())

format age %2.0f

gen income =1 + int(3*uniform())

gen group =1 + int(2*uniform())

gen sex = 1 + int(2*uniform())

lab def lab_sex 1 "Male" 2 "Female"

lab val sex lab_sex

gen race = 1 + int(2*uniform())

lab def lab_race 1 "white" 2 "black"

lab val race lab_race

Michael McCulloch wrote:

In the following simulated data, I'd like to create a table of mean age (row header) for:

each of 3 income levels (with income level the column sub-header)

within each of 2 groups (with group the column main header)

So that:

from left to right in the data area would groups 1, 2, and 3,

within each group, from left to right would be income categories

And in each cell the mean age.

Here are the data I've created:

clear

set obs 100

set seed 12358

gen age =30 + int(20*uniform())

format age %2.0f

gen income =1 + int(3*uniform())

gen group =1 + int(2*uniform())

==========================================================

It seems that you want a table with one row. The -table-

command interprets the first variable as the row variable,

so generating a variable with one value will do the trick.

That variable may even be a string variable:

generate str meanage = "Mean age"

table meanage group income , contents(mean age)

Hope this helps

Svend

________________________________________________________

Svend Juul

Institut for Folkesundhed, Afdeling for Epidemiologi

(Institute of Public Health, Department of Epidemiology)

Vennelyst Boulevard 6

DK-8000 Aarhus C, Denmark

Phone, work: +45 8942 6090

Phone, home: +45 8693 7796

Fax: +45 8613 1580

E-mail: sj@soci.au.dk

_________________________________________________________

*

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

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

- Prev by Date:
**st: exporting ereturn matrices with outreg2** - Next by Date:
**Re: st: tabulation of means, by group** - Previous by thread:
**Re: st: tabulation of means, by group** - Next by thread:
**st: Heteroscedastic Tobit** - Index(es):

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