A Stargazer Cheatsheet

table
stargazer
package
Published

October 18, 2024

1 Dataset: dplyr and nycflights13

Setting up a dataset for this cheatsheet allows me to spotlight two recent R packages created by Hadley Wickham. The first, dplyr, is a set of new tools for data manipulation. Using dplyr, I will extract flights and weather data from another new package called nycflights13. With this data I will show how to estimate a couple of regression models and nicely format the results into tables with stargazer.

Note: stargazer v. 5.1 does not play nicely with dplyr’s tbl_df class. As a temporary work-around I pipe the merged dataset to data.frame.

Code
library("dplyr")
library("nycflights13")
library("AER") # Applied Econometrics with R
library("stargazer")

daily <- flights %>%
  filter(origin == "EWR") %>%
  group_by(year, month, day) %>%
  summarise(delay = mean(dep_delay, na.rm = TRUE))

daily_weather <- weather %>%
  filter(origin == "EWR") %>%
  group_by(year, month, day) %>%
  summarise(temp   = mean(temp, na.rm = TRUE),
            wind   = mean(wind_speed, na.rm = TRUE),
            precip = sum(precip, na.rm = TRUE))

# Merge flights with weather data frames
both <- inner_join(daily, daily_weather) %>% 
  data.frame()  # Temporary fix

# Create an indicator for quarter
both$quarter <- cut(both$month, breaks = c(0, 3, 6, 9, 12), 
                                labels = c("1", "2", "3", "4"))

# Create a vector of class logical
both$hot <- as.logical(both$temp > 85)

head(both)


We can use the both data frame to estimate a couple of linear models predicting the average delay out of Newark controlling for the weather. The first model will use only the weather variables and in the second I’ll add dummy variables indicating the quarter. I also estimate a third model, using using the ivreg command from package AER to demonstrate output with mixed models. The raw R output:

Code
output  <- lm(delay ~ temp + wind + precip, data = both)
output2 <- lm(delay ~ temp + wind + precip + quarter, data = both)

# Instrumental variables model 
output3 <- ivreg(delay ~ temp + wind + precip | . - temp + hot, data = both)

summary(output)

Call:
lm(formula = delay ~ temp + wind + precip, data = both)

Residuals:
    Min      1Q  Median      3Q     Max 
-47.164  -8.150  -3.148   4.667  70.493 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  6.15166    2.98897   2.058   0.0403 *  
temp         0.07905    0.03933   2.010   0.0452 *  
wind         0.28523    0.15741   1.812   0.0708 .  
precip      15.25495    2.01280   7.579 2.98e-13 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 12.82 on 360 degrees of freedom
Multiple R-squared:  0.1541,    Adjusted R-squared:  0.147 
F-statistic: 21.86 on 3 and 360 DF,  p-value: 5.003e-13
Code
summary(output2)

Call:
lm(formula = delay ~ temp + wind + precip + quarter, data = both)

Residuals:
    Min      1Q  Median      3Q     Max 
-47.458  -8.086  -3.294   4.542  69.426 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  5.24570    3.41233   1.537   0.1251    
temp         0.16433    0.06628   2.479   0.0136 *  
wind         0.23710    0.15733   1.507   0.1327    
precip      14.84493    2.00409   7.407 9.38e-13 ***
quarter2    -2.06050    2.57919  -0.799   0.4249    
quarter3    -6.75538    3.12100  -2.164   0.0311 *  
quarter4    -4.40842    2.03707  -2.164   0.0311 *  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 12.72 on 357 degrees of freedom
Multiple R-squared:  0.1747,    Adjusted R-squared:  0.1608 
F-statistic: 12.59 on 6 and 357 DF,  p-value: 6.823e-13
Code
summary(output3)

Call:
ivreg(formula = delay ~ temp + wind + precip | . - temp + hot, 
    data = both)

Residuals:
    Min      1Q  Median      3Q     Max 
-47.100  -8.386  -3.451   4.613  69.801 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)   8.5765     8.7968   0.975    0.330    
temp          0.0412     0.1350   0.305    0.760    
wind          0.2501     0.1980   1.263    0.207    
precip       15.3351     2.0338   7.540 3.86e-13 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 12.84 on 360 degrees of freedom
Multiple R-Squared: 0.1519, Adjusted R-squared: 0.1449 
Wald test: 20.49 on 3 and 360 DF,  p-value: 2.788e-12 


Back to table of contents

2 Quick notes

Since I’m using knitr and R markdown to create this webpage, in the code that follows I will include the stargazer option type = "html". stargazer is set to produce LaTeX output by default. If you desire LaTeX output, just remove the type option from the code below.


Also, while I have added an example for many of the available stargazer options, I have not included all of them. So while you’re likely to find a relevant example don’t assume if it’s not listed that stargazer can’t do it. Check the documentation for additional features and updates to the package. It is often the case that an omitted argument is specific for LaTeX output and I can’t demonstrate it here.

2.1 HTML formatting

It is possible to change the formatting of html tables generated with stargazer via an html style sheet. See the R Markdown documentation about incorporating a custom CSS.


Back to table of contents

3 The default summary statistics table

