texdoc does not provide specific tools for producing tables. However, you
can use other programs such as listtex (see
ideas.repec.org/c/boc/bocode/s423201.html)
or esttab (see repec.org/bocode/e/estout) to
write a table in LaTeX format and then place a link to the table in your
document using the texdoc write command. Below is an example
based on esttab. The procedure for listtex or
other commands would be similar.
/***
\documentclass[a4paper]{article}
\usepackage{booktabs,dcolumn}
\usepackage{stata}
\begin{document}
\noindent
Table~\ref{table1} displays a number of regression models for price using the
1978 Automobile Data.
***/
texdoc stlog, nolog
sysuse auto
regress price weight
estimates store m1
regress price weight mpg
estimates store m2
regress price weight mpg foreign
estimates store m3
esttab m1 m2 m3 using table1.tex, replace se label ///
nomtitles booktabs align(D{.}{.}{-1}) ///
title(Some regression table\label{table1})
texdoc stlog close
texdoc write \input{table1.tex}
/***
\end{document}
***/
The regression commands have been put into a texdoc stlog
section in the example above, but nolog was specified to turn
the log off. Including the commands in a texdoc stlog section
makes sense to be able to apply the nodo option once the
commands are complete.
If you do not want to bother about specifying a name for the external file
holding the table, you can use the name provided by texdoc
stlog:
/***
\documentclass[a4paper]{article}
\usepackage{booktabs,dcolumn}
\usepackage{stata}
\begin{document}
\noindent
Table~\ref{table1} displays a number of regression models for price using the
1978 Automobile Data.
***/
texdoc stlog, nolog
sysuse auto
regress price weight
estimates store m1
regress price weight mpg
estimates store m2
regress price weight mpg foreign
estimates store m3
esttab m1 m2 m3 using "${TeXdoc_stfilename0}.tex", replace se label ///
nomtitles booktabs align(D{.}{.}{-1}) ///
title(Some regression table\label{table1})
texdoc stlog close
texdoc write \input{`s(texname0)'.tex}
/***
\end{document}
***/
texdoc stlog maintains a number of global macros while it is
running (see the remark on global
macros in the help file). Macro
TeXdoc_stfilename0 contains the name and absolute path of the
current log file (without suffix). Furthermore, several
s()-returns are provided by texdoc stlog close
(see the section on stored
results in the help file). For example,
s(texname0) contains the log file's name and include-path for
use in the LaTeX document (without suffix).
If you want to copy the table directly into the LaTeX document instead of
using an include-link, you can use the texdoc append command.
Here is an example in which, in addition, a custom table environment is
used to generate a rotated table in a box:
/***
\documentclass[a4paper]{article}
\usepackage{booktabs,dcolumn,rotating}
\usepackage{stata}
\begin{document}
\noindent
Table~\ref{table1} displays a number of regression models for price using the
1978 Automobile Data.
***/
texdoc stlog, nolog
sysuse auto
regress price weight mpg
estimates store m1
regress price weight mpg foreign
estimates store m2
esttab m1 m2 using "${TeXdoc_stfilename0}.tex", replace se label ///
nomtitles booktabs align(D{.}{.}{-1}) ///
title(Some regression table\label{table1}) ///
nofloat
texdoc stlog close
texdoc write \begin{table}[h]\raggedleft
texdoc write \fbox{\rotatebox{90}{\begin{minipage}{8cm}\centering
texdoc append "`s(filename0)'.tex"
texdoc write \end{minipage}}}\end{table}
/***
\end{document}
***/