Star
Star

Reputation: 2299

Adjusting the size of tables when using esttab

I am exporting regression results in tex files using the community-contributed command esttab:

esttab using reg.tex, nonumbers mtitles("1" "2" "3" "4" "5" "6" "7" "8" "9")

The table contains nine columns.

I would like to make the font size and the width of columns smaller so that the whole table can fit in the page when I compile the file in LaTeX.

Is there a way to do this directly in Stata when I use esttab?

Upvotes: 1

Views: 11118

Answers (1)

user8682794
user8682794

Reputation:

Consider the following example using Stata's auto toy dataset:

sysuse auto, clear
eststo clear

eststo: quietly regress price weight
eststo: quietly regress price weight mpg

esttab

--------------------------------------------
                      (1)             (2)   
                    price           price   
--------------------------------------------
weight              2.044***        1.747** 
                   (5.42)          (2.72)   

mpg                                -49.51   
                                  (-0.57)   

_cons              -6.707          1946.1   
                  (-0.01)          (0.54)   
--------------------------------------------
N                      74              74   
--------------------------------------------
t statistics in parentheses
* p<0.05, ** p<0.01, *** p<0.001

In general, the width of the columns can be controlled using varwidth() and/or modelwidth():

esttab, mlabels(none) varwidth(25)

---------------------------------------------------------
                                   (1)             (2)   
---------------------------------------------------------
weight                           2.044***        1.747** 
                                (5.42)          (2.72)   

mpg                                             -49.51   
                                               (-0.57)   

_cons                           -6.707          1946.1   
                               (-0.01)          (0.54)   
---------------------------------------------------------
N                                   74              74   
---------------------------------------------------------
t statistics in parentheses
* p<0.05, ** p<0.01, *** p<0.001

esttab, mlabels(none) modelwidth(25)

----------------------------------------------------------------------
                                   (1)                          (2)   
----------------------------------------------------------------------
weight                           2.044***                     1.747** 
                                (5.42)                       (2.72)   
mpg                                                          -49.51   
                                                            (-0.57)   
_cons                           -6.707                       1946.1   
                               (-0.01)                       (0.54)   
----------------------------------------------------------------------
N                                   74                           74   
----------------------------------------------------------------------
t statistics in parentheses
* p<0.05, ** p<0.01, *** p<0.001

The two aforementioned options can also work in combination:

-----------------------------------------------------------------------------------
                                                (1)                          (2)   
-----------------------------------------------------------------------------------
weight                                        2.044***                     1.747** 
                                             (5.42)                       (2.72)   

mpg                                                                       -49.51   
                                                                         (-0.57)   

_cons                                        -6.707                       1946.1   
                                            (-0.01)                       (0.54)   
-----------------------------------------------------------------------------------
N                                                74                           74   
-----------------------------------------------------------------------------------
t statistics in parentheses
* p<0.05, ** p<0.01, *** p<0.001

For LaTeX output you will need to include the necessary markup in the prehead() or postfoot() options as appropriate.

In this example, you can change the font size of the table as follows:

esttab, mlabels(none) tex ///
        prehead(`"\begin{table}"' `"\tiny"' ///
                `"\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}"' ///
                `"\begin{tabular}{l*{2}{c}}"') ///
        postfoot(`"\end{tabular}"' `"\end{table}"')

Similarly, you can control the column spacing by changing below the value {5pt}:

esttab, mlabels(none) tex ///
        prehead(`"\setlength{\tabcolsep}{5pt}"' `"\begin{tabular}"')

Upvotes: 6

Related Questions