Code
stargazer(both, type = "html")
Statistic N Mean St. Dev. Min Max
year 364 2,013.000 0.000 2,013 2,013
month 364 6.511 3.445 1 12
day 364 15.679 8.784 1 31
delay 364 15.080 13.883 -1.349 97.771
temp 364 55.531 17.598 15.455 91.085
wind 364 9.464 4.398 2.637 56.388
precip 364 0.121 0.335 0.000 3.710
hot 364 0.022 0.147 0 1


When supplied a data frame, by default stargazer creates a table with summary statistics. If the summary option is set to FALSE then stargazer will instead print the contents of the data frame.

Code
# Use only a few rows
both2 <- both %>% slice(1:6)

stargazer(both2, type = "html", summary = FALSE, rownames = FALSE)
year month day delay temp wind precip quarter hot
2,013 1 1 17.484 36.819 13.234 0 1 FALSE
2,013 1 2 25.323 28.700 10.884 0 1 FALSE
2,013 1 3 8.450 29.578 8.583 0 1 FALSE
2,013 1 4 12.104 34.333 14.001 0 1 FALSE
2,013 1 5 5.696 36.560 9.398 0 1 FALSE
2,013 1 6 12.383 39.920 9.110 0 1 FALSE

3.1 Remove row and column names

Code
stargazer(both2, type = "html", summary = FALSE,
          rownames = FALSE,
          colnames = FALSE)
2,013 1 1 17.484 36.819 13.234 0 1 FALSE
2,013 1 2 25.323 28.700 10.884 0 1 FALSE
2,013 1 3 8.450 29.578 8.583 0 1 FALSE
2,013 1 4 12.104 34.333 14.001 0 1 FALSE
2,013 1 5 5.696 36.560 9.398 0 1 FALSE
2,013 1 6 12.383 39.920 9.110 0 1 FALSE

3.2 Change which statistics are displayed

In order to customize which summary statistics are displayed, change any of the the following (logical) parameters, nobs, mean.sd, min.max, median, and iqr.

Code
stargazer(both, type = "html", nobs = FALSE, mean.sd = TRUE, median = TRUE,
          iqr = TRUE)
Statistic Mean St. Dev. Min Pctl(25) Median Pctl(75) Max
year 2,013.000 0.000 2,013 2,013 2,013 2,013 2,013
month 6.511 3.445 1 4 7 9.2 12
day 15.679 8.784 1 8 16 23 31
delay 15.080 13.883 -1.349 5.446 10.501 20.007 97.771
temp 55.531 17.598 15.455 40.114 56.356 71.647 91.085
wind 9.464 4.398 2.637 6.797 8.895 11.508 56.388
precip 0.121 0.335 0.000 0.000 0.000 0.030 3.710
hot 0.022 0.147 0 0 0 0 1

3.3 Change which statistics are displayed (a second way)

Code
stargazer(both, type = "html", summary.stat = c("n", "p75", "sd"))
Statistic N Pctl(75) St. Dev.
year 364 2,013 0.000
month 364 9.2 3.445
day 364 23 8.784
delay 364 20.007 13.883
temp 364 71.647 17.598
wind 364 11.508 4.398
precip 364 0.030 0.335
hot 364 0 0.147

3.4 Remove logical variables in the summary statistics

stargazer reports summary statistics for logical variables by default (0 = FALSE and 1 = TRUE). To supress the reporting of logical vectors change summary.logical to FALSE. Note the stats for our vector hot are gone.

Code
stargazer(both, type = "html", summary.logical = FALSE)
Statistic N Mean St. Dev. Min Max
year 364 2,013.000 0.000 2,013 2,013
month 364 6.511 3.445 1 12
day 364 15.679 8.784 1 31
delay 364 15.080 13.883 -1.349 97.771
temp 364 55.531 17.598 15.455 91.085
wind 364 9.464 4.398 2.637 56.388
precip 364 0.121 0.335 0.000 3.710

3.5 Flip the table axes

Code
stargazer(both, type = "html", flip = TRUE)
Statistic year month day delay temp wind precip hot
N 364 364 364 364 364 364 364 364
Mean 2,013.000 6.511 15.679 15.080 55.531 9.464 0.121 0.022
St. Dev. 0.000 3.445 8.784 13.883 17.598 4.398 0.335 0.147
Min 2,013 1 1 -1.349 15.455 2.637 0.000 0
Max 2,013 12 31 97.771 91.085 56.388 3.710 1


Back to table of contents

4 The default regression table

Code
stargazer(output, output2, type = "html")
Dependent variable:
delay
(1) (2)
temp 0.079** 0.164**
(0.039) (0.066)
wind 0.285* 0.237
(0.157) (0.157)
precip 15.255*** 14.845***
(2.013) (2.004)
quarter2 -2.060
(2.579)
quarter3 -6.755**
(3.121)
quarter4 -4.408**
(2.037)
Constant 6.152** 5.246
(2.989) (3.412)
Observations 364 364
R2 0.154 0.175
Adjusted R2 0.147 0.161
Residual Std. Error 12.822 (df = 360) 12.718 (df = 357)
F Statistic 21.860*** (df = 3; 360) 12.593*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01


Back to table of contents

5 Change the style

stargazer includes several pre-formatted styles that imitate popular academic journals. Use the style argument.

