Stata: How to export descriptive statistics tables?

Friday, September 25, 2009

When performing statistics analysis, the first thing you would probably do is to run descriptive statistics. Knowing how to export tables of descriptive statistics can save a considerable amount of time.

If you would like to obtain the exact results that I did, you could use the following code for your  dataset:

use http://twtcsl.org/dataset/gss2000.dta
tab race
tab race sex
sum race sex age income
tab race, gen(d)
rename d1 dwhite
rename d2 dblack
rename d3 dother
tab sex, gen(d)
rename d1 dmale
rename d2 dfemale
sum dwhite dblack dother dmale age income if !mi(age) & !mi(income)


The results:

5.png

How do we export it? You can use EDIT-COPY TABLE in stata dropdown menu, or write some code to do the work.

estpost sum dwhite dblack dother dmale age income if !mi(age) & !mi(income)
esttab using sum2.rtf, cells("mean(fmt(2)) sd(fmt(2)) min(fmt(1)) max(fmt(0))") nomtitle nonumber replace


The export table looks like this:
1.png

To obtain three digits after the decimal point, change fmt(2) to fmt(3).

If you require more advanced descriptive statistics tables, for example, if you wanted to determine age and income by race, you could use the following codes:

sort race
by race: eststo: estpost sum age income if !mi(age) & !mi(income)
esttab using grp_sum.rtf, cells("mean(fmt(2)) sd(fmt(2))") replace


This result in a neat table:
2.png
If you are unable to export tables, check this article
Stata: Export OLS regression table to Word or Excel
and install the estout package.
 
Related Posts Plugin for WordPress, Blogger...

Comments

No response to “Stata: How to export descriptive statistics tables?”
Post a Comment | Post Comments (Atom)

Post a Comment