stargazer2 supports plm model objects
natively. It auto-detects the estimator type (FE, RE, Pooled OLS, FD,
Between), displays fixed-effect and random-effect indicator rows, and
reports the appropriate fit statistics from
summary.plm.
The Grunfeld dataset (10 US manufacturing firms,
1935–1954, balanced panel) is included with plm. We
estimate four specifications of an investment equation:
library(plm)
data("Grunfeld", package = "plm")
m_pool <- plm(inv ~ value + capital, Grunfeld,
index = c("firm", "year"), model = "pooling")
m_fe <- plm(inv ~ value + capital, Grunfeld,
index = c("firm", "year"), model = "within")
m_twfe <- plm(inv ~ value + capital, Grunfeld,
index = c("firm", "year"), model = "within", effect = "twoways")
m_re <- plm(inv ~ value + capital, Grunfeld,
index = c("firm", "year"), model = "random")A bare call produces a complete table. stargazer2 reads
the model type from each plm object and builds indicator
rows for the fixed and random effects present across all columns:
Things to notice:
plm ships its own vcov functions. Pass them inline
through the vcov argument.
vcovHC(..., method = "arellano") gives standard errors
clustered by the individual unit, the most common choice for FE
models:
stargazer(m_fe, m_twfe,
type = "text",
vcov = list(vcovHC(m_fe, method = "arellano"),
vcovHC(m_twfe, method = "arellano")))stargazer2 auto-detects the SE type from the inline call
and labels the table note accordingly. For replication of Stata’s
vce(cluster id) results, sandwich::vcovCL is
preferable as it applies the G/(G−1) small-sample correction that Stata
uses; plm::vcovHC applies a heteroskedasticity-style
n/(n−k) correction instead.
For panels with cross-sectional dependence or long time dimensions,
Driscoll-Kraay (spatial HAC) standard errors are a common alternative.
plm::vcovSCC implements this estimator:
Once the defaults look right, labels can be added. The LaTeX source below sets a title and cross-reference label, renames the dependent variable and covariates, and assigns custom column headers: