Package {stargazer2}


Type: Package
Title: Beautiful Regression Tables for Modern Econometrics Packages
Version: 0.1.0
Date: 2026-06-30
Description: Produces publication-quality LaTeX, ASCII, and HTML regression tables. Designed as a drop-in replacement for the 'stargazer' package for 'lm' and 'glm' models, with added native support for 'fixest', 'plm', and 'alpaca' objects including automatic fixed-effect and random-effect indicator rows and SE-type detection. Standard errors can be supplied as variance-covariance matrices, numeric vectors, or auto-extracted from supported model objects. Follows the interface of Hlavac (2022) https://CRAN.R-project.org/package=stargazer.
License: GPL-3
Encoding: UTF-8
Imports: stats
Suggests: fixest (≥ 0.11.0), alpaca, plm, sandwich, wooldridge, stargazer, knitr, rmarkdown, testthat (≥ 3.0.0)
VignetteBuilder: knitr
Config/testthat/edition: 3
Config/roxygen2/version: 8.0.0
NeedsCompilation: no
Packaged: 2026-07-09 12:50:53 UTC; tzylkin
Author: Tom Zylkin [aut, cre]
Maintainer: Tom Zylkin <tzylkin@richmond.edu>
Repository: CRAN
Date/Publication: 2026-07-17 14:20:02 UTC

Cluster-robust variance-covariance matrix for alpaca feglm

Description

Wraps summary(mod, type = "clustered", cluster = cluster) and returns a diagonal variance-covariance matrix that stargazer recognises and labels with the appropriate "clustered by ..." description.

Usage

alpaca_vcovCL(mod, cluster)

Arguments

mod

A fitted feglm object from the alpaca package.

cluster

A one-sided formula identifying the clustering variable(s). Use ~X for one-way, ~X + Y for two-way additive, or ~X^Y for two-way interaction clustering.

Value

A square diagonal matrix of class "vcovAlpacaCL" with a "cluster" attribute containing the cluster formula.

Examples


if (requireNamespace("alpaca", quietly = TRUE)) {
  d <- data.frame(
    y   = rbinom(200, 1, 0.5),
    x1  = rnorm(200),
    grp = factor(rep(1:10, 20))
  )
  mod <- alpaca::feglm(y ~ x1 | grp, d, binomial("logit"))
  V   <- alpaca_vcovCL(mod, cluster = ~grp)
  stargazer(mod, vcov = list(V), type = "text")
}


Heteroskedasticity-robust variance-covariance matrix for alpaca feglm

Description

Wraps summary(mod, type = "sandwich") and returns a diagonal variance-covariance matrix that stargazer recognises and labels as "heteroskedasticity-robust standard errors".

Usage

alpaca_vcovSandwich(mod)

Arguments

mod

A fitted feglm object from the alpaca package.

Value

A square diagonal matrix of class "vcovAlpacaSandwich" with squared sandwich standard errors on the diagonal.

Examples


if (requireNamespace("alpaca", quietly = TRUE)) {
  d <- data.frame(
    y   = rbinom(200, 1, 0.5),
    x1  = rnorm(200),
    grp = factor(rep(1:10, 20))
  )
  mod <- alpaca::feglm(y ~ x1 | grp, d, binomial("logit"))
  V   <- alpaca_vcovSandwich(mod)
  stargazer(mod, vcov = list(V), type = "text")
}


Extract a standardised model record from a regression object

Description

Internal S3 generic consumed by format_table. Not intended for direct use.

Usage

extract_model(model, vcov_override = NULL, se_override = NULL, ...)

Arguments

model

A fitted model object.

vcov_override

A pre-computed variance-covariance matrix, or NULL to auto-extract.

se_override

A named numeric vector of standard errors, or NULL to auto-extract.

...

Currently unused.

Value

A named list (model record) with the following fields:

coef_names

Character vector of coefficient display names.

coefs

Numeric vector of coefficient estimates.

se

Numeric vector of standard errors.

tstat

Numeric vector of t- or z-statistics.

pval

Numeric vector of two-sided p-values.

nobs

Integer; number of observations.

fit

Named list of fit statistics (R-squared, F-statistic, log-likelihood, etc.; content varies by model type).

fixed_effects

Character vector of fixed-effect variable names; character(0) if none.

reports_fe

Logical; TRUE for models that absorb fixed effects.

se_label

Character; human-readable description of the SE type for use in the table note.

model_label

Character; estimator name for the column header (e.g. "OLS", "Logit", "FE").

dep_var

Character; dependent variable name extracted from the model formula.


Assemble table data from a list of model records

Description

Internal; called by stargazer.

Usage

