current version: Mar 19, 2005

(

The package

To download the according .ado files, you can use the command

. net from http://econ.ucsd.edu/muendler/download/stata/

in Stata.

Alternatively, you can download the zip file.

First, the command

Second, the command

The command

The command

A simple example below explains the main steps.

The package matsave must be installed for

. generate weightsq = weight^2

. regress mpg weight weightsq foreign

(

We can collect information from this first regression with

. est2vec table, e(r2 F) vars(weight weightsq length domestic foreign _cons)

This command creates three auxiliary matrices

. matrix dir

______________table_e[3,1]

_____________table_se[6,1]

______________table_b[6,1]

Take a look at

. matrix list table_b

________table_b[6,1]

_________________________mpg

__________weight__-.01657294

________weightsq___1.591e-06

__________length________-999

________domestic________-999

_________foreign__-2.2035002

____________cons___56.538839

The auxiliary matrix

. matrix list table_e

________table_e[3,1]

_____________________mpg

_________e(N)_________74

________e(r2)__.69129599

_________e(F)__52.251474

The command est2vec always stores the number of observations N in

Since the variables length and domestic were not included in the regression, their coefficient estimates are reported as missing in

No wildcards or dashes may be used in option

An additional regression (also in the Stata handbook) includes the variables length and domestic.

. gen byte domestic=~foreign

. reg weight length domestic, hascons

(

We can collect information from this regression with

. est2vec table, addto(table)

Under the option addto(), est2vec adds results from the present regression to the previously collected matrices. Check:

. matrix list table_b

________table_b[6,2]

_________________________mpg______weight

__________weight__-.01657294________-999

________weightsq___1.591e-06________-999

__________length________-999___31.444552

________domestic________-999____133.6775

_________foreign__-2.2035002________-999

____________cons___56.538839__-2983.9272

Stata sets missing values to zero in its result macros. Therefore, the estimate on _cons is zero under the hascons option and so is the standard error. Later, est2tex will produce a LaTeX table that sets both coefficients with -999 estimates and coefficients with zero standard errors to missing.

To create a LaTeX table from the assembled matrices, the command

We can also use the option

The command

. est2tex table, preserve path(../texdocs) mark(stars) fancy

creates a LaTeX table. It saves the files

The option mark(stars) adds one star (two stars, three stars) to the standard error when a coefficient estimate is significant at the 95% (99%, 99.9%) level. The option fancy creates separating lines and adds spaces between columns to fit the predetermined table width in LaTeX.

Suppose we did not specify the option preserve with {cmd:est2tex}. Then a glance at the resulting dataset in memory shows what information goes into the LaTeX table.

. preserve

. est2tex table, replace dropall path(../texdocs) mark(stars) fancy

. list

_______________rowname________mpg_____weight

__________1.____weight__-.0165729_______-999

__________2.________se___.0039692_______-999

__________3.__weightsq___1.59e-06_______-999

__________4.________se___6.25e-07_______-999

__________5.____length_______-999___31.44455

__________6.________se_______-999___1.601234

__________7.__domestic_______-999___133.6775

__________8.________se_______-999___77.47614

__________9.___foreign____-2.2035_______-999

_________10.________se___1.059246_______-999

_________11.______cons___56.53884__-2983.927

_________12.________se___6.197383___275.1041

_________13.______e(N)_________74_________74

_________14._____e(r2)____.691296___.8991605

_________15.______e(F)___52.25147___316.5447

The resulting LaTeX code in file table.tex is somewhat less transparent.

__\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}lcc}

__ & \multicolumn{1}{c}{mpg} & \multicolumn{1}{c}{weight} \\

__\cline{2-3}

__ & \multicolumn{1}{c}{(1)} & \multicolumn{1}{c}{(2)} \\

__\hline

__weight & -.016 & \\

__& \raisebox{.7ex}[0pt]{\scriptsize (.004)$^{***}$} & \\

__weightsq & 1.59e-06 & \\

__& \raisebox{.7ex}[0pt]{\scriptsize (6.25e-07)$^{*}$} & \\

__length & & 31.445 \\

__& & \raisebox{.7ex}[0pt]{\scriptsize (1.601)$^{***}$} \\

__domestic & & 133.678 \\

__& & \raisebox{.7ex}[0pt]{\scriptsize (77.476)} \\

__foreign & -2.203 & \\

__& \raisebox{.7ex}[0pt]{\scriptsize (1.059)$^{*}$} & \\

__cons & 56.539 & -2983.926 \\

__& \raisebox{.7ex}[0pt]{\scriptsize (6.197)$^{***}$} &

__ \raisebox{.7ex}[0pt]{\scriptsize (275.104)$^{***}$} \\

__e(N) & 74 & 74 \\

__e(r2) & .691 & .899 \\

__e(F) & 52.251 & 316.545 \\

__\hline\hline

__\end{tabular*}%

The resulting LaTeX document, however, should be quite agreeable. The file

The following LaTeX code produces a sample document.

__\documentclass[12pt]{article}

__\begin{document}

__\title{Stata: \emph{est2tex}}%

__\author{\Large Help File Example}%

__\maketitle

__\thispagestyle{empty}

__\bigskip

__\noindent This is the resulting table.

__\begin{table}[h]

__\input{table.tex}

__\end{table}

__\end{document}

If we wanted to include Stata's variable labels rather than the variable names in the LaTeX table, we could specify the option

. label var weight "Weight ({\it lbs.})"

. label var weightsq "Squared weight ({\it lbs.}$^2$)"

. label var length "Length ({\it in.})"

. est2tex table, replace preserve path(../texdocs) mark(stars) levels(95 99 99) fancy lab collab("Mileage~$\left(\frac{miles}{gallon}\right)$ Weight~(\emph{lbs.})")

The option levels(95 99 99) in the last command makes sure that only two levels of significance are used to mark the estimates with (zero, one or two) stars (but not with three stars).

The file est2tex.pdf shows the resulting LaTeX table under the above options.

By default,

Generally, tables contain results from more than one estimation. The command

Instead of creating LaTeX output immediately, the command

The name of

When assembling estimates from multiple equation regressions (reg3 or mlogit, for instance), est2vec only adds equations that have been specified initially. Consider the following regression from the same automobile dataset as before. The variable rep78 can take five values (1 through 5) that represent the repair record. The command

. mlogit rep78 price mpg foreign, base(1)

(

estimates the probability of categories 2 through 5, relative to category 1, as a function of price, mpg and foreign. We can store the results with

. est2vec table2

All estimates are identified with their according "equation name". These equation names are the categories of rep78 in the case of mlogit:

. matrix list table2_b

________table2_b[16,1]

________________________rep78

__________2:price___.00040825

____________2:mpg__-.02318283

________2:foreign___-18.15009

__________2:_cons__-.20046453

__________3:price____.0004733

____________3:mpg__-.00072598

________3:foreign___19.271375

__________3:_cons___.18466295

__________4:price___.00044831

____________4:mpg___.03087516

________4:foreign___21.364028

__________4:_cons__-1.3762754

__________5:price___.00064603

____________5:mpg___.21926142

________5:foreign___22.223713

__________5:_cons__-8.2147995

If we chose category 5 as base category instead of 1, we would run

. mlogit rep78 price mpg foreign, base(5)

(

Adding these estimates to the preceding

. est2vec table2, addto(table2) name(rep78_alt)

yields

. matrix list table2_b

________table2_b[16,2]

________________________rep78___rep78_alt

__________2:price___.00040825__-.00023778

____________2:mpg__-.02318283__-.24244424

________2:foreign___-18.15009__-37.373803

__________2:_cons__-.20046453____8.014335

__________3:price____.0004733__-.00017272

____________3:mpg__-.00072598__-.21998739

________3:foreign___19.271375__-2.9523383

__________3:_cons___.18466295___8.3994624

__________4:price___.00044831__-.00019772

____________4:mpg___.03087516__-.18838626

________4:foreign___21.364028__-.85968569

__________4:_cons__-1.3762754___6.8385241

__________5:price___.00064603___________0

____________5:mpg___.21926142___________0

________5:foreign___22.223713___________0

__________5:_cons__-8.2147995___________0

Since equation "5" is not independently identified in the last regression, the according estimates are set to missing in the Stata output (check

In some final tables, we may want to show the according estimates.

First, we can specify the according option

. mlogit rep78 price mpg foreign, base(1)

(

. est2vec table3, vars(1:price 1:mpg 1:foreign 1:_cons 2:price 2:mpg 2:foreign 2:_cons 3:price 3:mpg 3:foreign 3:_cons 4:price 4:mpg 4:foreign 4:_cons 5:price 5:mpg 5:foreign 5:_cons)

. mlogit rep78 price mpg foreign, base(5)

(

. est2vec table3, addto(table3) name(rep78_alt)

. matrix list table3_b

yields

________table3_b[20,2]

________________________rep78___rep78_alt

__________1:price___________0__-.00064603

____________1:mpg___________0__-.21926142

________1:foreign___________0__-37.223714

__________1:_cons___________0___8.2147995

__________2:price___.00040825__-.00023778

____________2:mpg__-.02318283__-.24244424

________2:foreign___-18.15009__-37.373803

__________2:_cons__-.20046453____8.014335

__________3:price____.0004733__-.00017272

____________3:mpg__-.00072598__-.21998739

________3:foreign___19.271375__-2.9523383

__________3:_cons___.18466295___8.3994624

__________4:price___.00044831__-.00019772

____________4:mpg___.03087516__-.18838626

________4:foreign___21.364028__-.85968569

__________4:_cons__-1.3762754___6.8385241

__________5:price___.00064603___________0

____________5:mpg___.21926142___________0

________5:foreign___22.223713___________0

__________5:_cons__-8.2147995___________0

Alternatively, we can specify the option

. mlogit rep78 price mpg foreign, base(1)

(

. est2vec table4

. mlogit rep78 price mpg foreign, base(5)

(

. est2vec table4, addto(table4) name(rep78_alt) force

. matrix list table4_b

________table4_b[16,2]

________________________rep78___rep78_alt

__________2:price___.00040825__-.00064603

____________2:mpg__-.02318283__-.21926142

________2:foreign___-18.15009__-37.223714

__________2:_cons__-.20046453___8.2147995

__________3:price____.0004733__-.00023778

____________3:mpg__-.00072598__-.24244424

________3:foreign___19.271375__-37.373803

__________3:_cons___.18466295____8.014335

__________4:price___.00044831__-.00017272

____________4:mpg___.03087516__-.21998739

________4:foreign___21.364028__-2.9523383

__________4:_cons__-1.3762754___8.3994624

__________5:price___.00064603__-.00019772

____________5:mpg___.21926142__-.18838626

________5:foreign___22.223713__-.85968569

__________5:_cons__-8.2147995___6.8385241

Much care is warranted with the force option. Most importantly, the row names in the table only apply to the first but by no means to the second estimation. In fact, the equation numbers underlying the second column are exactly the equation numbers of the first column less one.

Table3 above, for instance, can be saved in a plain text file with

. est2tex table3, path(../texdocs) dropall plain(tab)

Last modified: May 17, 2007.© February 2000 and July 2002. All rights reserved. Marc-Andreas Muendler |