skills/43-wentorai-research-plugins/skills/analysis/econometrics/panel-data-guide/SKILL.md
Panel data analysis with fixed and random effects models
npx skillsauth add brycewang-stanford/Awesome-Agent-Skills-for-Empirical-Research panel-data-guideInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Estimate and interpret fixed effects, random effects, and dynamic panel models using Stata, R, and Python for longitudinal/panel datasets.
Panel data (also called longitudinal or cross-sectional time-series data) tracks the same units (individuals, firms, countries) across multiple time periods. This structure enables:
| unit_id | year | gdp_growth | investment | trade_openness |
|---------|------|-----------|------------|----------------|
| USA | 2015 | 2.9 | 20.5 | 28.3 |
| USA | 2016 | 1.7 | 20.1 | 27.1 |
| USA | 2017 | 2.3 | 20.8 | 27.5 |
| CHN | 2015 | 6.9 | 43.3 | 39.9 |
| CHN | 2016 | 6.7 | 42.7 | 37.2 |
| CHN | 2017 | 6.9 | 43.1 | 38.1 |
Key notation:
Y_it = alpha + beta * X_it + epsilon_it
Ignores panel structure; assumes no unit-specific effects. Rarely appropriate.
Y_it = alpha_i + beta * X_it + epsilon_it
Each unit has its own intercept (alpha_i) that captures all time-invariant unobserved heterogeneity. The "within" estimator removes alpha_i by demeaning.
Y_it = alpha + beta * X_it + u_i + epsilon_it
The unit-specific effect u_i is treated as random and uncorrelated with X_it.
* Declare panel structure
xtset country_id year
* Summarize within and between variation
xtsum gdp_growth investment trade_openness
* Fixed effects regression
xtreg gdp_growth investment trade_openness, fe
* Store results for Hausman test
estimates store FE
* Fixed effects with robust standard errors (clustered by unit)
xtreg gdp_growth investment trade_openness, fe vce(cluster country_id)
* Test joint significance of fixed effects
testparm i.country_id
* Random effects regression
xtreg gdp_growth investment trade_openness, re
* Store results for Hausman test
estimates store RE
* Hausman specification test
hausman FE RE
* If p < 0.05: reject RE, use FE
* If p > 0.05: RE is consistent and efficient, prefer RE
* First-differenced regression (alternative to FE)
reg D.gdp_growth D.investment D.trade_openness, vce(cluster country_id)
library(plm)
# Convert to panel data frame
pdata <- pdata.frame(mydata, index = c("country_id", "year"))
# Fixed effects
fe_model <- plm(gdp_growth ~ investment + trade_openness,
data = pdata, model = "within")
summary(fe_model)
# Random effects
re_model <- plm(gdp_growth ~ investment + trade_openness,
data = pdata, model = "random")
summary(re_model)
# Hausman test
phtest(fe_model, re_model)
# Clustered standard errors
library(lmtest)
library(sandwich)
coeftest(fe_model, vcov = vcovHC(fe_model, type = "HC1", cluster = "group"))
# Time fixed effects
fe_twoway <- plm(gdp_growth ~ investment + trade_openness + factor(year),
data = pdata, model = "within")
# Test for time fixed effects
pFtest(fe_twoway, fe_model)
import pandas as pd
from linearmodels.panel import PanelOLS, RandomEffects, compare
# Set multi-index for panel structure
data = data.set_index(["country_id", "year"])
# Fixed effects
fe = PanelOLS.from_formula(
"gdp_growth ~ investment + trade_openness + EntityEffects",
data=data
)
fe_result = fe.fit(cov_type="clustered", cluster_entity=True)
print(fe_result.summary)
# Random effects
re = RandomEffects.from_formula(
"gdp_growth ~ investment + trade_openness + 1",
data=data
)
re_result = re.fit()
print(re_result.summary)
# Two-way fixed effects (entity + time)
twoway = PanelOLS.from_formula(
"gdp_growth ~ investment + trade_openness + EntityEffects + TimeEffects",
data=data
)
twoway_result = twoway.fit(cov_type="clustered", cluster_entity=True)
print(twoway_result.summary)
# Compare models
print(compare({"FE": fe_result, "RE": re_result, "Two-way FE": twoway_result}))
| Test | Stata | R | Null Hypothesis |
|------|-------|---|----------------|
| F-test for FE | Built into xtreg, fe | pFtest() | All alpha_i = 0 (pooled OLS is appropriate) |
| Breusch-Pagan LM | xttest0 | plmtest() | Var(u_i) = 0 (pooled OLS vs. RE) |
| Hausman | hausman FE RE | phtest() | RE is consistent (u_i uncorrelated with X) |
* Wooldridge test for serial correlation in panel data
xtserial gdp_growth investment trade_openness
* If p < 0.05: serial correlation present; use clustered SE or AR(1) correction
# Wooldridge test
pbgtest(fe_model) # Breusch-Godfrey test for serial correlation
* Modified Wald test for groupwise heteroskedasticity
xttest3
* If p < 0.05: heteroskedasticity present; use robust/clustered SE
When a lagged dependent variable is included as a regressor:
* Arellano-Bond one-step GMM
xtabond gdp_growth investment trade_openness, lags(1) vce(robust)
* System GMM (Blundell-Bond) - more efficient
xtdpdsys gdp_growth investment trade_openness, lags(1) vce(robust)
* Sargan/Hansen test for overidentifying restrictions
* AR(2) test for second-order serial correlation
* Basic DID with two-way fixed effects
xtreg outcome treated##post, fe vce(cluster unit_id)
* Event study specification
xtreg outcome i.relative_time##treated, fe vce(cluster unit_id)
Table X: Panel Regression Results (Fixed Effects)
Dependent Variable: GDP Growth (%)
(1) (2) (3)
FE RE Two-way FE
Investment 0.125*** 0.118*** 0.131***
(0.032) (0.029) (0.035)
Trade Openness 0.045** 0.051** 0.038*
(0.018) (0.017) (0.020)
Entity FE Yes No Yes
Time FE No No Yes
Observations 850 850 850
R-squared (within) 0.234 0.228 0.267
Hausman test (p) -- 0.003 --
Notes: Robust standard errors clustered at the country level in
parentheses. * p<0.10, ** p<0.05, *** p<0.01.
development
Conduct rigorous thematic analysis (TA) of qualitative data following Braun and Clarke's (2006) six-phase framework. Use whenever the user mentions 'thematic analysis', 'TA', 'Braun and Clarke', 'qualitative coding', 'identifying themes', or asks for help analysing interviews, focus groups, open-ended survey responses, or transcripts to identify patterns. Also trigger for questions about inductive vs theoretical coding, semantic vs latent themes, essentialist vs constructionist epistemology, building a thematic map, or writing up a qualitative findings section. Covers all six phases, the four upfront analytic decisions, the 15-point quality checklist, and the five common pitfalls. Produces a Word document write-up and an annotated thematic map. Does NOT cover IPA, grounded theory, discourse analysis, conversation analysis, or narrative analysis — use a different method for those.
development
Guide users through writing a systematic literature review (SLR) following the PRISMA 2020 framework. Use this skill whenever the user mentions 'systematic review', 'systematic literature review', 'SLR', 'PRISMA', 'PRISMA 2020', 'PRISMA flow diagram', 'PRISMA checklist', or asks for help writing, structuring, or auditing a literature review that follows reporting guidelines. Also trigger when the user asks about inclusion/exclusion criteria for a review, search strategies for databases like Scopus/WoS/PubMed, study selection processes, risk of bias assessment, or narrative synthesis for a review paper. This skill covers the full PRISMA 2020 checklist (27 items), produces a Word document manuscript in strict journal article format, generates an annotated PRISMA flow diagram, and enforces APA 7th Edition referencing throughout. It does NOT cover meta-analysis or statistical pooling. By Chuah Kee Man.
testing
Performs placebo-in-time sensitivity analysis with hierarchical null model and optional Bayesian assurance. Use when checking model robustness, verifying lack of pre-intervention effects, or estimating study power.
data-ai
Fit, summarize, plot, and interpret a chosen CausalPy experiment. Use after the causal method has been selected, including when configuring PyMC/sklearn models and scale-aware custom priors.