stargazer2 is a
drop-in replacement for the stargazer package with native
support for modern econometrics packages. For lm objects
the output is designed to be identical to the original, with one key
addition: the standard error type is always identified in the table
note.
The primary output format is "latex" for embedding in
papers. "text" provides a quick terminal preview without
needing to compile anything.
We use the wage1 dataset from the
wooldridge package throughout this vignette. Three
categorical variables are constructed from existing binary
indicators.
library(wooldridge)
data(wage1)
wage1$region <- factor(
ifelse(wage1$northcen == 1, "northcen",
ifelse(wage1$south == 1, "south",
ifelse(wage1$west == 1, "west", "northeast"))),
levels = c("northeast", "northcen", "south", "west")
)
wage1$occupation <- factor(
ifelse(wage1$profocc == 1, "professional",
ifelse(wage1$clerocc == 1, "clerical",
ifelse(wage1$servocc == 1, "service", "other"))),
levels = c("other", "professional", "clerical", "service")
)
wage1$industry <- factor(
ifelse(wage1$construc == 1, "construction",
ifelse(wage1$ndurman == 1, "nondurable_manuf",
ifelse(wage1$trcommpu == 1, "transport",
ifelse(wage1$trade == 1, "trade",
ifelse(wage1$services == 1, "services",
ifelse(wage1$profserv == 1, "prof_services", "other")))))),
levels = c("other", "construction", "nondurable_manuf",
"transport", "trade", "services", "prof_services")
)Four progressively richer log-wage specifications:
m1 <- lm(lwage ~ educ + exper + tenure, wage1)
m2 <- lm(lwage ~ educ + exper + tenure + female + married, wage1)
m3 <- lm(lwage ~ educ + exper + tenure + female + married +
region + occupation, wage1)
m4 <- lm(lwage ~ educ + exper + tenure + female + married +
region + occupation + industry, wage1)A single call produces a publication-ready table. Models 3 and 4
include factor variables; omit suppresses their level
dummies so the table stays focused on the economic variables of
interest.
stargazer(m1, m2, m3, m4,
type = "text",
title = "Determinants of Log Wages",
dep.var.labels = "log(Wage)",
covariate.labels = c("Education", "Experience", "Tenure",
"Female", "Married"),
omit = c("region", "occupation", "industry"),
column.labels = c("Baseline", "Demographics",
"Region/Occ.", "Full"),
notes.append = FALSE,
notes = "Controls for region, occupation, and industry in (3) and (4).")
Determinants of Log Wages
=====================================================================================================================
Dependent variable:
-------------------------------------------------------------------------------------------------
log(Wage)
Baseline Demographics Region/Occ. Full
(1) (2) (3) (4)
---------------------------------------------------------------------------------------------------------------------
Education 0.092*** 0.084*** 0.060*** 0.057***
(0.007) (0.007) (0.008) (0.008)
Experience 0.004** 0.003* 0.002 0.002
(0.002) (0.002) (0.002) (0.002)
Tenure 0.022*** 0.017*** 0.016*** 0.014***
(0.003) (0.003) (0.003) (0.003)
Female -0.286*** -0.263*** -0.264***
(0.037) (0.039) (0.038)
Married 0.126*** 0.120*** 0.094**
(0.040) (0.039) (0.037)
Constant 0.284*** 0.490*** 0.777*** 0.994***
(0.104) (0.101) (0.110) (0.112)
---------------------------------------------------------------------------------------------------------------------
Observations 526 526 526 526
R2 0.316 0.404 0.460 0.510
Adjusted R2 0.312 0.398 0.449 0.494
Residual Std. Error 0.441 (df = 522) 0.412 (df = 520) 0.395 (df = 514) 0.378 (df = 508)
F Statistic 80.391*** (df = 3; 522) 70.383*** (df = 5; 520) 39.877*** (df = 11; 514) 31.091*** (df = 17; 508)
=====================================================================================================================
Note: Controls for region, occupation, and industry in (3) and (4). The LaTeX source is what goes directly into your .tex
file or via \input{}. Write to a file with
out = "table.tex".
stargazer(m1, m2,
type = "latex",
title = "Determinants of Log Wages",
label = "tab:wage-ols",
dep.var.labels = "log(Wage)",
covariate.labels = c("Education", "Experience", "Tenure"))
% Table produced by stargazer2 v.0.1.0 by Tom Zylkin, University of Richmond (tzylkin@richmond.edu)
% Original stargazer package by: Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
% R package version 5.2.3. https://CRAN.R-project.org/package=stargazer
\begin{table}[!htbp] \centering
\caption{Determinants of Log Wages}
\label{tab:wage-ols}
\begin{tabular}{@{\extracolsep{5pt}}lcc}
\hline
& \multicolumn{2}{c}{\textit{Dependent variable:}} \\
& \multicolumn{2}{c}{log(Wage)} \\
& (1) & (2)\\
\hline
Education & 0.092$^{***}$ & 0.084$^{***}$ \\
& (0.007) & (0.007) \\
Experience & 0.004$^{**}$ & 0.003$^{*}$ \\
& (0.002) & (0.002) \\
Tenure & 0.022$^{***}$ & 0.017$^{***}$ \\
& (0.003) & (0.003) \\
female & & $-$0.286$^{***}$ \\
& & (0.037) \\
married & & 0.126$^{***}$ \\
& & (0.040) \\
Constant & 0.284$^{***}$ & 0.490$^{***}$ \\
& (0.104) & (0.101) \\
\hline
Observations & 526 & 526 \\
R$^{2}$ & 0.316 & 0.404 \\
Adjusted R$^{2}$ & 0.312 & 0.398 \\
Residual Std. Error & 0.441 (df = 522) & 0.412 (df = 520) \\
F Statistic & 80.391$^{***}$ (df = 3; 522) & 70.383$^{***}$ (df = 5; 520) \\
\hline
\hline
\multicolumn{3}{p{\linewidth}}{\textit{Note:} OLS standard errors; $^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01.} \\
\end{tabular}
\end{table} For use in R Markdown documents where a rendered table is more readable than LaTeX source:
stargazer(m1, m2,
type = "html",
dep.var.labels = "log(Wage)",
covariate.labels = c("Education", "Experience", "Tenure"))| Dependent variable: | ||
|---|---|---|
| log(Wage) | ||
| (1) | (2) | |
| Education | 0.092*** | 0.084*** |
| (0.007) | (0.007) | |
| Experience | 0.004** | 0.003* |
| (0.002) | (0.002) | |
| Tenure | 0.022*** | 0.017*** |
| (0.003) | (0.003) | |
| female | −0.286*** | |
| (0.037) | ||
| married | 0.126*** | |
| (0.040) | ||
| Constant | 0.284*** | 0.490*** |
| (0.104) | (0.101) | |
| Observations | 526 | 526 |
| R2 | 0.316 | 0.404 |
| Adjusted R2 | 0.312 | 0.398 |
| Residual Std. Error | 0.441 (df = 522) | 0.412 (df = 520) |
| F Statistic | 80.391*** (df = 3; 522) | 70.383*** (df = 5; 520) |
| Note: | OLS standard errors; p<0.1; p<0.05; p<0.01 | |
vcovThe vcov argument accepts a list of variance-covariance
matrices — one per model. stargazer2 extracts the square
root of the diagonal internally and updates the table note to name the
SE type used in each column. This works with any function returning a
matrix: sandwich::vcovHC, sandwich::vcovCL, or
your own estimator.
library(sandwich)
stargazer(m1, m2, m3, m4,
type = "text",
dep.var.labels = "log(Wage)",
covariate.labels = c("Education", "Experience", "Tenure",
"Female", "Married"),
omit = c("region", "occupation", "industry"),
vcov = list(vcovHC(m1, type = "HC1"),
vcovHC(m2, type = "HC1"),
vcovHC(m3, type = "HC1"),
vcovHC(m4, type = "HC1")))
=====================================================================================================================
Dependent variable:
-------------------------------------------------------------------------------------------------
log(Wage)
(1) (2) (3) (4)
---------------------------------------------------------------------------------------------------------------------
Education 0.092*** 0.084*** 0.060*** 0.057***
(0.008) (0.008) (0.009) (0.009)
Experience 0.004** 0.003* 0.002 0.002
(0.002) (0.002) (0.002) (0.001)
Tenure 0.022*** 0.017*** 0.016*** 0.014***
(0.004) (0.004) (0.003) (0.003)
Female -0.286*** -0.263*** -0.264***
(0.038) (0.040) (0.038)
Married 0.126*** 0.120*** 0.094**
(0.040) (0.039) (0.039)
Constant 0.284** 0.490*** 0.777*** 0.994***
(0.112) (0.114) (0.119) (0.124)
---------------------------------------------------------------------------------------------------------------------
Observations 526 526 526 526
R2 0.316 0.404 0.460 0.510
Adjusted R2 0.312 0.398 0.449 0.494
Residual Std. Error 0.441 (df = 522) 0.412 (df = 520) 0.395 (df = 514) 0.378 (df = 508)
F Statistic 80.391*** (df = 3; 522) 70.383*** (df = 5; 520) 39.877*** (df = 11; 514) 31.091*** (df = 17; 508)
=====================================================================================================================
Note: HC1 heteroskedasticity-robust standard errors; *p<0.1; **p<0.05; ***p<0.01 stargazer(m1, m2, m3, m4,
type = "text",
dep.var.labels = "log(Wage)",
covariate.labels = c("Education", "Experience", "Tenure",
"Female", "Married"),
omit = c("region", "occupation", "industry"),
vcov = list(vcovCL(m1, cluster = ~industry, data = wage1),
vcovCL(m2, cluster = ~industry, data = wage1),
vcovCL(m3, cluster = ~industry, data = wage1),
vcovCL(m4, cluster = ~industry, data = wage1)))
=====================================================================================================================
Dependent variable:
-------------------------------------------------------------------------------------------------
log(Wage)
(1) (2) (3) (4)
---------------------------------------------------------------------------------------------------------------------
Education 0.092*** 0.084*** 0.060*** 0.057***
(0.009) (0.010) (0.008) (0.009)
Experience 0.004*** 0.003*** 0.002** 0.002***
(0.001) (0.001) (0.001) (0.001)
Tenure 0.022*** 0.017*** 0.016*** 0.014***
(0.003) (0.002) (0.002) (0.002)
Female -0.286*** -0.263*** -0.264***
(0.049) (0.054) (0.052)
Married 0.126*** 0.120*** 0.094**
(0.043) (0.043) (0.041)
Constant 0.284*** 0.490*** 0.777*** 0.994***
(0.095) (0.101) (0.092) (0.132)
---------------------------------------------------------------------------------------------------------------------
Observations 526 526 526 526
R2 0.316 0.404 0.460 0.510
Adjusted R2 0.312 0.398 0.449 0.494
Residual Std. Error 0.441 (df = 522) 0.412 (df = 520) 0.395 (df = 514) 0.378 (df = 508)
F Statistic 80.391*** (df = 3; 522) 70.383*** (df = 5; 520) 39.877*** (df = 11; 514) 31.091*** (df = 17; 508)
=====================================================================================================================
Note: standard errors clustered by industry; *p<0.1; **p<0.05; ***p<0.01 vcov entries need not be the same type across columns.
When SE types differ, the note reports them by column group. Here column
(1) uses HC1-robust SEs while columns (2)–(4) use industry-clustered
SEs.
stargazer(m1, m2, m3, m4,
type = "latex",
dep.var.labels = "log(Wage)",
covariate.labels = c("Education", "Experience", "Tenure",
"Female", "Married"),
omit = c("region", "occupation", "industry"),
column.labels = c("Baseline", "Demographics",
"Region/Occ.", "Full"),
vcov = list(vcovHC(m1, type = "HC1"),
vcovCL(m2, cluster = ~industry, data = wage1),
vcovCL(m3, cluster = ~industry, data = wage1),
vcovCL(m4, cluster = ~industry, data = wage1)))
% Table produced by stargazer2 v.0.1.0 by Tom Zylkin, University of Richmond (tzylkin@richmond.edu)
% Original stargazer package by: Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
% R package version 5.2.3. https://CRAN.R-project.org/package=stargazer
\begin{table}[!htbp] \centering
\caption{}
\label{}
\begin{tabular}{@{\extracolsep{5pt}}lcccc}
\hline
& \multicolumn{4}{c}{\textit{Dependent variable:}} \\
& \multicolumn{4}{c}{log(Wage)} \\
& Baseline & Demographics & Region/Occ. & Full \\
& (1) & (2) & (3) & (4)\\
\hline
Education & 0.092$^{***}$ & 0.084$^{***}$ & 0.060$^{***}$ & 0.057$^{***}$ \\
& (0.008) & (0.010) & (0.008) & (0.009) \\
Experience & 0.004$^{**}$ & 0.003$^{***}$ & 0.002$^{**}$ & 0.002$^{***}$ \\
& (0.002) & (0.001) & (0.001) & (0.001) \\
Tenure & 0.022$^{***}$ & 0.017$^{***}$ & 0.016$^{***}$ & 0.014$^{***}$ \\
& (0.004) & (0.002) & (0.002) & (0.002) \\
Female & & $-$0.286$^{***}$ & $-$0.263$^{***}$ & $-$0.264$^{***}$ \\
& & (0.049) & (0.054) & (0.052) \\
Married & & 0.126$^{***}$ & 0.120$^{***}$ & 0.094$^{**}$ \\
& & (0.043) & (0.043) & (0.041) \\
Constant & 0.284$^{**}$ & 0.490$^{***}$ & 0.777$^{***}$ & 0.994$^{***}$ \\
& (0.112) & (0.101) & (0.092) & (0.132) \\
\hline
Observations & 526 & 526 & 526 & 526 \\
R$^{2}$ & 0.316 & 0.404 & 0.460 & 0.510 \\
Adjusted R$^{2}$ & 0.312 & 0.398 & 0.449 & 0.494 \\
Residual Std. Error & 0.441 (df = 522) & 0.412 (df = 520) & 0.395 (df = 514) & 0.378 (df = 508) \\
F Statistic & 80.391$^{***}$ (df = 3; 522) & 70.383$^{***}$ (df = 5; 520) & 39.877$^{***}$ (df = 11; 514) & 31.091$^{***}$ (df = 17; 508) \\
\hline
\hline
\multicolumn{5}{p{\linewidth}}{\textit{Note:} (1) HC1 heteroskedasticity-robust standard errors; (2)-(4) standard errors clustered by industry; $^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01.} \\
\end{tabular}
\end{table} The most commonly used formatting arguments:
| Argument | Purpose |
|---|---|
dep.var.labels |
Override dependent variable name(s) |
covariate.labels |
Rename coefficient rows (in display order) |
column.labels |
Column headers beneath the dep-var line |
omit / keep |
Regex patterns to drop or retain coefficient rows |
digits |
Decimal places for all numbers |
star.cutoffs |
P-value thresholds for significance stars |
notes / notes.append |
Add or replace the automatic table note |
title / label |
Caption and \label{} for LaTeX |
The style argument selects a layout preset.
| Style | Layout | Significance note |
|---|---|---|
"stargazer2" |
Single \hline, full-width left-aligned note |
p-value thresholds (default) |
"stargazer" |
Matches original package exactly (double rules,
\\[-1.8ex]) |
p-value thresholds |
"aer" |
American Economic Review — clean, no dep-var caption | Text descriptions (“Significant at the X percent level”) |
"qje" |
Quarterly Journal of Economics — like AER; observations labelled \(N\) | Text descriptions |
stargazer(m1, m2,
type = "latex",
dep.var.labels = "log(Wage)",
covariate.labels = c("Education", "Experience", "Tenure"),
style = "stargazer2") # default
% Table produced by stargazer2 v.0.1.0 by Tom Zylkin, University of Richmond (tzylkin@richmond.edu)
% Original stargazer package by: Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
% R package version 5.2.3. https://CRAN.R-project.org/package=stargazer
\begin{table}[!htbp] \centering
\caption{}
\label{}
\begin{tabular}{@{\extracolsep{5pt}}lcc}
\hline
& \multicolumn{2}{c}{\textit{Dependent variable:}} \\
& \multicolumn{2}{c}{log(Wage)} \\
& (1) & (2)\\
\hline
Education & 0.092$^{***}$ & 0.084$^{***}$ \\
& (0.007) & (0.007) \\
Experience & 0.004$^{**}$ & 0.003$^{*}$ \\
& (0.002) & (0.002) \\
Tenure & 0.022$^{***}$ & 0.017$^{***}$ \\
& (0.003) & (0.003) \\
female & & $-$0.286$^{***}$ \\
& & (0.037) \\
married & & 0.126$^{***}$ \\
& & (0.040) \\
Constant & 0.284$^{***}$ & 0.490$^{***}$ \\
& (0.104) & (0.101) \\
\hline
Observations & 526 & 526 \\
R$^{2}$ & 0.316 & 0.404 \\
Adjusted R$^{2}$ & 0.312 & 0.398 \\
Residual Std. Error & 0.441 (df = 522) & 0.412 (df = 520) \\
F Statistic & 80.391$^{***}$ (df = 3; 522) & 70.383$^{***}$ (df = 5; 520) \\
\hline
\hline
\multicolumn{3}{p{\linewidth}}{\textit{Note:} OLS standard errors; $^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01.} \\
\end{tabular}
\end{table} stargazer(m1, m2,
type = "latex",
dep.var.labels = "log(Wage)",
covariate.labels = c("Education", "Experience", "Tenure"),
style = "aer")
% Table produced by stargazer2 v.0.1.0 by Tom Zylkin, University of Richmond (tzylkin@richmond.edu)
% Original stargazer package by: Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
% R package version 5.2.3. https://CRAN.R-project.org/package=stargazer
\begin{table}[!htbp] \centering
\caption{}
\label{}
\begin{tabular}{@{\extracolsep{5pt}}lcc}
\hline
& \multicolumn{2}{c}{log(Wage)} \\
& (1) & (2)\\
\hline
Education & 0.092$^{***}$ & 0.084$^{***}$ \\
& (0.007) & (0.007) \\
Experience & 0.004$^{**}$ & 0.003$^{*}$ \\
& (0.002) & (0.002) \\
Tenure & 0.022$^{***}$ & 0.017$^{***}$ \\
& (0.003) & (0.003) \\
female & & $-$0.286$^{***}$ \\
& & (0.037) \\
married & & 0.126$^{***}$ \\
& & (0.040) \\
Constant & 0.284$^{***}$ & 0.490$^{***}$ \\
& (0.104) & (0.101) \\
\hline
Observations & 526 & 526 \\
R$^{2}$ & 0.316 & 0.404 \\
Adjusted R$^{2}$ & 0.312 & 0.398 \\
Residual Std. Error & 0.441 (df = 522) & 0.412 (df = 520) \\
F Statistic & 80.391$^{***}$ (df = 3; 522) & 70.383$^{***}$ (df = 5; 520) \\
\hline
\multicolumn{3}{p{\linewidth}}{\textit{Notes:} OLS standard errors; $^{***}$Significant at the 1 percent level. $^{**}$Significant at the 5 percent level. $^{*}$Significant at the 10 percent level.} \\
\end{tabular}
\end{table} Passing a data frame instead of model objects produces a summary statistics table.
stargazer(
wage1[, c("lwage", "educ", "exper", "tenure", "female", "married")],
type = "text",
covariate.labels = c("log(Wage)", "Education", "Experience",
"Tenure", "Female", "Married")
)
===========================================
Statistic N Mean St. Dev. Min Max
-------------------------------------------
log(Wage) 526 1.623 0.532 -0.635 3.218
Education 526 12.563 2.769 0 18
Experience 526 17.017 13.572 1 51
Tenure 526 5.105 7.224 0 44
Female 526 0.479 0.500 0 1
Married 526 0.608 0.489 0 1
-------------------------------------------