Code
stargazer(output, output2, type = "html", style = "qje")
delay
(1) (2)
temp 0.079** 0.164**
(0.039) (0.066)
wind 0.285* 0.237
(0.157) (0.157)
precip 15.255*** 14.845***
(2.013) (2.004)
quarter2 -2.060
(2.579)
quarter3 -6.755**
(3.121)
quarter4 -4.408**
(2.037)
Constant 6.152** 5.246
(2.989) (3.412)
N 364 364
R2 0.154 0.175
Adjusted R2 0.147 0.161
Residual Std. Error 12.822 (df = 360) 12.718 (df = 357)
F Statistic 21.860*** (df = 3; 360) 12.593*** (df = 6; 357)
Notes: ***Significant at the 1 percent level.
**Significant at the 5 percent level.
*Significant at the 10 percent level.


Back to table of contents

6 Labelling the table

6.1 Add a title; change the variable labels

Code
stargazer(output, output2, type = "html", 
          title            = "These are awesome results!",
          covariate.labels = c("Temperature", "Wind speed", "Rain (inches)",
                               "2nd quarter", "3rd quarter", "Fourth quarter"),
          dep.var.caption  = "A better caption",
          dep.var.labels   = "Flight delay (in minutes)")
These are awesome results!
A better caption
Flight delay (in minutes)
(1) (2)
Temperature 0.079** 0.164**
(0.039) (0.066)
Wind speed 0.285* 0.237
(0.157) (0.157)
Rain (inches) 15.255*** 14.845***
(2.013) (2.004)
2nd quarter -2.060
(2.579)
3rd quarter -6.755**
(3.121)
Fourth quarter -4.408**
(2.037)
Constant 6.152** 5.246
(2.989) (3.412)
Observations 364 364
R2 0.154 0.175
Adjusted R2 0.147 0.161
Residual Std. Error 12.822 (df = 360) 12.718 (df = 357)
F Statistic 21.860*** (df = 3; 360) 12.593*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01

6.2 Exclude the dependent variable label or the model numbers

Note the dependent variable caption stays. To additionally remove the caption add dep.var.caption = "".

Code
stargazer(output, output2, type = "html", 
          dep.var.labels.include = FALSE,
          model.numbers          = FALSE)
Dependent variable:
temp 0.079** 0.164**
(0.039) (0.066)
wind 0.285* 0.237
(0.157) (0.157)
precip 15.255*** 14.845***
(2.013) (2.004)
quarter2 -2.060
(2.579)
quarter3 -6.755**
(3.121)
quarter4 -4.408**
(2.037)
Constant 6.152** 5.246
(2.989) (3.412)
Observations 364 364
R2 0.154 0.175
Adjusted R2 0.147 0.161
Residual Std. Error 12.822 (df = 360) 12.718 (df = 357)
F Statistic 21.860*** (df = 3; 360) 12.593*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01

6.3 Change the column names

To change the column names just supply a character vector with the new labels, as shown below.

Code
stargazer(output, output2, type = "html", column.labels = c("Good", "Better"))
Dependent variable:
delay
Good Better
(1) (2)
temp 0.079** 0.164**
(0.039) (0.066)
wind 0.285* 0.237
(0.157) (0.157)
precip 15.255*** 14.845***
(2.013) (2.004)
quarter2 -2.060
(2.579)
quarter3 -6.755**
(3.121)
quarter4 -4.408**
(2.037)
Constant 6.152** 5.246
(2.989) (3.412)
Observations 364 364
R2 0.154 0.175
Adjusted R2 0.147 0.161
Residual Std. Error 12.822 (df = 360) 12.718 (df = 357)
F Statistic 21.860*** (df = 3; 360) 12.593*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01

6.4 Apply a label to more than one column

The option column.separate allows for assigning a label to more than one column. In this example I told stargazer to report each regression twice, for a total of four columns. Using column.separate, stargazer now applies the first label to the first two columns and the second label to the next two columns.

Code
stargazer(output, output, output2, output2, type = "html", 
          column.labels   = c("Good", "Better"),
          column.separate = c(2, 2))
Dependent variable:
delay
Good Better
(1) (2) (3) (4)
temp 0.079** 0.079** 0.164** 0.164**
(0.039) (0.039) (0.066) (0.066)
wind 0.285* 0.285* 0.237 0.237
(0.157) (0.157) (0.157) (0.157)
precip 15.255*** 15.255*** 14.845*** 14.845***
(2.013) (2.013) (2.004) (2.004)
quarter2 -2.060 -2.060
(2.579) (2.579)
quarter3 -6.755** -6.755**
(3.121) (3.121)
quarter4 -4.408** -4.408**
(2.037) (2.037)
Constant 6.152** 6.152** 5.246 5.246
(2.989) (2.989) (3.412) (3.412)
Observations 364 364 364 364
R2 0.154 0.154 0.175 0.175
Adjusted R2 0.147 0.147 0.161 0.161
Residual Std. Error 12.822 (df = 360) 12.822 (df = 360) 12.718 (df = 357) 12.718 (df = 357)
F Statistic 21.860*** (df = 3; 360) 21.860*** (df = 3; 360) 12.593*** (df = 6; 357) 12.593*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01

6.5 Model names

When the results from different types of regression models (e.g., “OLS”, “probit”) are displayed in the same table stargazer adds a row indicating model type. Remove these labels by including model.names = FALSE (not shown).

