Link Search Menu Expand Document

Regression Tables

Statistical packages often report regression results in a way that is not how you would want to display them in a paper or on a website. Additionally, they rarely provide an option to display multiple regression results in the same table.

Two (bad) options for including regression results in your paper include copying over each desied number by hand, or taking a screenshot of your regression output. Much better is using a command that outputs regression results in a nice format, in a way you can include in your presentation.

Keep in Mind

  • Any good regression table exporting command should include an option to limit the number of significant digits in your result. You should almost always make use of this option. It is very rare that the seventh or eighth decimal place (commonly reported in statistics packages) is actually meaningful, and it makes it difficult to read your table.
  • Variable names serve different purposes in statistical coding and in papers. Variable names in papers should be changed to be readable in the language of the paper. So for example, while employment may be recorded as EMP_STAT in your statistics package, you should rename it Employment for your paper. Most table exporting commands include options to perform this renaming. But if it doesn’t, you can always change it by hand after exporting.
  • If you use asterisks to indicate significance, be sure to check the significance levels that different numbers of asterisks indicate in the command you’re using, as standards for what significance levels the asterisks mean vary across fields (and so vary across commands as well). Most commands include an option to change the significance levels used. On that note, always include a table note saying what the different asterisk indicators mean! These commands should all include one by default - don’t take it out!

Also Consider

  • If you are a Word user, and the command you are using does not export to Word or RTF, you can get the table into Word by exporting an HTML, CSV, or LaTeX, then opening up the result in your browser, Excel, or TtH, respectively. Excel and HTML tables can generally be copy/pasted directly into Word (and then formatted within Word). You may at that point want to use Word’s “Convert Text to Table” command, especially if you’ve pasted in HTML.
  • By necessity, regression-output commands often have about ten million options, and they can’t all be covered on this page. If you want it to do something, it probably can. To reduce errors, it is probably a good idea to do as little formatting and copy/pasting by hand as possible. So if you want to do something it doesn’t do by default, like adding additional calculations, check out the help file for your command to see how you can do it automatically.

Implementations

R

There are many, many packages for exporting regression results in R, including RStudio’s gt, texreg, and xtable. Here we will focus on two: stargazer, which is probably the easiest to use, and huxtable, which is slightly more up-to-date and offers advanced formatting options, outlined on its website.

# Install stargazer if necessary
# install.packages('stargazer')
library(stargazer)

# Get mtcars data
data(mtcars)

# Let's give it two regressions to output
lm1 <- lm(mpg ~ cyl, data = mtcars)
lm2 <- lm(mpg ~ cyl + hp, data = mtcars)

# Let's output an HTML table, perhaps for pasting into Word
# We could instead set type = 'latex' for LaTeX or type = 'text' for a text-only table.
stargazer(lm1, lm2, type = 'html', out = 'my_reg_table.html')

# In line with good practices, we should use readable names for our variables
stargazer(lm1, lm2, type = 'html', out = 'my_reg_table.html',
          covariate.labels = c('Cylinders','Horsepower'),
          dep.var.labels = 'Miles per Gallon')

This produces:

(1) (2)
Cylinders -2.876 *** -2.265 ***
(0.322)    (0.576)   
Horsepower          -0.019    
         (0.015)   
N 32         32        
R2 0.726     0.741    
logLik -81.653     -80.781    
AIC 169.306     169.562    
*** p < 0.001; ** p < 0.01; * p < 0.05.

Now we will do the same thing with huxtable, using mostly defaults.

# Install huxtable and magrittr if necessary
# install.packages('huxtable', 'magrittr')
# huxtable works more easily with the pipe %>%
# which can come from magrittr or dplyr or tidyverse, etc.
library(huxtable)
library(magrittr)

# First we build a huxreg object, using readable names
huxreg(lm1, lm2,
       coefs=c('Cylinders' = 'cyl',
               'Horsepower' = 'hp')) %>%
  # We can send it to the screen to view it instantly
  print_screen()

# Or we can send it to a file with the quick_ functions, which can 
# output to pdf, docx, html, xlsx, pptx, rtf, or latex.
huxreg(lm1, lm2,
       coefs=c('Cylinders' = 'cyl',
               'Horsepower' = 'hp')) %>%
  # Let's make an HTML file
  quick_html(file = 'my_reg_output.html')

Which produces (note the different asterisks behavior, which can be changed with huxreg’s stars option):

Dependent variable:
Miles per Gallon
(1)(2)
Cylinders-2.876***-2.265***
(0.322)(0.576)
Horsepower-0.019
(0.015)
Constant37.885***36.908***
(2.074)(2.191)
Observations3232
R20.7260.741
Adjusted R20.7170.723
Residual Std. Error3.206 (df = 30)3.173 (df = 29)
F Statistic79.561*** (df = 1; 30)41.422*** (df = 2; 29)
Note:*p<0.1; **p<0.05; ***p<0.01

Stata

There are two main ways of outputting regression results in Stata, both of which must be installed from ssc install: outreg2 and estout. We will use estout here, as it is more flexible. More detail is available on the estout website.

Also note that, in a pinch, if you’re using a strange command that does not play nicely with estout, you can often select any Stata regression output, select the output, right-click, do “Copy Table”, and paste the result into Excel. This is only if all else fails.


* Install estout if necessary
* ssc install estout

* Load auto data
sysuse auto.dta, clear

* Let's provide it two regressions
* Making sure to store the results each time
reg mpg weight
estimates store weightonly
reg mpg weight foreign
estimates store weightandforeign

* Now let's export the table using estout
* while renaming the variables for readability using the variable labels already in Stata
* replacing any table we've already made
* and making an HTML table with style(html)
* style(tex) also works, and the default is tab-delimited data for use in Excel.
* Note also the default is to display t-statistics in parentheses. If we want 
* standard errors instead, we say so with se
esttab weightonly weightandforeign using my_reg_output.html, label replace style(html) se

Which produces:


(1) (2)
Mileage (mpg) Mileage (mpg)

Weight (lbs.) -0.00601*** -0.00659***
(0.000518) (0.000637)
 
Car type -1.650
(1.076)
 
Constant 39.44*** 41.68***
(1.614) (2.166)

Observations 74 74

Standard errors in parentheses
* p < 0.05, ** p < 0.01, *** p < 0.001