Package 'stargazer2'

Title: Beautiful Regression Tables for Modern Econometrics Packages
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>.
Authors: Tom Zylkin [aut, cre]
Maintainer: Tom Zylkin <[email protected]>
License: GPL-3
Version: 0.1.0
Built: 2026-07-17 18:46:38 UTC
Source: https://github.com/cran/stargazer2

Help Index


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")
}

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")