Code
stargazer(output, output2, output3, type = "html")
Dependent variable:
delay
OLS instrumental
variable
(1) (2) (3)
temp 0.079** 0.164** 0.041
(0.039) (0.066) (0.135)
wind 0.285* 0.237 0.250
(0.157) (0.157) (0.198)
precip 15.255*** 14.845*** 15.335***
(2.013) (2.004) (2.034)
quarter2 -2.060
(2.579)
quarter3 -6.755**
(3.121)
quarter4 -4.408**
(2.037)
Constant 6.152** 5.246 8.577
(2.989) (3.412) (8.797)
Observations 364 364 364
R2 0.154 0.175 0.152
Adjusted R2 0.147 0.161 0.145
Residual Std. Error 12.822 (df = 360) 12.718 (df = 357) 12.839 (df = 360)
F Statistic 21.860*** (df = 3; 360) 12.593*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01

6.6 Model names (again)

The example above shows the default behavior of stargazer is to display only one model name (and dependent variable caption) for adjacent columns with the same model type. To repeat these labels for all of the columns, do the following:

Code
stargazer(output, output2, output3, type = "html",
          multicolumn = FALSE)
Dependent variable:
delay delay delay
OLS OLS instrumental
variable
(1) (2) (3)
temp 0.079** 0.164** 0.041
(0.039) (0.066) (0.135)
wind 0.285* 0.237 0.250
(0.157) (0.157) (0.198)
precip 15.255*** 14.845*** 15.335***
(2.013) (2.004) (2.034)
quarter2 -2.060
(2.579)
quarter3 -6.755**
(3.121)
quarter4 -4.408**
(2.037)
Constant 6.152** 5.246 8.577
(2.989) (3.412) (8.797)
Observations 364 364 364
R2 0.154 0.175 0.152
Adjusted R2 0.147 0.161 0.145
Residual Std. Error 12.822 (df = 360) 12.718 (df = 357) 12.839 (df = 360)
F Statistic 21.860*** (df = 3; 360) 12.593*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01

6.7 Add a custom row to the reported statistics

I use this example to show how to add a row(s), such as reporting fixed effects.

Code
stargazer(output, output2, type = "html",
          add.lines = list(c("Fixed effects?", "No", "No"),
                           c("Results believable?", "Maybe", "Try again later")))
Dependent variable:
delay
(1) (2)
temp 0.079** 0.164**
(0.039) (0.066)
wind 0.285* 0.237
(0.157) (0.157)
precip 15.255*** 14.845***
(2.013) (2.004)
quarter2 -2.060
(2.579)
quarter3 -6.755**
(3.121)
quarter4 -4.408**
(2.037)
Constant 6.152** 5.246
(2.989) (3.412)
Fixed effects? No No
Results believable? Maybe Try again later
Observations 364 364
R2 0.154 0.175
Adjusted R2 0.147 0.161
Residual Std. Error 12.822 (df = 360) 12.718 (df = 357)
F Statistic 21.860*** (df = 3; 360) 12.593*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01

6.8 Include R object names

Code
stargazer(output, output2, type = "html", 
          object.names = TRUE)
Dependent variable:
delay
(1) (2)
output output2
temp 0.079** 0.164**
(0.039) (0.066)
wind 0.285* 0.237
(0.157) (0.157)
precip 15.255*** 14.845***
(2.013) (2.004)
quarter2 -2.060
(2.579)
quarter3 -6.755**
(3.121)
quarter4 -4.408**
(2.037)
Constant 6.152** 5.246
(2.989) (3.412)
Observations 364 364
R2 0.154 0.175
Adjusted R2 0.147 0.161
Residual Std. Error 12.822 (df = 360) 12.718 (df = 357)
F Statistic 21.860*** (df = 3; 360) 12.593*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01


Back to table of contents

7 Change the default output

7.1 Report t-statistics or p-values instead of standard errors

Standard errors are reported by default. To report the t-statistics or p-values instead, see the report argument. Notice that I’ve used this option to move the star characters to the t-statistics instead of being next to the coefficients.

Code
stargazer(output, output2, type = "html",
          report = "vct*")
Dependent variable:
delay
(1) (2)
temp 0.079 0.164
t = 2.010** t = 2.479**
wind 0.285 0.237
t = 1.812* t = 1.507
precip 15.255 14.845
t = 7.579*** t = 7.407***
quarter2 -2.060
t = -0.799
quarter3 -6.755
t = -2.164**
quarter4 -4.408
t = -2.164**
Constant 6.152 5.246
t = 2.058** t = 1.537
Observations 364 364
R2 0.154 0.175
Adjusted R2 0.147 0.161
Residual Std. Error 12.822 (df = 360) 12.718 (df = 357)
F Statistic 21.860*** (df = 3; 360) 12.593*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01

7.2 Report confidence intervals

Code
stargazer(output, output2, type = "html",
          ci = TRUE)