format_table(
  records,
  covariate.labels = NULL,
  coef.rename = NULL,
  omit = NULL,
  keep = NULL,
  omit.stat = NULL,
  digits = 3L,
  star.cutoffs = c(0.1, 0.05, 0.01),
  star.char = c("*", "**", "***"),
  no.space = FALSE,
  obs.label = "Observations"
)

Arguments

records

List of model_record objects from extract_model.

covariate.labels

Character vector of display names for covariates, applied positionally after omit/keep filtering.

coef.rename

Named character vector mapping raw coefficient names to display names before the union is computed (e.g. c("year::2004" = "t = -2")). Applied to all models.

omit

Character vector of regex patterns; matching covariates are dropped.

keep

Character vector of regex patterns; only matching covariates are kept (applied after omit).

omit.stat

Character vector of stat identifiers to suppress.

digits

Integer; decimal places for coefficients and SEs.

star.cutoffs

Numeric vector of p-value thresholds (ascending).

star.char

Character vector of star strings.

no.space

Logical; suppress blank spacer rows.

obs.label

Character; label for the Observations row. Default "Observations"; set to "\\textit\{N\}" for QJE style.


Render a table_data object as a plain-text string

Description

Internal; called by stargazer when type = "text".

Usage

render_ascii(
  table_data,
  title = "",
  dep.var.caption = "Dependent variable:",
  column.labels = NULL,
  notes = NULL,
  notes.append = TRUE
)

Arguments

table_data

List returned by format_table.

title

Table title string.

dep.var.caption

Caption above the dependent-variable line.

column.labels

Optional character vector of column labels.

notes

Additional note strings.

notes.append

Logical; if FALSE, replace the default note.


Render a table_data object as an HTML string

Description

Internal; called by stargazer.

Usage

render_html(
  table_data,
  title = "",
  dep.var.caption = "Dependent variable:",
  column.labels = NULL,
  notes = NULL,
  notes.append = TRUE,
  notes.label = "Note:"
)

Arguments

table_data

List returned by format_table.

title

Table caption string.

dep.var.caption

Caption above the dependent-variable line.

column.labels

Optional character vector of column labels (overrides model_labels in the header).

notes

Additional note strings appended after the SE note.

notes.append

Logical; if FALSE, replace the default note.

notes.label

Label preceding the note text.


Render a table_data object as a LaTeX string

Description

Internal; called by stargazer.

Usage

render_latex(
  table_data,
  title = "",
  label = "",
  dep.var.caption = "\\textit{Dependent variable:}",
  column.labels = NULL,
  font.size = NULL,
  notes = NULL,
  notes.append = TRUE,
  notes.align = "l",
  notes.label = "\\textit{Note:} ",
  style = "stargazer2"
)

Arguments

table_data

List returned by format_table.

title

Table caption string.

label

LaTeX label string (\label{...}).

dep.var.caption

Caption above the dependent-variable line (empty string suppresses the row entirely).

column.labels

Optional character vector of column labels.

font.size

LaTeX font-size command (e.g. "small").

notes

Additional note strings appended after the SE note.

notes.append

Logical; if FALSE, replace the default note.

notes.align

Alignment of the notes cell.

notes.label

Label preceding the note text.

style

One of "stargazer2", "stargazer", "aer", "qje".


Produce Publication-Quality Regression Tables

Description

Produces publication-quality regression tables, following the interface of the stargazer package, with native support for modern econometrics packages including fixest and alpaca. Outputs LaTeX, plain-text (ASCII), and HTML tables.

Usage

stargazer(
  ...,
  type = "latex",
  title = "",
  label = "",
  dep.var.labels = NULL,
  dep.var.caption = NULL,
  column.labels = NULL,
  column.separate = NULL,
  covariate.labels = NULL,
  coef.rename = NULL,
  omit = NULL,
  keep = NULL,
  omit.stat = NULL,
  digits = 3L,
  star.cutoffs = c(0.1, 0.05, 0.01),
  star.char = c("*", "**", "***"),
  notes = NULL,
  notes.append = TRUE,
  notes.align = NULL,
  notes.label = NULL,
  font.size = NULL,
  no.space = FALSE,
  style = "stargazer2",
  obs.label = NULL,
  summary.stat = NULL,
  median = FALSE,
  vcov = NULL,
  se = NULL,
  se_label = NULL,
  out = NULL
)

Arguments

...

One or more fitted model objects. Supported classes: lm, glm, plm, fixest (feols, fepois, fenegbin, feglm), alpaca::feglm, and summary.feglm.

type

Character; output format. One of "latex" (default), "text", or "html".

title

Character; table caption.

label

Character; LaTeX cross-reference label (used with type = "latex" only).

dep.var.labels

Character vector; custom labels for the dependent variable(s). Applied in column order.

