esttab is a wrapper for estout. Its syntax is much simpler than that of estout and, by default, it produces publication-style tables that display nicely in Stata's results window. The basic syntax of esttab is:
esttab [ namelist ] [ using filename ] [, options estout_options ]
The procedure is to first store a number of models and then apply esttab to these stored estimation sets to compose a regression table. The main difference between esttab and estout is that esttab produces a fully formatted right away. Example:
. sysuse auto, clear (1978 Automobile Data) . eststo: regress price weight mpg Source | SS df MS Number of obs = 74 -------------+---------------------------------- F(2, 71) = 14.74 Model | 186321280 2 93160639.9 Prob > F = 0.0000 Residual | 448744116 71 6320339.67 R-squared = 0.2934 -------------+---------------------------------- Adj R-squared = 0.2735 Total | 635065396 73 8699525.97 Root MSE = 2514 ------------------------------------------------------------------------------ price | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- weight | 1.746559 .6413538 2.72 0.008 .467736 3.025382 mpg | -49.51222 86.15604 -0.57 0.567 -221.3025 122.278 _cons | 1946.069 3597.05 0.54 0.590 -5226.245 9118.382 ------------------------------------------------------------------------------ (est1 stored) . eststo: regress price weight mpg foreign Source | SS df MS Number of obs = 74 -------------+---------------------------------- F(3, 70) = 23.29 Model | 317252881 3 105750960 Prob > F = 0.0000 Residual | 317812515 70 4540178.78 R-squared = 0.4996 -------------+---------------------------------- Adj R-squared = 0.4781 Total | 635065396 73 8699525.97 Root MSE = 2130.8 ------------------------------------------------------------------------------ price | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- weight | 3.464706 .630749 5.49 0.000 2.206717 4.722695 mpg | 21.8536 74.22114 0.29 0.769 -126.1758 169.883 foreign | 3673.06 683.9783 5.37 0.000 2308.909 5037.212 _cons | -5853.696 3376.987 -1.73 0.087 -12588.88 881.4934 ------------------------------------------------------------------------------ (est2 stored) . esttab -------------------------------------------- (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 . eststo clearCode
The eststo command is used in this example to store the
regression models. Models stored by eststo are automatically
picked up by esttab (the command eststo clear
on the last line removes
the models from memory). An alternative would be to use Stata's official
estimates store
as in the following example:
. sysuse auto, clear (1978 Automobile Data) . regress price weight mpg (output omitted) . estimates store model1 . regress price weight mpg foreign (output omitted) . estimates store model2 . esttab model1 model2 -------------------------------------------- (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 . estimates clearCode
The default of esttab is to display raw point estimates along with t-statistics and to print the number of observations in the table footer. To replace the t-statistics by, e.g., standard errors and add the adjusted R-squared type:
. sysuse auto, clear (1978 Automobile Data) . eststo: regress price weight mpg (output omitted) . eststo: regress price weight mpg foreign (output omitted) . esttab, se ar2 -------------------------------------------- (1) (2) price price -------------------------------------------- weight 1.747** 3.465*** (0.641) (0.631) mpg -49.51 21.85 (86.16) (74.22) foreign 3673.1*** (684.0) _cons 1946.1 -5853.7 (3597.0) (3377.0) -------------------------------------------- N 74 74 adj. R-sq 0.273 0.478 -------------------------------------------- Standard errors in parentheses * p<0.05, ** p<0.01, *** p<0.001Code
The t-statistics can also be replaced by p-values (option p
),
confidence intervals (option ci
), or any
parameter statistics contained in the estimates (see the
aux()
option).
Further summary statistics options are, for example,
pr2
for the pseudo R-squared and
bic
for Schwarz's information criterion. Moreover, there
is a generic scalars()
option to include any other scalar statistics
contained in the stored estimates. For instance, to print p-values and
add the overall F-statistic and information on the degrees of freedom, type:
. esttab, p scalars(F df_m df_r) -------------------------------------------- (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 F 14.74 23.29 df_m 2 3 df_r 71 70 -------------------------------------------- p-values in parentheses * p<0.05, ** p<0.01, *** p<0.001 . eststo clearCode
To display standardized coefficients and suppress the t-statistics type:
. sysuse auto, clear (1978 Automobile Data) . eststo: regress price weight mpg (output omitted) . eststo: regress price weight mpg foreign (output omitted) . esttab, beta not -------------------------------------------- (1) (2) price price -------------------------------------------- weight 0.460** 0.913*** mpg -0.097 0.043 foreign 0.573*** -------------------------------------------- N 74 74 -------------------------------------------- Standardized beta coefficients * p<0.05, ** p<0.01, *** p<0.001 . eststo clearCode
The wide
option arranges point estimates and t-statistics beside
one another instead of beneath one another:
. sysuse auto, clear (1978 Automobile Data) . eststo: regress price weight mpg (output omitted) . eststo: regress price weight mpg foreign (output omitted) . esttab, wide ---------------------------------------------------------------------- (1) (2) price price ---------------------------------------------------------------------- weight 1.747** (2.72) 3.465*** (5.49) mpg -49.51 (-0.57) 21.85 (0.29) foreign 3673.1*** (5.37) _cons 1946.1 (0.54) -5853.7 (-1.73) ---------------------------------------------------------------------- N 74 74 ---------------------------------------------------------------------- t statistics in parentheses * p<0.05, ** p<0.01, *** p<0.001 . eststo clearCode
esttab has sensible default settings for numerical display formats.
For example, t-statistics are printed using two decimal places and R-squared
measures are printed using three decimal places. For point estimates and,
for example, standard errors an adaptive display format is used where the
number of displayed decimal places depends on the scale of the statistic to
be printed (the default format is a3
; see below).
The format applied to a certain statistic can be changed by adding the appropriate display format specification in parentheses. For example, to increase precision for the point estimates and display p-values and the R-squared using four decimal places, type:
. sysuse auto, clear (1978 Automobile Data) . eststo: regress price weight mpg (output omitted) . eststo: regress price weight mpg foreign (output omitted) . esttab, b(a6) p(4) r2(4) nostar wide ---------------------------------------------------------------- (1) (2) price price ---------------------------------------------------------------- weight 1.746559 (0.0081) 3.464706 (0.0000) mpg -49.51222 (0.5673) 21.85360 (0.7693) foreign 3673.060 (0.0000) _cons 1946.069 (0.5902) -5853.696 (0.0874) ---------------------------------------------------------------- N 74 74 R-sq 0.2934 0.4996 ---------------------------------------------------------------- p-values in parentheses . eststo clearCode
Available formats are official Stata's display formats, such as
%9.0g
or %8.2f
(see help format
).
Alternatively, as is illustrated in the example above, a fixed format can
be requested by specifying a single integer indicating the desired number of decimal
places. Furthermore, an adaptive format a#
may be specified, where #
determines the minimum
number of "significant digits" to be printed (#
should be an integer between 1 and 9)
(see the Numerical formats section in the help file).
To use variable labels and add some titles and notes, e.g., type:
. sysuse auto, clear (1978 Automobile Data) . eststo: regress price weight mpg (output omitted) . eststo: regress price weight mpg foreign (output omitted) . esttab, label /// > title(This is a regression table) /// > nonumbers mtitles("Model A" "Model B") /// > addnote("Source: auto.dta") This is a regression table ---------------------------------------------------- Model A Model B ---------------------------------------------------- Weight (lbs.) 1.747** 3.465*** (2.72) (5.49) Mileage (mpg) -49.51 21.85 (-0.57) (0.29) Car type 3673.1*** (5.37) Constant 1946.1 -5853.7 (0.54) (-1.73) ---------------------------------------------------- Observations 74 74 ---------------------------------------------------- t statistics in parentheses Source: auto.dta * p<0.05, ** p<0.01, *** p<0.001 . eststo clearCode
The label
option supports factor variables and interactions in Stata 11 or newer:
. sysuse auto, clear (1978 Automobile Data) . eststo: regress price mpg i.foreign (output omitted) . eststo: regress price c.mpg##i.foreign (output omitted) . esttab, varwidth(25) --------------------------------------------------------- (1) (2) price price --------------------------------------------------------- mpg -294.2*** -329.3*** (-5.28) (-4.39) 0.foreign 0 0 (.) (.) 1.foreign 1767.3* -13.59 (2.52) (-0.01) 0.foreign#c.mpg 0 (.) 1.foreign#c.mpg 78.89 (0.70) _cons 11905.4*** 12600.5*** (10.28) (8.25) --------------------------------------------------------- N 74 74 --------------------------------------------------------- t statistics in parentheses * p<0.05, ** p<0.01, *** p<0.001 . esttab, varwidth(25) label --------------------------------------------------------- (1) (2) Price Price --------------------------------------------------------- Mileage (mpg) -294.2*** -329.3*** (-5.28) (-4.39) Domestic 0 0 (.) (.) Foreign 1767.3* -13.59 (2.52) (-0.01) Domestic # Mileage (mpg) 0 (.) Foreign # Mileage (mpg) 78.89 (0.70) Constant 11905.4*** 12600.5*** (10.28) (8.25) --------------------------------------------------------- Observations 74 74 --------------------------------------------------------- t statistics in parentheses * p<0.05, ** p<0.01, *** p<0.001 . esttab, varwidth(25) label nobaselevels interaction(" X ") --------------------------------------------------------- (1) (2) Price Price --------------------------------------------------------- Mileage (mpg) -294.2*** -329.3*** (-5.28) (-4.39) Foreign 1767.3* -13.59 (2.52) (-0.01) Foreign X Mileage (mpg) 78.89 (0.70) Constant 11905.4*** 12600.5*** (10.28) (8.25) --------------------------------------------------------- Observations 74 74 --------------------------------------------------------- t statistics in parentheses * p<0.05, ** p<0.01, *** p<0.001 . eststo clearCode
The plain
option produces a minimally formatted
table with all display formats set to %9.0g
:
. sysuse auto, clear (1978 Automobile Data) . eststo: regress price weight mpg (output omitted) . eststo: regress price weight mpg foreign (output omitted) . esttab, plain est1 est2 b/t b/t weight 1.746559 3.464706 2.723238 5.493003 mpg -49.51222 21.8536 -.5746808 .2944391 foreign 3673.06 5.370142 _cons 1946.069 -5853.696 .541018 -1.733408 N 74 74 . eststo clearCode
The compress
option reduces horizontal spacing to
fit more models on screen without line breaking:
. sysuse auto, clear (1978 Automobile Data) . eststo: regress price weight (output omitted) . eststo: regress price weight mpg (output omitted) . eststo: regress price weight mpg foreign (output omitted) . eststo: regress price weight mpg foreign displacement (output omitted) . esttab, compress -------------------------------------------------------------- (1) (2) (3) (4) price price price price -------------------------------------------------------------- weight 2.044*** 1.747** 3.465*** 2.458** (5.42) (2.72) (5.49) (2.82) mpg -49.51 21.85 19.08 (-0.57) (0.29) (0.26) foreign 3673.1*** 3930.2*** (5.37) (5.67) displace~t 10.22 (1.65) _cons -6.707 1946.1 -5853.7 -4846.8 (-0.01) (0.54) (-1.73) (-1.43) -------------------------------------------------------------- N 74 74 74 74 -------------------------------------------------------------- t statistics in parentheses * p<0.05, ** p<0.01, *** p<0.001 . eststo clearCode
The default symbols and thresholds are for the "significance stars" are:
*
for p<.05, **
for p<.01, and ***
p<.001. To
use +
for p<.10 and *
for p<.05, for example, type:
. sysuse auto, clear (1978 Automobile Data) . eststo: regress price weight mpg (output omitted) . eststo: regress price weight mpg foreign (output omitted) . esttab, star(+ 0.10 * 0.05) ---------------------------------------- (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.10, * p<0.05 . eststo clearCode
Use the nostar
option suppresses the significance stars.
To produce a table for use with Excel, specify an output filename and apply
the csv
format (or the
scsv
format depending on the language version of Excel). For
example:
. sysuse auto, clear (1978 Automobile Data) . eststo: regress price weight mpg (output omitted) . eststo: regress price weight mpg foreign (output omitted) . esttab using example.csv (output written to example.csv)Code
A click on "example.csv" in Stata's results window will launch Excel and display the file:
Depending on whether the plain
option is specified or not, esttab uses two different variants of the CSV format. By
default, that is, if plain
is omitted, the contents of the table
cells are enclosed in double quotes preceded by an equal sign (i.e.
="..."
). This prevents Excel from trying to interpret the
contents of the cells and, therefore, preserves formatting elements such as
parentheses around t-statistics. One drawback of this approach is, however,
that the displayed numbers cannot directly be used for further calculations
in Excel. Hence, if the purpose of exporting the estimates is to do
additional computations in Excel, specify the plain
option. In this
case, the table cells are enclosed in double quotes without the equal sign,
and Excel will interpret the contents as numbers. Example:
. esttab using example.csv, replace wide plain (output written to example.csv) . eststo clearCode
Result:
To produce a table for use with Word, specify an output filename with an .rtf
suffix
or apply the rtf
option:
. sysuse auto, clear (1978 Automobile Data) . eststo: regress price weight mpg (output omitted) . eststo: regress price weight mpg foreign (output omitted) . esttab using example.rtf (output written to example.rtf)Code
Result:
Appending is possible. Furthermore, varwidth()
and modelwidth()
may be used to change the column widths (the scale is about 1/12 inch). Example
. esttab using example.rtf, append wide label modelwidth(8)
(output written to example.rtf)
CodeResult:
Another very useful feature is the onecell
option that
causes the point estimates and t-statistics (or standard errors, etc.) to be
placed beneath one another in the same table cell:
. lab var mpg "The mgp variable has a really long label and that would disturb the tabl > e" . esttab using example.rtf, replace label nogap onecell (output written to example.rtf)Code
Result:
If you know a bit RTF you can also include RTF commands
to achieve specific effects, although you have to be careful not to break the document
(most importantly, do not introduce unmatched curly braces).
Useful are, for example, {\b ...}
for boldface and {\i ...}
for italics.
A very helpful reference is the RTF Pocket Guide by
Burke (2003):
. esttab using example.rtf, replace nogaps /// > title({\b Table 1.} {\i This is the 1{\super st} table}) (output written to example.rtf) . eststo clearCode
Result:
To create a table to be included in a LaTeX document, type:
. sysuse auto, clear (1978 Automobile Data) . eststo: regress price weight mpg (output omitted) . eststo: regress price weight mpg foreign (output omitted) . esttab using example.tex, label nostar /// > title(Regression table\label{tab1}) (output written to example.tex)Code
Compiling a document containing
\documentclass{article}
\begin{document}
\input{example.tex}
\end{document}
then produces the following result:
Note that esttab automatically initializes the tabular environment
and, if title()
is specified, sets the table as a float object. Use
the fragment
option if you prefer to hard-code the table's
environment and have esttab just produce the table rows.
The table above looks alright, but a better result is achieved by
specifying the booktabs
option and loading LaTeX's
booktabs
package in the document preamble:
. esttab using example.tex, label nostar replace booktabs ///
> title(Regression table\label{tab1})
(output written to example.tex)
CodeResult:
A further improvement is to load LaTeX's
dcolumn
package and format the columns using the D
column specifier:
. esttab using example.tex, label replace booktabs ///
> alignment(D{.}{.}{-1}) ///
> title(Regression table\label{tab1})
(output written to example.tex)
CodeResult:
Last but not least, you can space the table out to a certain width:
. esttab using example.tex, label replace booktabs /// > alignment(D{.}{.}{-1}) width(0.8\hsize) /// > title(Regression table\label{tab1}) (output written to example.tex) . eststo clearCode
Result:
Sometimes it is necessary to include parameter statistics in a table for which
no predefined option exists in esttab. Once the statistics are are stored
in an e()
-matrix, they can be displayed using the main()
option
(replacing the point-estimates) or the aux()
option (replacing the
t-statistics). For example, to include
variance inflation factors instead of t-statistics after
regress
, you
could type:
. sysuse auto, clear (1978 Automobile Data) . regress price weight mpg foreign (output omitted) . estadd vif Variable | VIF 1/VIF -------------+---------------------- weight | 3.86 0.258809 mpg | 2.96 0.337297 foreign | 1.59 0.627761 -------------+---------------------- Mean VIF | 2.81 added matrix: e(vif) : 1 x 4 . esttab, aux(vif 2) wide nopar ----------------------------------------- (1) price ----------------------------------------- weight 3.465*** 3.86 mpg 21.85 2.96 foreign 3673.1*** 1.59 _cons -5853.7 ----------------------------------------- N 74 ----------------------------------------- vif in second column * p<0.05, ** p<0.01, *** p<0.001Code
The second argument in aux()
specifies the display format.
However, if you want to include more than two kinds of parameter statistics, you
have to switch to estout syntax and make use of the
cells()
option.
All estout options are allowed in esttab, but you have to be aware
that the specified estout options will take precedence over
esttab's own options. For example,
specifying cells()
disables
b()
, beta()
, main()
, t()
, abs
, not
,
se()
, p()
, ci()
, aux()
, star
, staraux
,
wide
, onecell
, parentheses
, and brackets
. In the following
example the cells()
option is used to print point estimates, t-statistics,
and variance inflation factors in one table:
. sysuse auto, clear (1978 Automobile Data) . regress price weight mpg foreign (output omitted) . estadd vif Variable | VIF 1/VIF -------------+---------------------- weight | 3.86 0.258809 mpg | 2.96 0.337297 foreign | 1.59 0.627761 -------------+---------------------- Mean VIF | 2.81 added matrix: e(vif) : 1 x 4 . esttab, cells("b(fmt(a3) star) vif(fmt(2))" t(par fmt(2))) ----------------------------------------- (1) price b/t vif ----------------------------------------- weight 3.465*** 3.86 (5.49) mpg 21.85 2.96 (0.29) foreign 3673.1*** 1.59 (5.37) _cons -5853.7 (-1.73) ----------------------------------------- N 74 -----------------------------------------Code
Similarly, for a complicated summary statistics section
in the table footer you might have to use estout's
stats()
option
(which overwrites esttab options such as
r2()
, ar2()
, pr2()
, aic()
, bic()
, scalars()
,
sfmt()
, noobs
, and obslast
).
Sometimes, an approach is to use esttab to assemble a basic table
and then hand-edit and re-run the estout call. The call can be
made visible by the noisily
option
and is also returned in r(cmdline)
. Example:
. sysuse auto, clear (1978 Automobile Data) . eststo: regress price weight mpg (output omitted) . eststo: regress price weight mpg foreign (output omitted) . esttab, noisily notype estout , cells(b(fmt(a3) star) t(fmt(2) par("{ralign @modelwidth:{txt:(}" "{txt:)}}"))) stats(N, fmt(%18.0g) labels(`"N"')) starlevels(* 0.05 ** 0.01 *** 0.001) varwidth(12) modelwidth(12) abbrev delimiter(" ") smcltags prehead(`"{hline @width}"') posthead("{hline @width}") prefoot("{hline @width}") postfoot(`"{hline @width}"' `"t statistics in parentheses"' `"@starlegend"') varlabels(, end("" "") nolast) mlabels(, depvar) numbers collabels(none) eqlabels(, begin("{hline @width}" "") nofirst) interaction(" # ") notype level(95) style(esttab) . return list scalars: r(nmodels) = 2 r(ccols) = 3 macros: r(names) : "est1 est2" r(m2_depname) : "price" r(m1_depname) : "price" r(cmdline) : "estout , cells(b(fmt(a3) star) t(fmt(2) par("{ralign @mod.." matrices: r(coefs) : 4 x 6 r(stats) : 1 x 2 . eststo clearCode
notype
is specified in this example to suppress the display of the table.