Dependent variable:
delay
(1) (2)
temp 0.079** 0.164**
(0.002, 0.156) (0.034, 0.294)
wind 0.285* 0.237
(-0.023, 0.594) (-0.071, 0.545)
precip 15.255*** 14.845***
(11.310, 19.200) (10.917, 18.773)
quarter2 -2.060
(-7.116, 2.995)
quarter3 -6.755**
(-12.872, -0.638)
quarter4 -4.408**
(-8.401, -0.416)
Constant 6.152** 5.246
(0.293, 12.010) (-1.442, 11.934)
Observations 364 364
R2 0.154 0.175
Adjusted R2 0.147 0.161
Residual Std. Error 12.822 (df = 360) 12.718 (df = 357)
F Statistic 21.860*** (df = 3; 360) 12.593*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01

7.3 Adjust the confidence intervals

By default ci.level = 0.95. You may also change the character that separates the intervals with the ci.separator argument.

Code
stargazer(output, output2, type = "html",
          ci = TRUE, ci.level = 0.90, ci.separator = " @@ ")
Dependent variable:
delay
(1) (2)
temp 0.079** 0.164**
(0.014 @@ 0.144) (0.055 @@ 0.273)
wind 0.285* 0.237
(0.026 @@ 0.544) (-0.022 @@ 0.496)
precip 15.255*** 14.845***
(11.944 @@ 18.566) (11.548 @@ 18.141)
quarter2 -2.060
(-6.303 @@ 2.182)
quarter3 -6.755**
(-11.889 @@ -1.622)
quarter4 -4.408**
(-7.759 @@ -1.058)
Constant 6.152** 5.246
(1.235 @@ 11.068) (-0.367 @@ 10.858)
Observations 364 364
R2 0.154 0.175
Adjusted R2 0.147 0.161
Residual Std. Error 12.822 (df = 360) 12.718 (df = 357)
F Statistic 21.860*** (df = 3; 360) 12.593*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01

7.4 Robust standard errors (replicating Stata’s robust option)

If you want to use robust standard errors (or clustered), stargazer allows for replacing the default output by supplying a new vector of values to the option se. For this example I will display the same model twice and adjust the standard errors in the second column with the HC1 correction from the sandwich package (i.e. the same correction Stata uses).

I also need to adjust the F statistic with the corrected variance-covariance matrix (matching Stata’s results). Currently, this must be done manually (via add.lines) as stargazer does not (yet) have an option for directly replacing the F statistic.

Similar options exist to supply adjusted values to the coefficients, t-statistics, confidence intervals, and p-values. See coef, t, ci.custom, or p.

Code
library(sandwich)
library(lmtest)   # waldtest; see also coeftest.

# Adjust standard errors
cov1         <- vcovHC(output, type = "HC1")
robust_se    <- sqrt(diag(cov1))

# Adjust F statistic 
wald_results <- waldtest(output, vcov = cov1)

stargazer(output, output, type = "html",
          se        = list(NULL, robust_se),
          omit.stat = "f",
          add.lines = list(c("F Statistic (df = 3; 360)", "12.879***", "7.73***")))
Dependent variable:
delay
(1) (2)
temp 0.079** 0.079*
(0.039) (0.041)
wind 0.285* 0.285
(0.157) (0.177)
precip 15.255*** 15.255***
(2.013) (4.827)
Constant 6.152** 6.152**
(2.989) (3.074)
F Statistic (df = 3; 360) 12.879*** 7.73***
Observations 364 364
R2 0.154 0.154
Adjusted R2 0.147 0.147
Residual Std. Error (df = 360) 12.822 12.822
Note: p<0.1; p<0.05; p<0.01

7.5 Move the intercept term to the top of the table

Code
stargazer(output, output2, type = "html",
          intercept.bottom = FALSE)
Dependent variable:
delay
(1) (2)
Constant 6.152** 5.246
(2.989) (3.412)
temp 0.079** 0.164**
(0.039) (0.066)
wind 0.285* 0.237
(0.157) (0.157)
precip 15.255*** 14.845***
(2.013) (2.004)
quarter2 -2.060
(2.579)
quarter3 -6.755**
(3.121)
quarter4 -4.408**
(2.037)
Observations 364 364
R2 0.154 0.175
Adjusted R2 0.147 0.161
Residual Std. Error 12.822 (df = 360) 12.718 (df = 357)
F Statistic 21.860*** (df = 3; 360) 12.593*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01

7.6 Compress the table output

We can condense the table output by placing all the the output on the same row. When single.row is set to TRUE, the argument no.space is automatically set to TRUE.

Code
stargazer(output, output2, type = "html",
          single.row = TRUE)
Dependent variable:
delay
(1) (2)
temp 0.079** (0.039) 0.164** (0.066)
wind 0.285* (0.157) 0.237 (0.157)
precip 15.255*** (2.013) 14.845*** (2.004)
quarter2 -2.060 (2.579)
quarter3 -6.755** (3.121)
quarter4 -4.408** (2.037)
Constant 6.152** (2.989) 5.246 (3.412)
Observations 364 364
R2 0.154 0.175
Adjusted R2 0.147 0.161
Residual Std. Error 12.822 (df = 360) 12.718 (df = 357)
F Statistic 21.860*** (df = 3; 360) 12.593*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01


Back to table of contents

8 Omit parts of the default output

In fixed effect model specifications it is often undesirable to report the fixed effect coefficients. To omit any coefficient, supply a regular expression to omit.

