# Python Panel Data

Panel data analysis with Python using linearmodels and pandas.

- Repository: https://github.com/brycewang-stanford/Auto-Empirical-Research-Skills (4869 stars)
- Category: Data and ML
- License: see repository
- Last updated: 2026-10-30
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add brycewang-stanford/Auto-Empirical-Research-Skills --skill python-panel-data -g -a claude-code -y`
Codex: `npx skills add brycewang-stanford/Auto-Empirical-Research-Skills --skill python-panel-data -g -a codex -y`
Cursor: `npx skills add brycewang-stanford/Auto-Empirical-Research-Skills --skill python-panel-data -g -a cursor -y`
Gemini CLI: `npx skills add brycewang-stanford/Auto-Empirical-Research-Skills --skill python-panel-data -g -a gemini-cli -y`
Claude Code plugin marketplace: `/plugin marketplace add brycewang-stanford/Auto-Empirical-Research-Skills`

## Description

Panel data analysis with Python using linearmodels and pandas.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Python Panel Data

## Purpose

This skill helps economists run panel data models in Python using `pandas`, `statsmodels`, and `linearmodels`, with correct fixed effects, clustering, and diagnostics.

## When to Use

- Estimating fixed effects or random effects models
- Running difference-in-differences on panel data
- Creating regression tables and plots in Python

## Instructions

Follow these steps to complete the task:

### Step 1: Understand the Context

Before generating any code, ask the user:

- What is the unit of observation and panel identifiers?
- Which outcomes and regressors are required?
- What fixed effects or time effects are needed?
- How should standard errors be clustered?

### Step 2: Generate the Output

Based on the context, generate Python code that:

1. **Loads and cleans the data** with `pandas`
2. **Sets a MultiIndex** for panel structure
3. **Fits the model** using `linearmodels.PanelOLS` or `RandomEffects`
4. **Outputs results** in a readable table and optional LaTeX

### Step 3: Verify and Explain

After generating output:

- Interpret key coefficients
- Note assumptions (strict exogeneity, parallel trends, etc.)
- Suggest robustness checks (alternative clustering, placebo tests)

## Example Prompts

- "Run a two-way fixed effects model with firm and year effects"
- "Estimate a DiD using state and year fixed effects"
- "Export panel regression results to LaTeX"

## Example Output

```python
# ============================================
# Panel Data Analysis in Python
# ============================================
import pandas as pd
from linearmodels.panel import PanelOLS

# Load data
df = pd.read_csv("panel_data.csv")

# Set panel index
df = df.set_index(["firm_id", "year"])

# Create treatment indicator
df["treat_post"] = df["treated"] * df["post"]

The rest: https://github.com/brycewang-stanford/Auto-Empirical-Research-Skills/blob/HEAD/skills/09-meleantonio-awesome-econ-ai-stuff/_skills/analysis/python-panel-data/SKILL.md
