Friday, January 01, 2010

Create LaTeX table for descriptive statistics using Estout

I want to create a table of descriptive statistics. To be more specific, The table should contains 6 rows and 4 columns, something like this:
Descriptive Statistics
-----------------------------------------------------------
Cohort A Cohort B Cohort C
-----------------------------------------------------------
Urban Residence 0.263 0.313 0.264
Years of Schooling 5.585 7.280 7.592
Ethnic Majority 0.928 0.918 0.915
Want Children 0.990 0.992 0.991
Ever Pregnant 0.991 0.987 0.992
-----------------------------------------------------------
Observations 3553 2450 4694
-----------------------------------------------------------
The official document for Estout provides some clues but does not make it crystal clear. Here are the steps I followed:
  1. Generate an arbitrary variable;
  2. Run regression, separately for each cohort;
  3. Collect the results;
  4. Make the table
Here are the code:

eststo clear
gen y=uniform()
quietly regress y urban eduy han want_birth preg if cohort==1, noconstant
estadd mean
eststo d1

quietly regress y urban eduy han want_birth preg if cohort==2, noconstant
estadd mean
eststo d2

quietly regress y urban eduy han want_birth preg if cohort==3, noconstant
estadd mean
eststo d3

esttab d1 d2 d3, cells(mean(fmt(%8.3f))) label nonotes nonumber nodepvars mtitles("Cohort A" "Cohort B" "Cohort C") width(1\hsize) title(Descriptive Statistics)

1 comment:

Anonymous said...

Do you have copy writer for so good articles? If so please give me contacts, because this really rocks! :)

Counter