Code
stargazer(output, output2, type = "html", omit = "quarter")
Dependent variable:
delay
(1) (2)
temp 0.079** 0.164**
(0.039) (0.066)
wind 0.285* 0.237
(0.157) (0.157)
precip 15.255*** 14.845***
(2.013) (2.004)
Constant 6.152** 5.246
(2.989) (3.412)
Observations 364 364
R2 0.154 0.175
Adjusted R2 0.147 0.161
Residual Std. Error 12.822 (df = 360) 12.718 (df = 357)
F Statistic 21.860*** (df = 3; 360) 12.593*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01

8.1 Reporting omitted variables

Add the omit.labels parameter to report which variables have been omitted. Must be the same length as the number of regular expressions supplied to omit. By default omit.labels reports “Yes” or “No”. To change this supply a new vector of length 2 to omit.yes.no = c("Yes", "No").

Code
stargazer(output, output2, type = "html", 
          omit        = "quarter",
          omit.labels = "Quarter dummies?")
Dependent variable:
delay
(1) (2)
temp 0.079** 0.164**
(0.039) (0.066)
wind 0.285* 0.237
(0.157) (0.157)
precip 15.255*** 14.845***
(2.013) (2.004)
Constant 6.152** 5.246
(2.989) (3.412)
Quarter dummies? No No
Observations 364 364
R2 0.154 0.175
Adjusted R2 0.147 0.161
Residual Std. Error 12.822 (df = 360) 12.718 (df = 357)
F Statistic 21.860*** (df = 3; 360) 12.593*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01

8.2 Omit summary statistics

Code
## Remove r-square and f-statistic
stargazer(output, output2, type = "html", 
          omit.stat = c("rsq", "f"))
Dependent variable:
delay
(1) (2)
temp 0.079** 0.164**
(0.039) (0.066)
wind 0.285* 0.237
(0.157) (0.157)
precip 15.255*** 14.845***
(2.013) (2.004)
quarter2 -2.060
(2.579)
quarter3 -6.755**
(3.121)
quarter4 -4.408**
(2.037)
Constant 6.152** 5.246
(2.989) (3.412)
Observations 364 364
Adjusted R2 0.147 0.161
Residual Std. Error 12.822 (df = 360) 12.718 (df = 357)
Note: p<0.1; p<0.05; p<0.01


See also keep.stat a related argument with the opposite behavior.

8.3 Omit whole parts of the table

If you just want to remove parts of the table it is easier to use omit.table.layout to explicitly specify table elements. See table layout chracters for a list of codes.

Code
# Remove statistics and notes sections completely
stargazer(output, output2, type = "html", 
          omit.table.layout = "sn")
Dependent variable:
delay
(1) (2)
temp 0.079** 0.164**
(0.039) (0.066)
wind 0.285* 0.237
(0.157) (0.157)
precip 15.255*** 14.845***
(2.013) (2.004)
quarter2 -2.060
(2.579)
quarter3 -6.755**
(3.121)
quarter4 -4.408**
(2.037)
Constant 6.152** 5.246
(2.989) (3.412)

8.4 Omit whole parts of the table (a second way)

Another way to achieve the result above is through the argument table.layout. It also accepts a character string that tells stargazer which table elements to include.

Code
# Include everything except the statistics and notes sections
stargazer(output, output2, type = "html", 
          table.layout = "-ld#-t-")
Dependent variable:
delay
(1) (2)
temp 0.079** 0.164**
(0.039) (0.066)
wind 0.285* 0.237
(0.157) (0.157)
precip 15.255*** 14.845***
(2.013) (2.004)
quarter2 -2.060
(2.579)
quarter3 -6.755**
(3.121)
quarter4 -4.408**
(2.037)
Constant 6.152** 5.246
(2.989) (3.412)

8.5 Omit the degrees of freedom

Code
stargazer(output, output2, type = "html", 
          df = FALSE)
Dependent variable:
delay
(1) (2)
temp 0.079** 0.164**
(0.039) (0.066)
wind 0.285* 0.237
(0.157) (0.157)
precip 15.255*** 14.845***
(2.013) (2.004)
quarter2 -2.060
(2.579)
quarter3 -6.755**
(3.121)
quarter4 -4.408**
(2.037)
Constant 6.152** 5.246
(2.989) (3.412)
Observations 364 364
R2 0.154 0.175
Adjusted R2 0.147 0.161
Residual Std. Error 12.822 12.718
F Statistic 21.860*** 12.593***
Note: p<0.1; p<0.05; p<0.01


Back to table of contents

9 Statistical significance options

By default stargazer uses ***, **, and * to denote statistical significance at the one, five, and ten percent levels. This behavior can be changed by altering the star.char option.

Code
stargazer(output, output2, type = "html", 
          star.char = c("@", "@@", "@@@"))
