Chapter 5 Displaying your results with publication-quality tables with estout and outreg
Stata has two suites of functions that help produce publication-quality tables: estout and outreg2. While it is easy to copy and paste tables, this is not a best practice. You want to have your Stata scripts reduce the amounts of pointing-and-clicking. Pointing-and-clicking is highly repeative and more prone to user error. It is better to avoid doing this! Using estout or outreg2 will help you in the long-run.
5.1 Estout
Estout and its functions are a way to produce publication-quality tables of descriptive statistics or regression results. The main function will be esttab.
You can install estout by running the following ssc install command: http://repec.sowi.unibe.ch/stata/estout/index.html
Esttab is the main function in estout that provides publication-quality tables. The basics of esttab are the following:
5.1.1 Esttab Examples
Here is an example of a simple regression output comparing two models. We use eststo to store the model and use esttab to display the results.
quietly sysuse auto
eststo m1: quietly regress price weight mpg
eststo m2: quietly regress price weight mpg foreign
esttab m1 m2 (1) (2)
price price
--------------------------------------------
weight 1.747** 3.465***
(2.72) (5.49)
mpg -49.51 21.85
(-0.57) (0.29)
foreign 3673.1***
(5.37)
_cons 1946.1 -5853.7
(0.54) (-1.73)
--------------------------------------------
N 74 74
--------------------------------------------
t statistics in parentheses
* p<0.05, ** p<0.01, *** p<0.001
We can replace t-statistics with pvalues with “p”. Or, we can use “se” for standard errors, and we can use ci “ci” for confidence interval. We can add scalars to the model output as well. We can use “F” to display the overall F-statistic, “df_r” for degrees of freedom, and “rmse” for root mean squared error. We can also use “r2” for R-Squared and “ar2” for adjusted R-Squared.
quietly sysuse auto
eststo m1: quietly regress price weight mpg
eststo m2: quietly regress price weight mpg foreign
esttab m1 m2, p scalars(F df_r rmse) r2 ar2 (1) (2)
price price
--------------------------------------------
weight 1.747** 3.465***
(0.008) (0.000)
mpg -49.51 21.85
(0.567) (0.769)
foreign 3673.1***
(0.000)
_cons 1946.1 -5853.7
(0.590) (0.087)
--------------------------------------------
N 74 74
R-sq 0.293 0.500
adj. R-sq 0.273 0.478
F 14.74 23.29
df_r 71 70
rmse 2514.0 2130.8
--------------------------------------------
p-values in parentheses
* p<0.05, ** p<0.01, *** p<0.001
With the title() option, we can add a title to the table output. We can also change the model names at the top of the columns with the mtitle() option. We can move the p-values, t-statistics, or standard errors to the right of the beta coefficients with the option “wide”. We can also add a note with the addnote() option
quietly sysuse auto
eststo m1: quietly regress price weight mpg
eststo m2: quietly regress price weight mpg foreign
esttab m1 m2, title("Regression Analysis Example") p scalars(F df_r rmse) r2 ar2 mtitle("Model 1" "Model 2") wideRegression Analysis Example
----------------------------------------------------------------------
(1) (2)
Model 1 Model 2
----------------------------------------------------------------------
weight 1.747** (0.008) 3.465*** (0.000)
mpg -49.51 (0.567) 21.85 (0.769)
foreign 3673.1*** (0.000)
_cons 1946.1 (0.590) -5853.7 (0.087)
----------------------------------------------------------------------
N 74 74
R-sq 0.293 0.500
adj. R-sq 0.273 0.478
F 14.74 23.29
df_r 71 70
rmse 2514.0 2130.8
----------------------------------------------------------------------
p-values in parentheses
* p<0.05, ** p<0.01, *** p<0.001
5.1.2 Exporting into Word, Excel, or LaTex format
**Do not copy and paste! Automate!*
We can use esttab with the export options to export into an RTF (Word), Excel, or LaTex format.
5.1.2.1 Export into Excel format
If you want to use your table in Excel. Don’t copy and paste! Just add “using” after esttab and include the “.csv” file format to the file name
5.1.2.2 Export into Word format
If you want to add your table to a Word document, add “using” after esttab and include the “.rtf” file format to the file name.
5.2 Outreg2
Outreg2 is another set of functions that help produce publication-quality tables. My preference is for esttab in estout, so I will provide you with a reference to get started with outreg2 if you are interested.
5.3 Example: Mincer Equations - Replicate Tables
Important Note: Missing values are set to -1 in the CPS PUMS (public-use micro dataset). If you do not account for missing, you will have an incorrect analysis.First, let’s generate some mutually exclusive categories of interest. Recategorize Female:
gen female = .
replace female = 0 if pesex == 1
replace female = 1 if pesex == 2
label define female1 0 "Male" 1 "Female"
label values female female1Generate Union
gen union = .
replace union = 0 if peernlab == 2
replace union = 1 if peernlab == 1
label define union1 0 "Nonunion" 1 "Union"
label values union union1Our outcome of interest: Weekly Earnings - PTERNWA. Note: Documentation says that the data in pternwa imply 2 decimals, so we need to divide by 100. We will also use the variable PRERELG to flag individuals with valid earnings.
gen earnings = .
replace earnings = pternwa if prerelg==1
*Divide by 100 for decimals
replace earnings = earnings/100Generate Educational Bins
tab peeduca
gen educ = .
*High School Drop Out: from Less than 1st Grade to 12th Grade No Diploma
replace educ = 1 if peeduca >= 31 & peeduca <38
*Graduated High School or GED
replace educ = 2 if peeduca == 39
*Some College
replace educ = 3 if peeduca == 40
*AA Degree: Vocational or Academic
replace educ = 4 if peeduca == 41 | peeduca == 42
*Bachelor's Degree
replace educ = 5 if peeduca == 43
*Advanced Degree: Master's, Professional, or Doctorate
replace educ = 6 if peeduca >= 44 & peeduca <= 46
label define educ1 1 "High School Dropout" 2 "High School Graduate" ///
3 "Some College" 4 "Associates (VorA) Degree" ///
5 "Bachelor's Degree" 6 "Advanced Degree"
label values educ educ1Caveat with Generating Categorical Variables in Stata Don’t do peeduca >= 44 without peeduca <= 46 since missing values are very large. So you if do peeduca >= 44 and missing educational status is “.”, then missing observations will get categorized as an advanced degree which will be a measurement error.
Generate Potential Experience
You can use local macros for testing models
local rhs1 i.educ exp exp2
local rhs2 i.educ exp exp2 i.female
local rhs3 i.educ exp exp2 i.female i.union
local rhs4 i.educ exp exp2 i.female i.union i.hryear4
local rhs5 i.educ exp exp2 i.female i.union i.hryear4 i.peio1icd
*Add interaction between female and union
local rhs6 i.educ exp exp2 i.female##i.union i.hryear4 i.peio1icdRun our regression
reg earnings `rhs1', robust
reg earnings `rhs2', robust
reg earnings `rhs3', robust
reg earnings `rhs4', robust
reg earnings `rhs5', robust
reg earnings `rhs6', robustLinear regression Number of obs = 248,811
F(7, 248803) = 11601.57
Prob > F = 0.0000
R-squared = 0.2645
Root MSE = .72359
-------------------------------------------------------------------------------------------
| Robust
lnearnings | Coef. Std. Err. t P>|t| [95% Conf. Interval]
--------------------------+----------------------------------------------------------------
educ |
High School Graduate | .409167 .0061648 66.37 0.000 .3970841 .4212499
Some College | .4095462 .0067562 60.62 0.000 .3963043 .422788
Associates (VorA) Degree | .5171878 .0069999 73.88 0.000 .5034681 .5309075
Bachelor's Degree | .8685378 .0063983 135.75 0.000 .8559973 .8810782
Advanced Degree | 1.073213 .0069293 154.88 0.000 1.059631 1.086794
|
exp | .062107 .0004216 147.31 0.000 .0612807 .0629333
exp2 | -.0009771 7.65e-06 -127.80 0.000 -.000992 -.0009621
_cons | 5.518003 .0069875 789.70 0.000 5.504308 5.531699
-------------------------------------------------------------------------------------------
Linear regression Number of obs = 248,811
F(8, 248802) = 12342.42
Prob > F = 0.0000
R-squared = 0.3031
Root MSE = .70438
-------------------------------------------------------------------------------------------
| Robust
lnearnings | Coef. Std. Err. t P>|t| [95% Conf. Interval]
--------------------------+----------------------------------------------------------------
educ |
High School Graduate | .4156047 .0059502 69.85 0.000 .4039425 .4272668
Some College | .4408511 .0065453 67.35 0.000 .4280225 .4536797
Associates (VorA) Degree | .5596453 .0067703 82.66 0.000 .5463758 .5729149
Bachelor's Degree | .9084709 .0061978 146.58 0.000 .8963234 .9206184
Advanced Degree | 1.121183 .0067401 166.34 0.000 1.107973 1.134394
|
exp | .0613624 .0004132 148.52 0.000 .0605526 .0621722
exp2 | -.0009637 7.50e-06 -128.53 0.000 -.0009784 -.000949
|
female |
Female | -.333084 .0028429 -117.16 0.000 -.338656 -.3275119
_cons | 5.660114 .0069181 818.17 0.000 5.646555 5.673673
-------------------------------------------------------------------------------------------
Linear regression Number of obs = 248,811
F(9, 248801) = 11129.25
Prob > F = 0.0000
R-squared = 0.3040
Root MSE = .7039
-------------------------------------------------------------------------------------------
| Robust
lnearnings | Coef. Std. Err. t P>|t| [95% Conf. Interval]
--------------------------+----------------------------------------------------------------
educ |
High School Graduate | .4125402 .0059457 69.39 0.000 .4008868 .4241935
Some College | .4372733 .0065413 66.85 0.000 .4244525 .4500942
Associates (VorA) Degree | .5552335 .0067633 82.09 0.000 .5419776 .5684895
Bachelor's Degree | .9050996 .0061986 146.02 0.000 .8929506 .9172486
Advanced Degree | 1.114006 .0067622 164.74 0.000 1.100752 1.12726
|
exp | .0609065 .0004135 147.28 0.000 .060096 .061717
exp2 | -.0009571 7.50e-06 -127.69 0.000 -.0009718 -.0009424
|
female |
Female | -.3322049 .0028417 -116.91 0.000 -.3377745 -.3266354
|
union |
Union | .0886408 .0041953 21.13 0.000 .0804181 .0968635
_cons | 5.660998 .0069149 818.66 0.000 5.647445 5.674551
-------------------------------------------------------------------------------------------
Linear regression Number of obs = 248,811
F(10, 248800) = 10030.61
Prob > F = 0.0000
R-squared = 0.3049
Root MSE = .70345
-------------------------------------------------------------------------------------------
| Robust
lnearnings | Coef. Std. Err. t P>|t| [95% Conf. Interval]
--------------------------+----------------------------------------------------------------
educ |
High School Graduate | .4122138 .0059457 69.33 0.000 .4005605 .4238672
Some College | .4373993 .0065415 66.86 0.000 .424578 .4502205
Associates (VorA) Degree | .5545629 .0067628 82.00 0.000 .541308 .5678177
Bachelor's Degree | .9045909 .0061969 145.97 0.000 .8924451 .9167367
Advanced Degree | 1.113443 .0067577 164.77 0.000 1.100198 1.126688
|
exp | .0609184 .0004136 147.29 0.000 .0601077 .0617291
exp2 | -.0009573 7.50e-06 -127.69 0.000 -.000972 -.0009426
|
female |
Female | -.3321621 .0028397 -116.97 0.000 -.3377278 -.3265963
|
union |
Union | .0887879 .004192 21.18 0.000 .0805716 .0970041
|
hryear4 |
2024 | .0501524 .0028201 17.78 0.000 .044625 .0556798
|
_cons | 5.636116 .0070549 798.90 0.000 5.622289 5.649943
-------------------------------------------------------------------------------------------
Linear regression Number of obs = 248,811
F(22, 248788) = 5310.25
Prob > F = 0.0000
R-squared = 0.3349
Root MSE = .68812
-------------------------------------------------------------------------------------------------------------------
| Robust
lnearnings | Coef. Std. Err. t P>|t| [95% Conf. Interval]
--------------------------------------------------+----------------------------------------------------------------
educ |
High School Graduate | .3840322 .0059144 64.93 0.000 .3724401 .3956243
Some College | .4091063 .0065253 62.70 0.000 .396317 .4218957
Associates (VorA) Degree | .5233398 .0068026 76.93 0.000 .510007 .5366727
Bachelor's Degree | .8481448 .0063508 133.55 0.000 .8356973 .8605923
Advanced Degree | 1.0828 .0069954 154.79 0.000 1.069089 1.09651
|
exp | .0550617 .0004126 133.46 0.000 .054253 .0558703
exp2 | -.0008699 7.42e-06 -117.31 0.000 -.0008844 -.0008553
|
female |
Female | -.2669904 .0030367 -87.92 0.000 -.2729423 -.2610385
|
union |
Union | .1018213 .0042456 23.98 0.000 .0934999 .1101426
|
hryear4 |
2024 | .0511416 .0027589 18.54 0.000 .0457342 .0565491
|
prmjind1 |
NAICS 21: Mining | .4601445 .0215585 21.34 0.000 .4178905 .5023985
NAICS 23: Construction | .2414286 .0139472 17.31 0.000 .2140925 .2687648
NAICS 31-33: Manufacturing | .2237477 .0137168 16.31 0.000 .1968631 .2506322
NAICS 42,44-45: Wholesale & Retail | -.0344484 .0137914 -2.50 0.012 -.0614792 -.0074177
NAICS 22,48-49: Utilities & Transportation | .1267323 .0143908 8.81 0.000 .0985266 .1549379
NAICS 51: Information | .2449216 .0178831 13.70 0.000 .2098712 .279972
NAICS 52-53: Financial Activities | .2939349 .0142959 20.56 0.000 .2659154 .3219545
NAICS 53,55,56: Professional & Business Services | .2228786 .0138884 16.05 0.000 .1956577 .2500995
NAICS 61-62: Education & Health | -.0262834 .0136592 -1.92 0.054 -.053055 .0004882
NAICS 71-72: Leisure & Hospitality | -.1961534 .0141092 -13.90 0.000 -.223807 -.1684998
NAICS 81: Other Services | -.1098199 .015223 -7.21 0.000 -.1396565 -.0799833
NAICS 92: Public Administration | .1422022 .0142532 9.98 0.000 .1142663 .1701381
|
_cons | 5.638847 .0146119 385.91 0.000 5.610208 5.667486
-------------------------------------------------------------------------------------------------------------------
Linear regression Number of obs = 248,811
F(23, 248787) = 5081.12
Prob > F = 0.0000
R-squared = 0.3349
Root MSE = .68812
-------------------------------------------------------------------------------------------------------------------
| Robust
lnearnings | Coef. Std. Err. t P>|t| [95% Conf. Interval]
--------------------------------------------------+----------------------------------------------------------------
educ |
High School Graduate | .3841487 .0059155 64.94 0.000 .3725543 .395743
Some College | .4092612 .0065272 62.70 0.000 .396468 .4220543
Associates (VorA) Degree | .5235541 .0068043 76.94 0.000 .5102179 .5368903
Bachelor's Degree | .8481453 .0063508 133.55 0.000 .8356979 .8605928
Advanced Degree | 1.08265 .006998 154.71 0.000 1.068934 1.096366
|
exp | .0550613 .0004126 133.46 0.000 .0542527 .0558699
exp2 | -.0008699 7.42e-06 -117.31 0.000 -.0008844 -.0008554
|
female |
Female | -.2680058 .0031915 -83.97 0.000 -.2742611 -.2617506
|
union |
Union | .0964584 .0056709 17.01 0.000 .0853436 .1075732
|
female#union |
Female#Union | .0112795 .008181 1.38 0.168 -.004755 .0273139
|
hryear4 |
2024 | .0511369 .0027589 18.53 0.000 .0457294 .0565443
|
prmjind1 |
NAICS 21: Mining | .4602906 .0215562 21.35 0.000 .418041 .5025401
NAICS 23: Construction | .2417802 .0139496 17.33 0.000 .2144393 .2691211
NAICS 31-33: Manufacturing | .2239984 .0137179 16.33 0.000 .1971116 .2508852
NAICS 42,44-45: Wholesale & Retail | -.0342786 .013792 -2.49 0.013 -.0613106 -.0072466
NAICS 22,48-49: Utilities & Transportation | .1272795 .0143997 8.84 0.000 .0990564 .1555026
NAICS 51: Information | .2452513 .0178858 13.71 0.000 .2101957 .2803069
NAICS 52-53: Financial Activities | .2942334 .0142996 20.58 0.000 .2662066 .3222603
NAICS 53,55,56: Professional & Business Services | .2231206 .0138903 16.06 0.000 .1958961 .2503451
NAICS 61-62: Education & Health | -.02622 .0136591 -1.92 0.055 -.0529915 .0005516
NAICS 71-72: Leisure & Hospitality | -.1959203 .0141108 -13.88 0.000 -.2235772 -.1682635
NAICS 81: Other Services | -.1095106 .015225 -7.19 0.000 -.1393512 -.07967
NAICS 92: Public Administration | .1426441 .0142568 10.01 0.000 .1147012 .1705869
|
_cons | 5.639084 .0146121 385.92 0.000 5.610445 5.667723
-------------------------------------------------------------------------------------------------------------------
Use esttab for formatted results: esttab documentation.
local rhs4 i.educ exp exp2 i.female i.union i.hryear4
local rhs5 i.educ exp exp2 i.female i.union i.hryear4 i.peio1icd
*Add interaction between female and union
local rhs6 i.educ exp exp2 i.female##i.union i.hryear4 i.peio1icdUse est clear to clear out your prior estimates.
We use eststo to save a model to compare it to another.
Output the results
esttab, title (Mincer Equation) r2 se noconstant star(* .10 ** .05 *** .01) ///
b(%10.3f) drop (*peio1icd) wide label.Mincer Equation
-------------------------------------------------------------------------------------
(1) (2) (3)
OLS1 OLS2 OLS3
-------------------------------------------------------------------------------------
High School Gr~e 0.412*** (0.006) 0.384*** (0.006) 0.384*** (0.006)
Some College 0.437*** (0.007) 0.409*** (0.007) 0.409*** (0.007)
Associates (Vo~e 0.555*** (0.007) 0.523*** (0.007) 0.524*** (0.007)
Bachelor's Deg~e 0.905*** (0.006) 0.848*** (0.006) 0.848*** (0.006)
Advanced Degree 1.113*** (0.007) 1.083*** (0.007) 1.083*** (0.007)
exp 0.061*** (0.000) 0.055*** (0.000) 0.055*** (0.000)
exp2 -0.001*** (0.000) -0.001*** (0.000) -0.001*** (0.000)
Female -0.332*** (0.003) -0.267*** (0.003) -0.268*** (0.003)
Union 0.089*** (0.005) 0.102*** (0.005) 0.096*** (0.007)
HRYEAR4=2024 0.050*** (0.003) 0.051*** (0.003) 0.051*** (0.003)
NAICS 11: Agri~e 0.000 (.) 0.000 (.)
NAICS 21: Mining 0.460*** (0.022) 0.460*** (0.022)
NAICS 23: Cons~n 0.241*** (0.014) 0.242*** (0.014)
NAICS 31-33: M~g 0.224*** (0.014) 0.224*** (0.014)
NAICS 42,44-45~a -0.034** (0.014) -0.034** (0.014)
NAICS 22,48-49~n 0.127*** (0.015) 0.127*** (0.015)
NAICS 51: Info~n 0.245*** (0.017) 0.245*** (0.017)
NAICS 52-53: F~e 0.294*** (0.014) 0.294*** (0.014)
NAICS 53,55,56~B 0.223*** (0.014) 0.223*** (0.014)
NAICS 61-62: E~h -0.026* (0.014) -0.026* (0.014)
NAICS 71-72: L~i -0.196*** (0.014) -0.196*** (0.014)
NAICS 81: Othe~s -0.110*** (0.015) -0.110*** (0.015)
NAICS 92: Publ~n 0.142*** (0.015) 0.143*** (0.015)
Female # Union 0.011 (0.009)
Constant 5.636*** (0.007) 5.639*** (0.015) 5.639*** (0.015)
-------------------------------------------------------------------------------------
Observations 248811 248811 248811
R-squared 0.305 0.335 0.335
-------------------------------------------------------------------------------------
Standard errors in parentheses
* p<.10, ** p<.05, *** p<.01