dep.var.caption

Character; caption text above the dep-var row. Default: "\textit\{Dependent variable:\}" for LaTeX.

column.labels

Character vector; custom column header labels. Overrides the auto-detected model-type labels.

column.separate

Integer vector; controls how many consecutive columns share each column.labels entry. Unused in the current version.

covariate.labels

Character vector; display names for covariates, applied positionally after omit/keep filtering.

coef.rename

Named character vector mapping raw coefficient names to new display names before the column union is computed. Names are the existing coefficient names; values are the replacement names. Useful for aligning TWFE event-study year indicators with relative-time labels from other estimators, e.g. c("year::2004" = "t = -2", "year::2005" = "t = -1").

omit

Character vector; regex patterns — covariates whose names match any pattern are excluded from the table.

keep

Character vector; regex patterns — only covariates whose names match are included (applied after omit).

omit.stat

Character vector; stat identifiers to suppress. Recognised values: "n", "r2", "adj.r2", "sigma", "f", "pr2", "ll".

digits

Integer; number of decimal places for coefficients, SEs, and most fit statistics. Default: 3.

star.cutoffs

Numeric vector of length 3; p-value thresholds for one, two, and three stars. Default: c(0.1, 0.05, 0.01).

star.char

Character vector of length 3; star symbols. Default: c("*", "**", "***").

notes

Character vector; additional table notes appended after the SE-type note.

notes.append

Logical; if FALSE, the default SE-type and significance notes are replaced by notes. Default: TRUE.

notes.align

Character; cell alignment for the note row in LaTeX ("l", "c", or "r"). NULL (default) defers to the style preset: "l" for "stargazer2" and "aer", "r" for "stargazer" and "qje".

notes.label

Character; text preceding the note. Default: "\textit\{Note:\} ".

font.size

Character; LaTeX font-size command (e.g. "small", "footnotesize"). NULL (default) means no size command is inserted.

no.space

Logical; suppress blank spacer rows in the table body. Only affects style = "stargazer". Default: FALSE.

style

Character; table formatting style. Controls overall layout, rule style, notes format, and significance-note wording.

"stargazer2"

(Default) Clean layout: single \hline throughout, no \cline, full-width left-aligned notes cell ending in a period, p-value significance legend.

"stargazer"

Replicates the original stargazer output byte-for-byte: double top rule with \\{[}-1.8ex{]}, \cline, blank spacer rows (controlled by no.space), right-aligned notes.

"aer"

American Economic Review style: clean layout, no “Dependent variable:” caption, single bottom rule, left-aligned notes with text significance descriptions.

"qje"

Quarterly Journal of Economics style: like "aer" but double bottom rule, right-aligned notes, and \textit{N} for the observations label.

obs.label

Character; overrides the label for the Observations row. Defaults to the style preset ("Observations" for most styles, "\textit\{N\}" for "qje").

summary.stat

Character vector; which summary statistics to include when stargazer is called with a data.frame. Recognised values: "n", "mean", "sd", "min", "max", "median", "p25", "p75". Default: c("n","mean","sd","min","max").

median

Logical; if TRUE, add a Median column to summary tables. Equivalent to including "median" in summary.stat. Default: FALSE.

vcov

List of variance-covariance matrices (one per model, or NULL for a given model to fall back to auto-extraction). Takes priority over se. The square root of the diagonal is extracted internally.

se

List of numeric vectors of standard errors (one per model, or NULL to fall back to auto-extraction). Used only when vcov is not supplied for a given model.

se_label

Character vector (one per model, or a single string applied to all) overriding the auto-detected SE-type description used in the table note. Useful when supplying a vcov matrix whose type cannot be detected automatically. Examples: "Heteroskedasticity-robust standard errors (HC1)", "Standard errors clustered by firm".

out

Character; file path. If provided, output is written to the file (appending the appropriate extension if absent). The table string is also returned invisibly.

Value

The rendered table as a single character string, returned invisibly. Also printed to the console unless out is specified.

Examples

m1 <- lm(mpg ~ cyl + hp, mtcars)
m2 <- lm(mpg ~ cyl + hp + wt, mtcars)
stargazer(m1, m2, type = "text")
stargazer(m1, m2, type = "latex")


Render a summary statistics table

Description

Internal; called by stargazer when its first argument is a data.frame or matrix.

Usage

stargazer_summary(
  data,
  type,
  title = "",
  label = "",
  font.size = NULL,
  covariate.labels = NULL,
  omit = NULL,
  keep = NULL,
  digits = 3L,
  summary.stat = NULL,
  median = FALSE,
  notes = NULL,
  notes.append = TRUE,
  notes.align = "l",
  notes.label = "",
  out = NULL
)