Dependent variable:
delay
(1) (2)
temp 0.079@@ 0.164@@
(0.039) (0.066)
wind 0.285@ 0.237
(0.157) (0.157)
precip 15.255@@@ 14.845@@@
(2.013) (2.004)
quarter2 -2.060
(2.579)
quarter3 -6.755@@
(3.121)
quarter4 -4.408@@
(2.037)
Constant 6.152@@ 5.246
(2.989) (3.412)
Observations 364 364
R2 0.154 0.175
Adjusted R2 0.147 0.161
Residual Std. Error 12.822 (df = 360) 12.718 (df = 357)
F Statistic 21.860@@@ (df = 3; 360) 12.593@@@ (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01

9.1 Change the cutoffs for significance

Notice that temperature, quarter3, and quarter4 have each lost a gold star because we made it tougher to earn them.

Code
stargazer(output, output2, type = "html", 
          star.cutoffs = c(0.05, 0.01, 0.001)) # star.cutoffs = NULL by default
Dependent variable:
delay
(1) (2)
temp 0.079* 0.164*
(0.039) (0.066)
wind 0.285 0.237
(0.157) (0.157)
precip 15.255*** 14.845***
(2.013) (2.004)
quarter2 -2.060
(2.579)
quarter3 -6.755*
(3.121)
quarter4 -4.408*
(2.037)
Constant 6.152* 5.246
(2.989) (3.412)
Observations 364 364
R2 0.154 0.175
Adjusted R2 0.147 0.161
Residual Std. Error 12.822 (df = 360) 12.718 (df = 357)
F Statistic 21.860*** (df = 3; 360) 12.593*** (df = 6; 357)
Note: p<0.05; p<0.01; p<0.001


Back to table of contents

10 Modifying table notes

10.1 Make an addition to the existing note section

Code
stargazer(output, output2, type = "html", 
          notes = "I make this look good!")
Dependent variable:
delay
(1) (2)
temp 0.079** 0.164**
(0.039) (0.066)
wind 0.285* 0.237
(0.157) (0.157)
precip 15.255*** 14.845***
(2.013) (2.004)
quarter2 -2.060
(2.579)
quarter3 -6.755**
(3.121)
quarter4 -4.408**
(2.037)
Constant 6.152** 5.246
(2.989) (3.412)
Observations 364 364
R2 0.154 0.175
Adjusted R2 0.147 0.161
Residual Std. Error 12.822 (df = 360) 12.718 (df = 357)
F Statistic 21.860*** (df = 3; 360) 12.593*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01
I make this look good!

10.2 Replace the note section

Code
stargazer(output, output2, type = "html", 
          notes        = "Sometimes you just have to start over.", 
          notes.append = FALSE)
Dependent variable:
delay
(1) (2)
temp 0.079** 0.164**
(0.039) (0.066)
wind 0.285* 0.237
(0.157) (0.157)
precip 15.255*** 14.845***
(2.013) (2.004)
quarter2 -2.060
(2.579)
quarter3 -6.755**
(3.121)
quarter4 -4.408**
(2.037)
Constant 6.152** 5.246
(2.989) (3.412)
Observations 364 364
R2 0.154 0.175
Adjusted R2 0.147 0.161
Residual Std. Error 12.822 (df = 360) 12.718 (df = 357)
F Statistic 21.860*** (df = 3; 360) 12.593*** (df = 6; 357)
Note: Sometimes you just have to start over.

10.3 Change note alignment

Code
stargazer(output, output2, type = "html", 
          notes.align = "l")
Dependent variable:
delay
(1) (2)
temp 0.079** 0.164**
(0.039) (0.066)
wind 0.285* 0.237
(0.157) (0.157)
precip 15.255*** 14.845***
(2.013) (2.004)
quarter2 -2.060
(2.579)
quarter3 -6.755**
(3.121)
quarter4 -4.408**
(2.037)
Constant 6.152** 5.246
(2.989) (3.412)
Observations 364 364
R2 0.154 0.175
Adjusted R2 0.147 0.161
Residual Std. Error 12.822 (df = 360) 12.718 (df = 357)
F Statistic 21.860*** (df = 3; 360) 12.593*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01

10.4 Change the note section label

Code
stargazer(output, output2, type = "html", 
          notes.label = "New note label")
Dependent variable:
delay
(1) (2)
temp 0.079** 0.164**
(0.039) (0.066)
wind 0.285* 0.237
(0.157) (0.157)
precip 15.255*** 14.845***
(2.013) (2.004)
quarter2 -2.060
(2.579)
quarter3 -6.755**
(3.121)
quarter4 -4.408**
(2.037)
Constant 6.152** 5.246
(2.989) (3.412)
Observations 364 364
R2 0.154 0.175
Adjusted R2 0.147 0.161
Residual Std. Error 12.822 (df = 360) 12.718 (df = 357)
F Statistic 21.860*** (df = 3; 360) 12.593*** (df = 6; 357)
New note label p<0.1; p<0.05; p<0.01


Back to table of contents

11 Table aesthetics

11.1 Use html tags to modify table elements

Code
# For LaTeX output you can also wrap table text in commands like \textbf{...}, 
# just remember to escape the first backslash, e.g., "A \\textbf{better} caption"

stargazer(output, output2, type = "html", 
          title = "These are <em> awesome </em> results!",  # Italics
          dep.var.caption  = "A <b> better </b> caption")   # Bold
These are awesome results!
A better caption
delay
(1) (2)
temp 0.079** 0.164**
(0.039) (0.066)
wind 0.285* 0.237
(0.157) (0.157)
precip 15.255*** 14.845***
(2.013) (2.004)
quarter2 -2.060
(2.579)
quarter3 -6.755**
(3.121)
quarter4 -4.408**
(2.037)
Constant 6.152** 5.246
(2.989) (3.412)
Observations 364 364
R2 0.154 0.175
Adjusted R2 0.147 0.161
Residual Std. Error 12.822 (df = 360) 12.718 (df = 357)
F Statistic 21.860*** (df = 3; 360) 12.593*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01

11.2 Change decimal character

Code
stargazer(output, output2, type = "html", 
          decimal.mark = ",")
Dependent variable:
delay
(1) (2)
temp 0,079** 0,164**
(0,039) (0,066)
wind 0,285* 0,237
(0,157) (0,157)
precip 15,255*** 14,845***
(2,013) (2,004)
quarter2 -2,060
(2,579)
quarter3 -6,755**
(3,121)
quarter4 -4,408**
(2,037)
Constant 6,152** 5,246
(2,989) (3,412)
Observations 364 364
R2 0,154 0,175
Adjusted R2 0,147 0,161
Residual Std. Error 12,822 (df = 360) 12,718 (df = 357)
F Statistic 21,860*** (df = 3; 360) 12,593*** (df = 6; 357)
Note: p<0,1; p<0,05; p<0,01

11.3 Control the number of decimal places

Code
stargazer(output, output2, type = "html", 
          digits = 1)
Dependent variable:
delay
(1) (2)
temp 0.1** 0.2**
(0.04) (0.1)
wind 0.3* 0.2
(0.2) (0.2)
precip 15.3*** 14.8***
(2.0) (2.0)
quarter2 -2.1
(2.6)
quarter3 -6.8**
(3.1)
quarter4 -4.4**
(2.0)
Constant 6.2** 5.2
(3.0) (3.4)
Observations 364 364
R2 0.2 0.2
Adjusted R2 0.1 0.2
Residual Std. Error 12.8 (df = 360) 12.7 (df = 357)
F Statistic 21.9*** (df = 3; 360) 12.6*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01

11.4 Additional decimal controls

You may also specify the number of additional decimal places to be used if a number, when rounded to digits decimal places, is equal to zero (Use argument digits.extra).

My example models do not have any numbers in the thousands, so I won’t show them, but digit.separate and digits.separator are also available for customizing the output of those characters.

Code
stargazer(output, output2, type = "html", 
          digits       = 1,
          digits.extra = 1)
Dependent variable:
delay
(1) (2)
temp 0.1** 0.2**
(0.04) (0.1)
wind 0.3* 0.2
(0.2) (0.2)
precip 15.3*** 14.8***
(2.0) (2.0)
quarter2 -2.1
(2.6)
quarter3 -6.8**
(3.1)
quarter4 -4.4**
(2.0)
Constant 6.2** 5.2
(3.0) (3.4)
Observations 364 364
R2 0.2 0.2
Adjusted R2 0.1 0.2
Residual Std. Error 12.8 (df = 360) 12.7 (df = 357)
F Statistic 21.9*** (df = 3; 360) 12.6*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01

11.5 Drop leading zeros from decimals

Code
stargazer(output, output2, type = "html", 
          initial.zero = FALSE)
Dependent variable:
delay
(1) (2)
temp .079** .164**
(.039) (.066)
wind .285* .237
(.157) (.157)
precip 15.255*** 14.845***
(2.013) (2.004)
quarter2 -2.060
(2.579)
quarter3 -6.755**
(3.121)
quarter4 -4.408**
(2.037)
Constant 6.152** 5.246
(2.989) (3.412)
Observations 364 364
R2 .154 .175
Adjusted R2 .147 .161
Residual Std. Error 12.822 (df = 360) 12.718 (df = 357)
F Statistic 21.860*** (df = 3; 360) 12.593*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01

11.6 Change the order of the variables

The order argument will also accept a vector of regular expressions.

Code
stargazer(output, output2, type = "html", 
          order = c(4, 5, 6, 3, 2, 1))
Dependent variable:
delay
(1) (2)
quarter2 -2.060
(2.579)
quarter3 -6.755**
(3.121)
quarter4 -4.408**
(2.037)
precip 15.255*** 14.845***
(2.013) (2.004)
wind 0.285* 0.237
(0.157) (0.157)
temp 0.079** 0.164**
(0.039) (0.066)
Constant 6.152** 5.246
(2.989) (3.412)
Observations 364 364
R2 0.154 0.175
Adjusted R2 0.147 0.161
Residual Std. Error 12.822 (df = 360) 12.718 (df = 357)
F Statistic 21.860*** (df = 3; 360) 12.593*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01

11.7 Select which variables to keep in the table

By default keep = NULL meaning all variables are included. keep accepts a vector of regular expressions.

Code
# Regex for keep "precip" but not "precipitation"
stargazer(output, output2, type = "html", 
          keep = c("\\bprecip\\b"))
Dependent variable:
delay
(1) (2)
precip 15.255*** 14.845***
(2.013) (2.004)
Observations 364 364
R2 0.154 0.175
Adjusted R2 0.147 0.161
Residual Std. Error 12.822 (df = 360) 12.718 (df = 357)
F Statistic 21.860*** (df = 3; 360) 12.593*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01


Back to table of contents

12 Feedback

The .Rmd file for this cheatsheet is on GitHub and I welcome suggestions or pull requests.


Back to table of contents

Back to top