Chapter 14 Tables

14.1 Regression tables

To export regression tables from R, we are going to use the package stargazer (Hlavac, 2015). Remember to install the package if you haven’t already done so.

library("stargazer")

First, we use the stargazer() function to show the output from the object reg_obama estimated in the OLS regression chapter. Notice that we also add the option type = "text". If we do not do that, we will get the output as LaTeX code.

stargazer(reg_obama, type = "text")
## 
## ===============================================
##                         Dependent variable:    
##                     ---------------------------
##                              obama2012         
## -----------------------------------------------
## abort_rate08                 0.826***          
##                               (0.130)          
##                                                
## Constant                     35.259***         
##                               (2.297)          
##                                                
## -----------------------------------------------
## Observations                    50             
## R2                             0.458           
## Adjusted R2                    0.446           
## Residual Std. Error       7.654 (df = 48)      
## F Statistic           40.521*** (df = 1; 48)   
## ===============================================
## Note:               *p<0.1; **p<0.05; ***p<0.01

This shows the output from one regression model. To add more regression models to the table, simply add a comma and the name of the object with the model. Below we use the same code as above and add the model with control variables included, reg_obama_full.

stargazer(reg_obama, reg_obama_full, type = "text")
## 
## =================================================================
##                                  Dependent variable:             
##                     ---------------------------------------------
##                                       obama2012                  
##                              (1)                    (2)          
## -----------------------------------------------------------------
## abort_rate08               0.826***               0.681***       
##                            (0.130)                (0.161)        
##                                                                  
## density                                            0.008         
##                                                   (0.005)        
##                                                                  
## Constant                  35.259***              36.019***       
##                            (2.297)                (2.328)        
##                                                                  
## -----------------------------------------------------------------
## Observations                  50                     50          
## R2                          0.458                  0.482         
## Adjusted R2                 0.446                  0.459         
## Residual Std. Error    7.654 (df = 48)        7.564 (df = 47)    
## F Statistic         40.521*** (df = 1; 48) 21.827*** (df = 2; 47)
## =================================================================
## Note:                                 *p<0.1; **p<0.05; ***p<0.01

14.1.1 Exporting the regression table

To export the regression table, we use the option out to specify, where we want to save our regresion table. Below we save the table in the file tab-regression.htm.

stargazer(reg_obama, reg_obama_full, 
          type = "text",
          out="tab-regression.htm")

An .htm file is a HTML file you can open in your browser (e.g. Google Chrome). To get it into Word, simply open the file via Word. You might have to do some extra changes before it is ready for a broader audience. Always try to make your tables look like tables in published articles and books.