Escolar Documentos
Profissional Documentos
Cultura Documentos
A Stargazer Cheatsheet
Updated 06 May, 2016
Dataset: dplyr and nyc倀ights13
Quick notes
HTML formatting
The default summary statistics table
Remove row and column names
Change which statistics are displayed
Change which statistics are displayed (a second way)
Remove logical variables in the summary statistics
Flip the table axes
The default regression table
Change the style
Labelling the table
Add a title; change the variable labels
Exclude the dependent variable label or the model numbers
Change the column names
Apply a label to more than one column
Model names
Model names (again)
Add a custom row to the reported statistics
Include R object names
Change the default output
Report t-statistics or p-values instead of standard errors
Report con᠈Ādence intervals
Adjust the con᠈Ādence intervals
Robust standard errors (replicating Stata’s robust option)
Move the intercept term to the top of the table
Compress the table output
Omit parts of the default output
Reporting omitted variables
Omit summary statistics
Omit whole parts of the table
http://jakeruss.com/cheatsheets/stargazer.html 1/40
7/19/2016 A Stargazer Cheatsheet
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 .
http://jakeruss.com/cheatsheets/stargazer.html 2/40
7/19/2016 A Stargazer Cheatsheet
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)
## year month day delay temp wind precip quarter hot
## 1 2013 1 1 17.483553 38.4800 12.758648 0 1 FALSE
## 2 2013 1 2 25.322674 28.8350 12.514732 0 1 FALSE
## 3 2013 1 3 8.450450 29.4575 7.863663 0 1 FALSE
## 4 2013 1 4 12.103858 33.4775 13.857309 0 1 FALSE
## 5 2013 1 5 5.696203 36.7325 10.836512 0 1 FALSE
## 6 2013 1 6 12.383333 37.9700 8.007511 0 1 FALSE
http://jakeruss.com/cheatsheets/stargazer.html 3/40
7/19/2016 A Stargazer Cheatsheet
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 ᠈Ārst 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 (http://cran.r-project.org/web/packages/AER/index.html) to
demonstrate output with mixed models. The raw R output:
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
## ‐26.201 ‐8.497 ‐3.533 4.708 75.727
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 7.26298 3.09879 2.344 0.0196 *
## temp 0.08808 0.04068 2.165 0.0310 *
## wind 0.16648 0.16392 1.016 0.3105
## precip 18.91805 3.24948 5.822 1.29e‐08 ***
## ‐‐‐
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 13.25 on 360 degrees of freedom
## Multiple R‐squared: 0.09693, Adjusted R‐squared: 0.0894
## F‐statistic: 12.88 on 3 and 360 DF, p‐value: 5.19e‐08
summary(output2)
http://jakeruss.com/cheatsheets/stargazer.html 4/40
7/19/2016 A Stargazer Cheatsheet
##
## Call:
## lm(formula = delay ~ temp + wind + precip + quarter, data = both)
##
## Residuals:
## Min 1Q Median 3Q Max
## ‐26.927 ‐8.740 ‐3.937 5.181 74.631
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 6.14163 3.53599 1.737 0.08327 .
## temp 0.18396 0.06856 2.683 0.00763 **
## wind 0.11445 0.16357 0.700 0.48459
## precip 18.16739 3.22973 5.625 3.75e‐08 ***
## quarter2 ‐2.26471 2.66038 ‐0.851 0.39519
## quarter3 ‐7.52596 3.22585 ‐2.333 0.02020 *
## quarter4 ‐4.75737 2.10380 ‐2.261 0.02434 *
## ‐‐‐
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 13.12 on 357 degrees of freedom
## Multiple R‐squared: 0.1218, Adjusted R‐squared: 0.107
## F‐statistic: 8.253 on 6 and 357 DF, p‐value: 2.221e‐08
summary(output3)
http://jakeruss.com/cheatsheets/stargazer.html 5/40
7/19/2016 A Stargazer Cheatsheet
##
## Call:
## ivreg(formula = delay ~ temp + wind + precip | . ‐ temp + hot,
## data = both)
##
## Residuals:
## Min 1Q Median 3Q Max
## ‐25.739 ‐8.929 ‐3.834 5.015 74.767
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 10.7297 9.1384 1.174 0.241
## temp 0.0342 0.1397 0.245 0.807
## wind 0.1157 0.2070 0.559 0.577
## precip 18.8775 3.2589 5.793 1.51e‐08 ***
## ‐‐‐
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 13.28 on 360 degrees of freedom
## Multiple R‐Squared: 0.09253, Adjusted R‐squared: 0.08496
## Wald test: 11.28 on 3 and 360 DF, p‐value: 4.326e‐07
Quick notes
Since I’m using knitr (http://cran.rstudio.com/web/packages/knitr/index.html) and R markdown (http://rmarkdown.rstudio.com/) 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
᠈Ānd 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 speci᠈Āc for LaTeX output and I can’t demonstrate it here.
HTML formatting
http://jakeruss.com/cheatsheets/stargazer.html 6/40
7/19/2016 A Stargazer Cheatsheet
It is possible to change the formatting of html tables generated with stargazer via an html style sheet. See the R Markdown
documentation (http://rmarkdown.rstudio.com/html_document_format.html#custom_css) about incorporating a custom CSS.
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.
# Use only a few rows
both2 <‐ both %>% slice(1:6)
stargazer(both2, type = "html", summary = FALSE, rownames = FALSE)
2,0131117.48438.48012.75901FALSE
2,0131225.32328.83512.51501FALSE
2,01313 8.450 29.457 7.864 01FALSE
2,0131412.10433.47713.85701FALSE
2,01315 5.696 36.73310.83701FALSE
2,0131612.38337.970 8.008 01FALSE
stargazer(both, type = "html", nobs = FALSE, mean.sd = TRUE, median = TRUE,
iqr = TRUE)
Statistic N Pctl(75)St. Dev.
http://jakeruss.com/cheatsheets/stargazer.html 8/40
7/19/2016 A Stargazer Cheatsheet
stargazer(both, type = "html", summary.logical = FALSE)
http://jakeruss.com/cheatsheets/stargazer.html 9/40
7/19/2016 A Stargazer Cheatsheet
Dependent variable:
delay
(1) (2)
temp 0.088 ** 0.184***
(0.041) (0.069)
wind 0.166 0.114
(0.164) (0.164)
precip 18.918 *** 18.167***
(3.249) (3.230)
quarter2 -2.265
(2.660)
quarter3 -7.526**
(3.226)
quarter4 -4.757**
(2.104)
Constant 7.263 ** 6.142*
(3.099) (3.536)
Observations 364 364
R2 0.097 0.122
Adjusted R2 0.089 0.107
Residual Std. Error 13.248 (df = 360) 13.119 (df = 357)
F Statistic 12.879 *** (df = 3; 360)8.253*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01
stargazer includes several pre-formatted styles that imitate popular academic journals. Use the style argument.
stargazer(output, output2, type = "html", style = "qje")
delay
(1) (2)
temp 0.088** 0.184***
(0.041) (0.069)
wind 0.166 0.114
(0.164) (0.164)
precip 18.918*** 18.167***
(3.249) (3.230)
quarter2 -2.265
(2.660)
quarter3 -7.526**
(3.226)
quarter4 -4.757**
(2.104)
Constant 7.263** 6.142*
(3.099) (3.536)
N 364 364
R2 0.097 0.122
Adjusted R2 0.089 0.107
Residual Std. Error 13.248 (df = 360) 13.119 (df = 357)
F Statistic 12.879 *** (df = 3; 360)8.253*** (df = 6; 357)
Notes: ***Signi᠈Ācant at the 1 percent level.
**Signi᠈Ācant at the 5 percent level.
*Signi᠈Ācant at the 10 percent level.
http://jakeruss.com/cheatsheets/stargazer.html 11/40
7/19/2016 A Stargazer Cheatsheet
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)")
A better caption
Flight delay (in minutes)
(1) (2)
Temperature 0.088 ** 0.184***
(0.041) (0.069)
Wind speed 0.166 0.114
(0.164) (0.164)
Rain (inches) 18.918*** 18.167***
(3.249) (3.230)
2nd quarter -2.265
(2.660)
3rd quarter -7.526**
(3.226)
Fourth quarter -4.757**
(2.104)
Constant 7.263** 6.142*
(3.099) (3.536)
Observations 364 364
R2 0.097 0.122
Adjusted R2 0.089 0.107
Residual Std. Error 13.248 (df = 360) 13.119 (df = 357)
F Statistic 12.879 *** (df = 3; 360)8.253*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01
http://jakeruss.com/cheatsheets/stargazer.html 12/40
7/19/2016 A Stargazer Cheatsheet
stargazer(output, output2, type = "html",
dep.var.labels.include = FALSE,
model.numbers = FALSE)
Dependent variable:
temp 0.088** 0.184***
(0.041) (0.069)
wind 0.166 0.114
(0.164) (0.164)
precip 18.918*** 18.167***
(3.249) (3.230)
quarter2 -2.265
(2.660)
quarter3 -7.526**
(3.226)
quarter4 -4.757**
(2.104)
Constant 7.263 ** 6.142*
(3.099) (3.536)
Observations 364 364
R2 0.097 0.122
Adjusted R 2 0.089 0.107
Residual Std. Error 13.248 (df = 360) 13.119 (df = 357)
F Statistic 12.879*** (df = 3; 360)8.253*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01
stargazer(output, output2, type = "html", column.labels = c("Good", "Better"))
Dependent variable:
delay
Good Better
(1) (2)
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.088** 0.088** 0.184*** 0.184***
(0.041) (0.041) (0.069) (0.069)
http://jakeruss.com/cheatsheets/stargazer.html 14/40
7/19/2016 A Stargazer Cheatsheet
Model names
When the results from di悠erent 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).
stargazer(output, output2, output3, type = "html")
Dependent variable:
delay
OLS instrumental
variable
(1) (2) (3)
temp 0.088** 0.184*** 0.034
(0.041) (0.069) (0.140)
wind 0.166 0.114 0.116
(0.164) (0.164) (0.207)
precip 18.918*** 18.167*** 18.877***
http://jakeruss.com/cheatsheets/stargazer.html 15/40
7/19/2016 A Stargazer Cheatsheet
stargazer(output, output2, output3, type = "html",
multicolumn = FALSE)
Dependent variable:
delay delay delay
OLS OLS instrumental
variable
(1) (2) (3)
temp 0.088** 0.184*** 0.034
(0.041) (0.069) (0.140)
wind 0.166 0.114 0.116
(0.164) (0.164) (0.207)
precip 18.918*** 18.167*** 18.877***
(3.249) (3.230) (3.259)
quarter2 -2.265
(2.660)
http://jakeruss.com/cheatsheets/stargazer.html ** 16/40
7/19/2016 A Stargazer Cheatsheet
quarter3 -7.526**
(3.226)
quarter4 -4.757**
(2.104)
Constant 7.263** 6.142* 10.730
(3.099) (3.536) (9.138)
Observations 364 364 364
R2 0.097 0.122 0.093
Adjusted R 2 0.089 0.107 0.085
Residual Std. Error 13.248 (df = 360) 13.119 (df = 357) 13.280 (df = 360)
F Statistic 12.879*** (df = 3; 360)8.253*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01
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.088** 0.184***
(0.041) (0.069)
wind 0.166 0.114
(0.164) (0.164)
precip 18.918*** 18.167***
(3.249) (3.230)
quarter2 -2.265
(2.660)
quarter3 -7.526**
(3.226)
quarter4 -4.757**
(2.104)
Constant 7.263** 6.142*
http://jakeruss.com/cheatsheets/stargazer.html 17/40
7/19/2016 A Stargazer Cheatsheet
(3.099) (3.536)
Fixed e悠ects? No No
Results believable? Maybe Try again later
Observations 364 364
R2 0.097 0.122
Adjusted R 2 0.089 0.107
Residual Std. Error 13.248 (df = 360) 13.119 (df = 357)
F Statistic 12.879*** (df = 3; 360)8.253*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01
Dependent variable:
delay
(1) (2)
output output2
temp 0.088** 0.184***
(0.041) (0.069)
wind 0.166 0.114
(0.164) (0.164)
precip 18.918*** 18.167***
(3.249) (3.230)
quarter2 -2.265
(2.660)
quarter3 -7.526**
(3.226)
quarter4 -4.757**
(2.104)
Constant 7.263** 6.142*
(3.099) (3.536)
Observations 364 364
R2 0.097 0.122
Adjusted R2 0.089 0.107
http://jakeruss.com/cheatsheets/stargazer.html 18/40
7/19/2016 A Stargazer Cheatsheet
stargazer(output, output2, type = "html",
report = "vct*")
Dependent variable:
delay
(1) (2)
temp 0.088 0.184
t = 2.165** t = 2.683***
wind 0.166 0.114
t = 1.016 t = 0.700
precip 18.918 18.167
t = 5.822*** t = 5.625***
quarter2 -2.265
t = -0.851
quarter3 -7.526
t = -2.333**
quarter4 -4.757
t = -2.261**
Constant 7.263 6.142
t = 2.344** t = 1.737*
Observations 364 364
R2 0.097 0.122
Adjusted R2 0.089 0.107
http://jakeruss.com/cheatsheets/stargazer.html 19/40
7/19/2016 A Stargazer Cheatsheet
Dependent variable:
delay
(1) (2)
temp 0.088** 0.184***
(0.008, 0.168) (0.050, 0.318)
wind 0.166 0.114
(-0.155, 0.488) (-0.206, 0.435)
precip 18.918*** 18.167***
(12.549, 25.287) (11.837, 24.498)
quarter2 -2.265
(-7.479, 2.950)
quarter3 -7.526**
(-13.849, -1.203)
quarter4 -4.757**
(-8.881, -0.634)
Constant 7.263** 6.142*
(1.189, 13.337) (-0.789, 13.072)
Observations 364 364
R2 0.097 0.122
Adjusted R2 0.089 0.107
Residual Std. Error 13.248 (df = 360) 13.119 (df = 357)
F Statistic 12.879 *** (df = 3; 360)8.253*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01
http://jakeruss.com/cheatsheets/stargazer.html 20/40
7/19/2016 A Stargazer Cheatsheet
stargazer(output, output2, type = "html",
ci = TRUE, ci.level = 0.90, ci.separator = " @@ ")
Dependent variable:
delay
(1) (2)
temp 0.088** 0.184***
(0.021 @@ 0.155) (0.071 @@ 0.297)
wind 0.166 0.114
(-0.103 @@ 0.436) (-0.155 @@ 0.384)
precip 18.918 *** 18.167***
(13.573 @@ 24.263) (12.855 @@ 23.480)
quarter2 -2.265
(-6.641 @@ 2.111)
quarter3 -7.526**
(-12.832 @@ -2.220)
quarter4 -4.757**
(-8.218 @@ -1.297)
Constant 7.263** 6.142*
(2.166 @@ 12.360) (0.325 @@ 11.958)
Observations 364 364
R2 0.097 0.122
Adjusted R2 0.089 0.107
Residual Std. Error 13.248 (df = 360) 13.119 (df = 357)
F Statistic 12.879 *** (df = 3; 360)8.253*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01
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.
http://jakeruss.com/cheatsheets/stargazer.html 21/40
7/19/2016 A Stargazer Cheatsheet
Similar options exist to supply adjusted values to the coe樇cients, t-statistics, con᠈Ādence intervals, and p-values. See coef , t , ci.custom ,
or p .
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.088 ** 0.088**
(0.041) (0.043)
wind 0.166 0.166
(0.164) (0.159)
precip 18.918 *** 18.918***
(3.249) (4.735)
Constant 7.263** 7.263**
(3.099) (3.053)
F Statistic (df = 3; 360) 12.879*** 7.73***
Observations 364 364
R2 0.097 0.097
Adjusted R2 0.089 0.089
Residual Std. Error (df = 360) 13.248 13.248
Note: p<0.1; p<0.05; p<0.01
stargazer(output, output2, type = "html",
intercept.bottom = FALSE)
Dependent variable:
delay
(1) (2)
Constant 7.263** 6.142*
(3.099) (3.536)
temp 0.088** 0.184***
(0.041) (0.069)
wind 0.166 0.114
(0.164) (0.164)
precip 18.918*** 18.167***
(3.249) (3.230)
quarter2 -2.265
(2.660)
quarter3 -7.526**
(3.226)
quarter4 -4.757**
(2.104)
Observations 364 364
R2 0.097 0.122
Adjusted R2 0.089 0.107
Residual Std. Error 13.248 (df = 360) 13.119 (df = 357)
F Statistic 12.879 *** (df = 3; 360)8.253*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01
stargazer(output, output2, type = "html",
single.row = TRUE)
Dependent variable:
http://jakeruss.com/cheatsheets/stargazer.html 23/40
7/19/2016 A Stargazer Cheatsheet
delay
(1) (2)
temp 0.088**
(0.041) 0.184***
(0.069)
wind 0.166 (0.164) 0.114 (0.164)
precip 18.918 *** (3.249) 18.167*** (3.230)
quarter2 -2.265 (2.660)
quarter3 -7.526** (3.226)
quarter4 -4.757** (2.104)
Constant 7.263** (3.099) 6.142* (3.536)
Observations 364 364
R2 0.097 0.122
Adjusted R2 0.089 0.107
Residual Std. Error 13.248 (df = 360) 13.119 (df = 357)
F Statistic 12.879 *** (df = 3; 360)8.253*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01
stargazer(output, output2, type = "html", omit = "quarter")
Dependent variable:
delay
(1) (2)
temp 0.088** 0.184***
(0.041) (0.069)
wind 0.166 0.114
(0.164) (0.164)
precip 18.918*** 18.167***
(3.249) (3.230)
Constant 7.263** 6.142*
(3.099) (3.536)
http://jakeruss.com/cheatsheets/stargazer.html 24/40
7/19/2016 A Stargazer Cheatsheet
stargazer(output, output2, type = "html",
omit = "quarter",
omit.labels = "Quarter dummies?")
Dependent variable:
delay
(1) (2)
temp 0.088** 0.184***
(0.041) (0.069)
wind 0.166 0.114
(0.164) (0.164)
precip 18.918*** 18.167***
(3.249) (3.230)
Constant 7.263** 6.142*
(3.099) (3.536)
Quarter dummies? No No
Observations 364 364
R2 0.097 0.122
Adjusted R2 0.089 0.107
Residual Std. Error 13.248 (df = 360) 13.119 (df = 357)
F Statistic 12.879 *** (df = 3; 360)8.253*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01
Dependent variable:
delay
(1) (2)
temp 0.088 ** 0.184***
(0.041) (0.069)
wind 0.166 0.114
(0.164) (0.164)
precip 18.918*** 18.167***
(3.249) (3.230)
quarter2 -2.265
(2.660)
quarter3 -7.526**
(3.226)
quarter4 -4.757**
(2.104)
Constant 7.263 ** 6.142*
(3.099) (3.536)
Observations 364 364
Adjusted R 2 0.089 0.107
Residual Std. Error13.248 (df = 360)13.119 (df = 357)
Note: p<0.1; p<0.05; p<0.01
http://jakeruss.com/cheatsheets/stargazer.html 26/40
7/19/2016 A Stargazer Cheatsheet
# Remove statistics and notes sections completely
stargazer(output, output2, type = "html",
omit.table.layout = "sn")
Dependent variable:
delay
(1) (2)
temp 0.088 ** 0.184***
(0.041) (0.069)
wind 0.166 0.114
(0.164) (0.164)
precip 18.918*** 18.167***
(3.249) (3.230)
quarter2 -2.265
(2.660)
quarter3 -7.526**
(3.226)
quarter4 -4.757**
(2.104)
Constant 7.263** 6.142*
(3.099) (3.536)
# Include everything except the statistics and notes sections
stargazer(output, output2, type = "html",
table.layout = "‐ld#‐t‐")
Dependent variable:
delay
(1) (2)
temp 0.088** 0.184***
(0.041) (0.069)
http://jakeruss.com/cheatsheets/stargazer.html 27/40
7/19/2016 A Stargazer Cheatsheet
Dependent variable:
delay
(1) (2)
temp 0.088** 0.184***
(0.041) (0.069)
wind 0.166 0.114
(0.164) (0.164)
precip 18.918*** 18.167***
(3.249) (3.230)
quarter2 -2.265
(2.660)
quarter3 -7.526**
(3.226)
quarter4 -4.757**
(2.104)
Constant 7.263** 6.142*
(3.099) (3.536)
Observations 364 364
2
http://jakeruss.com/cheatsheets/stargazer.html 28/40
7/19/2016 A Stargazer Cheatsheet
R2 0.097 0.122
Adjusted R2 0.089 0.107
Residual Std. Error 13.248 13.119
F Statistic 12.879 *** 8.253***
Note: p<0.1; p<0.05; p<0.01
stargazer(output, output2, type = "html",
star.char = c("@", "@@", "@@@"))
Dependent variable:
delay
(1) (2)
temp 0.088@@ 0.184@@@
(0.041) (0.069)
wind 0.166 0.114
(0.164) (0.164)
precip 18.918@@@ 18.167@@@
(3.249) (3.230)
quarter2 -2.265
(2.660)
quarter3 -7.526@@
(3.226)
quarter4 -4.757@@
(2.104)
Constant 7.263@@ 6.142@
(3.099) (3.536)
Observations 364 364
R2 0.097 0.122
Adjusted R2 0.089 0.107
http://jakeruss.com/cheatsheets/stargazer.html 29/40
7/19/2016 A Stargazer Cheatsheet
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.088 * 0.184**
(0.041) (0.069)
wind 0.166 0.114
(0.164) (0.164)
precip 18.918 *** 18.167***
(3.249) (3.230)
quarter2 -2.265
(2.660)
quarter3 -7.526*
(3.226)
quarter4 -4.757*
(2.104)
Constant 7.263 * 6.142
(3.099) (3.536)
Observations 364 364
R2 0.097 0.122
Adjusted R 2 0.089 0.107
Residual Std. Error 13.248 (df = 360) 13.119 (df = 357)
F Statistic 12.879*** (df = 3; 360)8.253*** (df = 6; 357)
Note: p<0.05; p<0.01; p<0.001
Dependent variable:
delay
(1) (2)
temp 0.088** 0.184***
(0.041) (0.069)
wind 0.166 0.114
(0.164) (0.164)
precip 18.918 *** 18.167***
(3.249) (3.230)
quarter2 -2.265
(2.660)
quarter3 -7.526**
(3.226)
quarter4 -4.757**
(2.104)
Constant 7.263 ** 6.142*
(3.099) (3.536)
Observations 364 364
R2 0.097 0.122
Adjusted R 2 0.089 0.107
Residual Std. Error 13.248 (df = 360) 13.119 (df = 357)
F Statistic 12.879*** (df = 3; 360)8.253*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01
I make this look good!
http://jakeruss.com/cheatsheets/stargazer.html 31/40
7/19/2016 A Stargazer Cheatsheet
stargazer(output, output2, type = "html",
notes = "Sometimes you just have to start over.",
notes.append = FALSE)
Dependent variable:
delay
(1) (2)
temp 0.088** 0.184***
(0.041) (0.069)
wind 0.166 0.114
(0.164) (0.164)
precip 18.918*** 18.167***
(3.249) (3.230)
quarter2 -2.265
(2.660)
quarter3 -7.526**
(3.226)
quarter4 -4.757**
(2.104)
Constant 7.263** 6.142*
(3.099) (3.536)
Observations 364 364
R2 0.097 0.122
Adjusted R 2 0.089 0.107
Residual Std. Error 13.248 (df = 360) 13.119 (df = 357)
F Statistic 12.879*** (df = 3; 360)8.253*** (df = 6; 357)
Note: Sometimes you just have to start over.
Dependent variable:
delay
(1) (2)
http://jakeruss.com/cheatsheets/stargazer.html ** *** 32/40
7/19/2016 A Stargazer Cheatsheet
Dependent variable:
delay
(1) (2)
temp 0.088** 0.184***
(0.041) (0.069)
wind 0.166 0.114
(0.164) (0.164)
precip 18.918*** 18.167***
(3.249) (3.230)
quarter2 -2.265
http://jakeruss.com/cheatsheets/stargazer.html 33/40
7/19/2016 A Stargazer Cheatsheet
(2.660)
quarter3 -7.526**
(3.226)
quarter4 -4.757**
(2.104)
Constant 7.263** 6.142*
(3.099) (3.536)
Observations 364 364
R2 0.097 0.122
Adjusted R 2 0.089 0.107
Residual Std. Error 13.248 (df = 360) 13.119 (df = 357)
F Statistic 12.879*** (df = 3; 360)8.253*** (df = 6; 357)
New note label p<0.1; p<0.05; p<0.01
Table aesthetics
Use html tags to modify table elements
# 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
A better caption
delay
(1) (2)
temp 0.088** 0.184***
(0.041) (0.069)
wind 0.166 0.114
(0.164) (0.164)
Dependent variable:
delay
(1) (2)
temp 0,088** 0,184***
(0,041) (0,069)
wind 0,166 0,114
(0,164) (0,164)
precip 18,918*** 18,167***
(3,249) (3,230)
quarter2 -2,265
(2,660)
quarter3 -7,526**
(3,226)
quarter4 -4,757**
http://jakeruss.com/cheatsheets/stargazer.html 35/40
7/19/2016 A Stargazer Cheatsheet
(2,104)
Constant 7,263** 6,142*
(3,099) (3,536)
Observations 364 364
R2 0,097 0,122
Adjusted R 2 0,089 0,107
Residual Std. Error 13,248 (df = 360) 13,119 (df = 357)
F Statistic 12,879*** (df = 3; 360)8,253*** (df = 6; 357)
Note: p<0,1; p<0,05; p<0,01
Dependent variable:
delay
(1) (2)
temp 0.1** 0.2***
(0.04) (0.1)
wind 0.2 0.1
(0.2) (0.2)
precip 18.9*** 18.2***
(3.2) (3.2)
quarter2 -2.3
(2.7)
quarter3 -7.5**
(3.2)
quarter4 -4.8**
(2.1)
Constant 7.3** 6.1*
(3.1) (3.5)
Observations 364 364
R2 0.1 0.1
Adjusted R2 0.1 0.1
Residual Std. Error 13.2 (df = 360) 13.1 (df = 357)
***
http://jakeruss.com/cheatsheets/stargazer.html *** 36/40
7/19/2016 A Stargazer Cheatsheet
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.
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.2 0.1
(0.2) (0.2)
precip 18.9*** 18.2***
(3.2) (3.2)
quarter2 -2.3
(2.7)
quarter3 -7.5**
(3.2)
quarter4 -4.8**
(2.1)
Constant 7.3** 6.1*
(3.1) (3.5)
Observations 364 364
R2 0.1 0.1
Adjusted R 2 0.1 0.1
Residual Std. Error 13.2 (df = 360) 13.1 (df = 357)
F Statistic 12.9*** (df = 3; 360)8.3*** (df = 6; 357)
http://jakeruss.com/cheatsheets/stargazer.html 37/40
7/19/2016 A Stargazer Cheatsheet
Dependent variable:
delay
(1) (2)
temp .088** .184***
(.041) (.069)
wind .166 .114
(.164) (.164)
precip 18.918*** 18.167***
(3.249) (3.230)
quarter2 -2.265
(2.660)
quarter3 -7.526**
(3.226)
quarter4 -4.757**
(2.104)
Constant 7.263** 6.142*
(3.099) (3.536)
Observations 364 364
R2 .097 .122
Adjusted R2 .089 .107
Residual Std. Error 13.248 (df = 360) 13.119 (df = 357)
F Statistic 12.879 *** (df = 3; 360)8.253*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01
http://jakeruss.com/cheatsheets/stargazer.html 38/40
7/19/2016 A Stargazer Cheatsheet
stargazer(output, output2, type = "html",
order = c(4, 5, 6, 3, 2, 1))
Dependent variable:
delay
(1) (2)
quarter2 -2.265
(2.660)
quarter3 -7.526**
(3.226)
quarter4 -4.757**
(2.104)
precip 18.918*** 18.167***
(3.249) (3.230)
wind 0.166 0.114
(0.164) (0.164)
temp 0.088** 0.184***
(0.041) (0.069)
Constant 7.263** 6.142*
(3.099) (3.536)
Observations 364 364
R2 0.097 0.122
Adjusted R2 0.089 0.107
Residual Std. Error 13.248 (df = 360) 13.119 (df = 357)
F Statistic 12.879 *** (df = 3; 360)8.253*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01
# Regex for keep "precip" but not "precipitation"
stargazer(output, output2, type = "html",
keep = c("\\bprecip\\b"))
Dependent variable:
http://jakeruss.com/cheatsheets/stargazer.html 39/40
7/19/2016 A Stargazer Cheatsheet
delay
(1) (2)
precip 18.918*** 18.167***
(3.249) (3.230)
Observations 364 364
R2 0.097 0.122
Adjusted R2 0.089 0.107
Residual Std. Error 13.248 (df = 360) 13.119 (df = 357)
F Statistic 12.879 *** (df = 3; 360)8.253*** (df = 6; 357)
Note: p<0.1; p<0.05; p<0.01
Feedback
The .Rmd ᠈Āle for this cheatsheet is on GitHub (https://github.com/JakeRuss/cheatsheets) and I welcome suggestions or pull requests.
http://jakeruss.com/cheatsheets/stargazer.html 40/40