1
votes

Sometimes you must export using from Stata to Latex very long or very large regression tables such that it does not fit into a single page. This commonly happens in preliminary analysis is you keep a maximum of control variables and tests various models side by side. One solution is to modify fonts manually in the Latex output ResultsTable.tex file by adding \footnotesize or \tiny after \caption:

\begin{table}[htbp]\centering
\caption{Main Results} \footnotesize
\begin{tabular}{l*{3}{c}}

But this must be repeated each time a modification is made to the table.

What would be the approach to modify the Latex's font size directly into STATA using the esttab package?

esttab m1 m2 m3 m4 m5 m6 m7 m8 using "ResultsTable.tex", replace booktabs compress 

Thank you for any advice on this!

1
The options of esttab are documented in help esttab. If this doesn't allow enough flexibility you can read in the resulting tex file using import delimited and add your changes using replace ifWouter
I think @Wouter's linked solution is a great solution for edits to the body of the table (i.e. the part not controlled by prehead and postfoot), but for edits to the "head" the answer below is also nice, and would suffice.Arthur Morris

1 Answers

3
votes

Though help esttab is always useful, most solutions to tricky esttab-to-Latex problems rely on the fact that esttab is a wrapper for estout, and are easily solved with estout's prehead option... which is not documented under esttab.

Here is a quick MWE that approximates the information in your question:

sysuse auto

reg price mpg 
estimates store m1
reg price mpg rep78
estimates store m2 
reg price mpg rep78 headroom
estimates store m3

esttab m1 m2 m3 ///
    using "out1.tex", ///
    replace booktabs compress ///
    title("Main Results")

This produces a .tex file containing a table with the following header:

\begin{table}[htbp]\centering
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\caption{Main Results}
\begin{tabular}{l*{3}{c}}
\toprule

To add \footnotesize you'll need to pass the full header from \begin{table} to \toprule (since you're using booktabs) to the prehead() option as follows:

esttab m1 m2 m3 ///
    using "out2.tex", ///
    replace booktabs compress ///
    prehead(`"\begin{table}[htbp]\centering"' `"\footnotesize"' ///
            `"\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}"' ///
            `"\caption{Main Results}"' ///
            `"\begin{tabular}{l*{@M}{c}}"' ///
            `"\toprule"' ) //

Note that each line in the .tex output is wrapped with a back-tick and apostrophe, and that the \begin{tabular}{l*{@M}{c}} statement references @M rather than explicitly stating the number of columns. This produces a .tex file containing a table with the following header:

\begin{table}[htbp]\centering
\footnotesize
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\caption{Main Results}
\begin{tabular}{l*{3}{c}}
\toprule