Panel data
Start with the expanded example for each command. Open the variants for options and alternative R approaches. Read the qualifications before adapting the code.
hausman
Hausman comparison of fixed and random effects
Stata
hausman fixed randomR Package:plm
plm::phtest(fe, re)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Requires same regressors and compatible covariance assumptions.
xtcloglog
Random-intercept panel cloglog
Stata
xtcloglog binary x, reR Package:lme4
lme4::glmer(binary ~ x + (1 | id), data = data, family = stats::binomial(link = "cloglog"), nAGQ = 12)Differs from Stata Uses normal panel random intercepts and 12-point adaptive quadrature, matching Stata intpoints(12). Quadrature adaptation and convergence criteria remain package-specific.
xtdpd
One-step difference GMM for a dynamic panel
Stata
xtdpd y L.y x, div(x) dgmmiv(y, lagrange(2 3))R Package:plm
{ plm <- plm::plm; plm::pgmm(y ~ lag(y, 1) + x | lag(y, 2:3), data = pd, effect = "individual", model = "onestep", transformation = "d", collapse = TRUE) }Differs from Stata Fixed workflow; adapt the named data columns explicitly. Supports the standard difference-GMM subset, with deliberately collapsed instruments. Stata xtdpd supports richer error processes; align instruments, initial weight matrices and finite-sample corrections before comparing.
xtdpdsys
System GMM with level and differenced equations
Stata
xtdpdsys y x, maxldep(3)R Package:plm
{ plm <- plm::plm; plm::pgmm(y ~ lag(y, 1) + x | lag(y, 2:3), data = pd, effect = "individual", model = "onestep", transformation = "ld", collapse = TRUE) }Differs from Stata Fixed workflow; adapt the named data columns explicitly. Additional level moment conditions require stronger initial-condition assumptions. Instrument collapsing, instrument ranges and weighting differ unless explicitly matched; no blanket parity with xtdpdsys defaults.
xtgee
binomial GEE with exchangeable working correlation
Stata
xtgee binary x, family( binomial ) corr( exchangeable )R Package:geepack
geepack::geeglm(binary ~ x, id = id, waves = time, data = data, family = stats::binomial(), corstr = "exchangeable")Differs from Stata Keep rows sorted in contiguous panels. geeglm defaults to sandwich robust standard errors (std.err=“san.se”), corresponding to xtgee, vce(robust); Stata defaults to conventional model-based standard errors. Scale estimation, small-sample adjustments and correlation estimation may still differ.
binomial GEE with independence working correlation
Stata
xtgee binary x, family( binomial ) corr( independence )R Package:geepack
geepack::geeglm(binary ~ x, id = id, waves = time, data = data, family = stats::binomial(), corstr = "independence")Differs from Stata Keep rows sorted in contiguous panels. geeglm defaults to sandwich robust standard errors (std.err=“san.se”), corresponding to xtgee, vce(robust); Stata defaults to conventional model-based standard errors. Scale estimation, small-sample adjustments and correlation estimation may still differ.
gaussian GEE with ar1 working correlation
Stata
xtgee y x, family( gaussian ) corr( ar1 )R Package:geepack
geepack::geeglm(y ~ x, id = id, waves = time, data = data, family = stats::gaussian(), corstr = "ar1")Differs from Stata Keep rows sorted in contiguous panels. geeglm defaults to sandwich robust standard errors (std.err=“san.se”), corresponding to xtgee, vce(robust); Stata defaults to conventional model-based standard errors. Scale estimation, small-sample adjustments and correlation estimation may still differ.
gaussian GEE with exchangeable working correlation
Stata
xtgee y x, family( gaussian ) corr( exchangeable )R Package:geepack
geepack::geeglm(y ~ x, id = id, waves = time, data = data, family = stats::gaussian(), corstr = "exchangeable")Differs from Stata Keep rows sorted in contiguous panels. geeglm defaults to sandwich robust standard errors (std.err=“san.se”), corresponding to xtgee, vce(robust); Stata defaults to conventional model-based standard errors. Scale estimation, small-sample adjustments and correlation estimation may still differ.
gaussian GEE with independence working correlation
Stata
xtgee y x, family( gaussian ) corr( independence )R Package:geepack
geepack::geeglm(y ~ x, id = id, waves = time, data = data, family = stats::gaussian(), corstr = "independence")Differs from Stata Keep rows sorted in contiguous panels. geeglm defaults to sandwich robust standard errors (std.err=“san.se”), corresponding to xtgee, vce(robust); Stata defaults to conventional model-based standard errors. Scale estimation, small-sample adjustments and correlation estimation may still differ.
4 more examples and alternatives
binomial GEE with ar1 working correlation
Stata
xtgee binary x, family( binomial ) corr( ar1 )R Package:geepack
geepack::geeglm(binary ~ x, id = id, waves = time, data = data, family = stats::binomial(), corstr = "ar1")Differs from Stata Keep rows sorted in contiguous panels. geeglm defaults to sandwich robust standard errors (std.err=“san.se”), corresponding to xtgee, vce(robust); Stata defaults to conventional model-based standard errors. Scale estimation, small-sample adjustments and correlation estimation may still differ.
poisson GEE with ar1 working correlation
Stata
xtgee count x, family( poisson ) corr( ar1 )R Package:geepack
geepack::geeglm(count ~ x, id = id, waves = time, data = data, family = stats::poisson(), corstr = "ar1")Differs from Stata Keep rows sorted in contiguous panels. geeglm defaults to sandwich robust standard errors (std.err=“san.se”), corresponding to xtgee, vce(robust); Stata defaults to conventional model-based standard errors. Scale estimation, small-sample adjustments and correlation estimation may still differ.
poisson GEE with exchangeable working correlation
Stata
xtgee count x, family( poisson ) corr( exchangeable )R Package:geepack
geepack::geeglm(count ~ x, id = id, waves = time, data = data, family = stats::poisson(), corstr = "exchangeable")Differs from Stata Keep rows sorted in contiguous panels. geeglm defaults to sandwich robust standard errors (std.err=“san.se”), corresponding to xtgee, vce(robust); Stata defaults to conventional model-based standard errors. Scale estimation, small-sample adjustments and correlation estimation may still differ.
poisson GEE with independence working correlation
Stata
xtgee count x, family( poisson ) corr( independence )R Package:geepack
geepack::geeglm(count ~ x, id = id, waves = time, data = data, family = stats::poisson(), corstr = "independence")Differs from Stata Keep rows sorted in contiguous panels. geeglm defaults to sandwich robust standard errors (std.err=“san.se”), corresponding to xtgee, vce(robust); Stata defaults to conventional model-based standard errors. Scale estimation, small-sample adjustments and correlation estimation may still differ.
xtgls
Group-heteroskedastic panel GLS by maximum likelihood
Stata
xtgls y x z, panels(heteroskedastic) iglsR Package:nlme
nlme::gls(y ~ x + z, data = data, weights = nlme::varIdent(form = ~1 | id), method = "ML")Fixed workflow; adapt the named data columns explicitly. Common slopes with independent residuals and group-specific residual variances; likelihood, variance normalization and convergence criteria can differ.
xthtaylor
Hausman-Taylor model with time-varying and invariant endogenous covariates
Stata
xthtaylor y x1 x2 a b, endog(x2 b) constant(a b)R Package:plm
plm::plm(y ~ x1 + x2 + a + b | x1 + a | x2, data = data, index = c("id", "time"), random.method = "ht", model = "random", inst.method = "baltagi")Differs from Stata Fixed workflow; adapt the named data columns explicitly. The three-part R formula explicitly separates exogenous covariates and time-varying endogenous covariates. Identification of invariant endogenous effects requires sufficient exogenous time-varying instruments; these classifications need substantive justification.
xtivreg
Fixed-effects instrumental-variable regression
Stata
xtivreg y z (x = instrument), feR Package:plm
plm::plm(y ~ x + z | instrument + z, data = pd, model = "within")Differs from Stata Fixed workflow; adapt the named data columns explicitly. Instrument validity must be justified substantively; this fixture only verifies execution.
xtlogit
Conditional fixed-effects logistic regression
Stata
xtlogit binary x, feR Package:survival
{ coxph <- survival::coxph; survival::clogit(binary ~ x + survival::strata(id), data = data) }Differs from Stata Fixed workflow; adapt the named data columns explicitly. Conditions out group intercepts; groups without outcome variation contribute no coefficient information.
xtpcse
Beck-Katz panel-corrected covariance
Stata
xtpcse y x z, correlation(independent)R Package:plm
{ fit <- plm::plm(y ~ x + z, data = pd, model = "pooling"); lmtest::coeftest(fit, vcov. = plm::vcovBK(fit, type = "HC0", cluster = "time")) }Differs from Stata vcovBK(cluster=“time”) allows contemporaneous cross-panel covariance, as required for PCSE. Balancedness, pairwise missing-data treatment, finite-sample normalization and reference tests can still differ from xtpcse.
xtpoisson
Random-intercept panel Poisson
Stata
xtpoisson count x, re normalR Package:lme4
lme4::glmer(count ~ x + (1 | id), data = data, family = stats::poisson(link = "log"), nAGQ = 12)Differs from Stata Uses normal panel random intercepts and 12-point adaptive quadrature, matching the Stata integration-point default. xtpoisson requires re normal for this distribution; its plain re default is gamma. Quadrature adaptation and convergence criteria remain package-specific.
xtprobit
Random-intercept panel probit
Stata
xtprobit binary x, reR Package:lme4
lme4::glmer(binary ~ x + (1 | id), data = data, family = stats::binomial(link = "probit"), nAGQ = 12)Differs from Stata Uses normal panel random intercepts and 12-point adaptive quadrature, matching Stata intpoints(12). Quadrature adaptation and convergence criteria remain package-specific.
xtrc
Random-coefficient panel model workflow
Stata
xtrc y x zR Package:nlme
nlme::lme(y ~ x + z, random = ~ x + z | id, data = data, method = "ML")All three coefficients (intercept, x and z) vary by panel. nlme fits a Gaussian mixed model by ML; xtrc uses Swamy random-coefficient GLS, so the estimators and covariance estimates differ.
xtreg
Individual and time fixed effects
Stata
xtreg y x z i.time, feR Package:plm
plm::plm(y ~ x + z, data = pd, model = "within", effect = "twoways")Differs from Stata Fixed workflow; adapt the named data columns explicitly. First-difference and pooled rows are explicit benchmarks; match estimator and effects.
11 more examples and alternatives
Between-unit regression
Stata
xtreg y x z, beR Package:plm
plm::plm(y ~ x + z, data = pd, model = "between", effect = "individual")Differs from Stata Fixed workflow; adapt the named data columns explicitly. First-difference and pooled rows are explicit benchmarks; match estimator and effects.
Individual fixed effects
Stata
xtreg y x z, feR Package:plm
plm::plm(y ~ x + z, data = pd, model = "within", effect = "individual")Differs from Stata Fixed workflow; adapt the named data columns explicitly. First-difference and pooled rows are explicit benchmarks; match estimator and effects.
Fit a within-panel fixed-effects regression
Stata
xtreg y x z, feR Package:plm
plm::plm(y ~ x + z, data = pd, model = "within", effect = "individual")Both commands fit individual fixed effects using the within transformation. plm reports the transformed-model coefficient vector without Stata reported intercept; residual degrees of freedom and covariance scaling must be aligned separately.
Cluster-robust panel standard errors
Stata
xtreg y x z, fe vce(cluster id)R Package:plm
{ V <- plm::vcovHC(fit, method = "arellano", type = "HC1", cluster = "group"); lmtest::coeftest(fit, vcov. = V) }Differs from Stata Stata xtreg, fe vce(robust) equals vce(cluster id). plm HC1 uses N/(N-K) with K counting within-model coefficients and coeftest uses residual degrees of freedom; Stata also applies its cluster correction and uses G-1 reference degrees of freedom. These standard errors and p-values are not exact Stata finite-sample parity.
Cluster-robust within-panel standard errors
Stata
xtreg y x z, fe vce(robust)R Package:plm
{ V <- plm::vcovHC(fit, method = "arellano", type = "HC1", cluster = "group"); lmtest::coeftest(fit, vcov. = V) }Differs from Stata Stata xtreg, fe vce(robust) equals vce(cluster id). plm HC1 uses N/(N-K) with K counting within-model coefficients and coeftest uses residual degrees of freedom; Stata also applies its cluster correction and uses G-1 reference degrees of freedom. These standard errors and p-values are not exact Stata finite-sample parity.
Pooled panel regression benchmark
Stata
xtreg y x z, pa corr(independent)R Package:plm
plm::plm(y ~ x + z, data = pd, model = "pooling", effect = "individual")Under independent working correlation, population-averaged Gaussian GEE and pooled OLS have the same coefficients. xtreg, pa defaults to conventional model-based GEE covariance (not robust unless requested); pooled plm uses OLS residual scaling, so reported standard errors can differ.
Random-effects panel regression
Stata
xtreg y x z, reR Package:plm
plm::plm(y ~ x + z, data = pd, model = "random", effect = "individual")Differs from Stata Fixed workflow; adapt the named data columns explicitly. First-difference and pooled rows are explicit benchmarks; match estimator and effects.
Random effects with amemiya variance components
Stata
xtreg y x z, reR Package:plm
plm::plm(y ~ x + z, data = pd, model = "random", random.method = "amemiya")Amemiya is an R alternative variance-component estimator with no corresponding xtreg option. Stata xtreg, re uses its default estimator or sa for Swamy-Arora; the Stata line does not select Amemiya and numerical parity is not claimed.
Random effects with nerlove variance components
Stata
xtreg y x z, reR Package:plm
plm::plm(y ~ x + z, data = pd, model = "random", random.method = "nerlove")Nerlove is an R alternative variance-component estimator with no corresponding xtreg option. Stata xtreg, re uses its default estimator or sa for Swamy-Arora; the Stata line does not select Nerlove and numerical parity is not claimed.
Random effects with swar variance components
Stata
xtreg y x z, reR Package:plm
plm::plm(y ~ x + z, data = pd, model = "random", random.method = "swar")Fixed workflow; adapt the named data columns explicitly. These are named alternative variance-component estimators; only matching methods justify comparing estimates.
Random effects with walhus variance components
Stata
xtreg y x z, reR Package:plm
plm::plm(y ~ x + z, data = pd, model = "random", random.method = "walhus")Walhus is an R alternative variance-component estimator with no corresponding xtreg option. Stata xtreg, re uses its default estimator or sa for Swamy-Arora; the Stata line does not select Walhus and numerical parity is not claimed.
xtregar
Random intercept with AR(1) residual correlation
Stata
xtregar y x z, reR Package:nlme
nlme::lme(y ~ x + z, random = ~1 | id, correlation = nlme::corAR1(form = ~time | id), data = data, method = "ML")Fixed workflow; adapt the named data columns explicitly. Likelihood-based mixed-model workflow differs from xtregar’s estimator.
xtscc
Driscoll-Kraay covariance
Stata
xtscc y x z, fe lag(2)R Package:plm
{ V <- plm::vcovSCC(fit, type = "HC1", maxlag = 2); lmtest::coeftest(fit, vcov. = V) }Differs from Stata Requires the community command xtscc (ssc install xtscc); xtreg has no vce(dkraay) option. Both use a within estimator with lag-2 Driscoll-Kraay covariance; finite-sample scaling and reference degrees of freedom differ.
xttest0
Breusch-Pagan test of individual random effects
Stata
xtreg y x z, re
xttest0R Package:plm
plm::plmtest(plm::plm(y ~ x + z, data = pd, model = "pooling"), type = "bp", effect = "individual")Differs from Stata Fixed workflow; adapt the named data columns explicitly. Stata’s boundary-adjusted mixture distribution can differ from plm’s chi-square reference.
xtunitroot
Panel unit-root test: madwu
Stata
xtunitroot fisher y, dfuller lags(1)R Package:plm
plm::purtest(pd$y, test = "madwu", exo = "intercept", lags = 1, pmax = 1)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Hadri reverses the null to stationarity; deterministic terms and lag rules must match.
Panel unit-root test: hadri
Stata
xtunitroot hadri y, robustR Package:plm
plm::purtest(pd$y, test = "hadri", exo = "intercept", Hcons = TRUE)Differs from Stata The null is panel stationarity. Hcons=TRUE selects the heteroskedasticity-robust Hadri statistic, corresponding to Stata robust; plm ignores lag selections for Hadri and provides no Bartlett HAC kernel correction.
Panel unit-root test: ips
Stata
xtunitroot ips y, lags(1)R Package:plm
plm::purtest(pd$y, test = "ips", exo = "intercept", lags = 1, pmax = 1)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Hadri reverses the null to stationarity; deterministic terms and lag rules must match.
Panel unit-root test: levinlin
Stata
xtunitroot llc y, lags(1)R Package:plm
plm::purtest(pd$y, test = "levinlin", exo = "intercept", lags = 1, pmax = 1)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Hadri reverses the null to stationarity; deterministic terms and lag rules must match.