|
|
|
||||
|
Stat Computing >
Stata > Stata Tools for LaTeX
|
|
||||
Stata command outtex is a user-written program. It generates LaTeX code for results tables after any estimation command. You can use Stata's findit command to download the program from the internet. Please see our webpage on how to use findit to search for programs and additional help for more details. There are many useful options after the outtex. We are going to demonstrate some of them in the examples below.
Example 1: Default output of outtex
The default for command outtex only displays the variable names, estimated coefficients, and the standard errors for the estimates.
use http://www.ats.ucla.edu/stat/stata/notes/hsb2, clear (highschool and beyond (200 cases))
regress write math female
Source | SS df MS Number of obs = 200
-------------+------------------------------ F( 2, 197) = 82.81
Model | 8165.58839 2 4082.79419 Prob > F = 0.0000
Residual | 9713.28661 197 49.3060234 R-squared = 0.4567
-------------+------------------------------ Adj R-squared = 0.4512
Total | 17878.875 199 89.843593 Root MSE = 7.0218
------------------------------------------------------------------------------
write | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
math | .6328663 .0531548 11.91 0.000 .5280407 .7376918
female | 5.218377 .9975118 5.23 0.000 3.251205 7.185549
_cons | 16.61374 2.908957 5.71 0.000 10.87705 22.35043
------------------------------------------------------------------------------
outtex
%------- Begin LaTeX code -------%
{
\begin{table}[htbp]\centering
\caption{Estimation results : regress
\label{tabresult regress}}
\begin{tabular}{l c c }\hline\hline
\multicolumn{1}{c} {\textbf{Variable}}
& {\textbf{Coefficient}} & \textbf{(Std. Err.)} \\ \hline
math & 0.633 & (0.053)\\
female & 5.218 & (0.998)\\
Intercept & 16.614 & (2.909)\\
\hline
\end{tabular}
\end{table}
}
%------- End LaTeX code -------%
Here is a LaTeX file for this example and here is the pdf file corresponding to it.
Example 2: Displaying the significance level using the level option
regress write math female
Source | SS df MS Number of obs = 200
-------------+------------------------------ F( 2, 197) = 82.81
Model | 8165.58839 2 4082.79419 Prob > F = 0.0000
Residual | 9713.28661 197 49.3060234 R-squared = 0.4567
-------------+------------------------------ Adj R-squared = 0.4512
Total | 17878.875 199 89.843593 Root MSE = 7.0218
------------------------------------------------------------------------------
write | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
math | .6328663 .0531548 11.91 0.000 .5280407 .7376918
female | 5.218377 .9975118 5.23 0.000 3.251205 7.185549
_cons | 16.61374 2.908957 5.71 0.000 10.87705 22.35043
------------------------------------------------------------------------------
outtex, level
%------- Begin LaTeX code -------%
{
\def\onepc{$^{\ast\ast}$} \def\fivepc{$^{\ast}$}
\def\tenpc{$^{\dag}$}
\def\legend{\multicolumn{4}{l}{\footnotesize{Significance levels
:\hspace{1em} $\dag$ : 10\% \hspace{1em}
$\ast$ : 5\% \hspace{1em} $\ast\ast$ : 1\% \normalsize}}}
\begin{table}[htbp]\centering
\caption{Estimation results : regress
\label{tabresult regress}}
\begin{tabular}{l r @{} l c }\hline\hline
\multicolumn{1}{c}
{\textbf{Variable}}
& \multicolumn{2}{c}{\textbf{Coefficient}} & \textbf{(Std. Err.)} \\ \hline
math & 0.633&\onepc & (0.053)\\
female & 5.218&\onepc & (0.998)\\
Intercept & 16.614&\onepc & (2.909)\\
\hline
\end{tabular}
\end{table}
}
%------- End LaTeX code -------%
Remember that the significance level is set in the regress command using its level option with default set to be 95%. In outtex the option level is for adding symbols according to the coefficient's significance level. Here is the LaTeX file containing the code and here is the pdf file corresponding to it.
Example 3: Detailed output using the detail option and a customized title
If you want to output some of the details such as R-square and number of observations used in the model, you can use the option detail after the outtex command. We also used the option below to display the standard error of the estimate right below it. Command regress also saves a macro variable called e(depvar) for storing the name of the dependent variable. This can be used to create a title with this piece of information.
outtex, detail level below title(Dep = `e(depvar)')
%------- Begin LaTeX code -------%
{
\def\sep{0.5em}
\def\fns{\footnotesize}
\def\onepc{$^{\ast\ast}$} \def\fivepc{$^{\ast}$}
\def\tenpc{$^{\dag}$}
\def\legend{\multicolumn{3}{l}{\footnotesize{Significance levels
:\hspace{1em} $\dag$ : 10\% \hspace{1em}
$\ast$ : 5\% \hspace{1em} $\ast\ast$ : 1\% \normalsize}}}
\begin{table}[htbp]\centering
\caption{Dep = write
\label{tabresult regress}}
\begin{tabular}{l r @{} l }\hline\hline
\multicolumn{1}{c}
{\textbf{Variable}}
& \textbf{Coefficient} \\& \fns{(Std. Err.)} \\ \hline
math & 0.633&\onepc \\ & \fns{(0.053)} &\\[\sep]
female & 5.218&\onepc \\ & \fns{(0.998)} &\\[\sep]
Intercept & 16.614&\onepc \\ & \fns{(2.909)} &\\[\sep]
\hline
\multicolumn{3}{c}{}\\
\hline N & \multicolumn{2}{c}{200}\\
R$^{2}$ & \multicolumn{2}{c}{0.457}\\
F $ _{(2,197)}$ & \multicolumn{2}{c}{82.805}\\
\hline
\end{tabular}
\end{table}
}
%------- End LaTeX code -------%
Here is the LaTeX file containing the code and here is the pdf file corresponding to it.
UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services