Logo von Python Panel Data

Python Panel Data

Community
JonasWeinert
python-panel-data

Generates rigorous panel and causal-inference code in Python using `pyfixest` (modern fixest port), `linearmodels.PanelOLS`, `statsmodels`, and pandas, with proper fixed effects, clustering, weak-IV diagnostics, event studies, and DIME-aligned reproducibility. Honest about Python's smaller modern-DiD ecosystem and routes the user to R when needed. Use when the user asks for PanelOLS, pyfixest, fixed effects, two-way clustering, IV2SLS, panel DiD, event studies, weak instruments, BJS imputation, or publication-ready Python regression output.

Übersicht

HerausgeberJonasWeinert
RepositoryEconAgentSkills
Skill-Namepython-panel-data
Sterne
30
Forks
4
Mitgelieferte Dateien
7
Links
  • Anweisungen in Markdown

    Eine SKILL.md-Datei, die das Modell bei Bedarf lädt. So werden nur dann Token verbraucht, wenn eine Anfrage tatsächlich dazu passt.

  • Funktioniert mit jedem LLM

    KI-Skills bestehen aus reinem Markdown, nicht aus anbieterspezifischem Code. Daher funktionieren sie mit GPT, Claude, Gemini, Grok oder einem lokalen Modell.

  • 7 mitgelieferte Dateien

    Skripte, Vorlagen und Referenzmaterial, die das Modell bei der Arbeit lesen kann. Die Dateien sind schreibgeschützt und werden niemals ausgeführt.

  • Open Source

    Von JonasWeinert auf GitHub veröffentlicht. Prüfen Sie den Quellinhalt vor der Installation.

Installation

Installieren Sie den KI-Skill Python Panel Data in TypingMind, um ihn mit jedem LLM zu nutzen, oder fügen Sie ihn einem anderen Agenten hinzu, der SKILL.md lesen kann.

1

In TypingMind installieren

TypingMind installiert einen Skill direkt aus seinem GitHub-Ordner — liest SKILL.md, bündelt die Ressourcendateien und speichert das Ergebnis lokal.

  1. Öffnen Sie die App und gehen Sie zu Plugins → Skills.
  2. Wählen Sie „Von GitHub installieren“.
  3. Fügen Sie die unten angegebene URL des Skill-Ordners ein und bestätigen Sie.
    https://github.com/JonasWeinert/EconAgentSkills/tree/main/_skills/analysis/python-panel-data
  4. Aktivieren Sie den Skill in jedem Chat, in dem er verfügbar sein soll.
Plugins → Skills → Skill anlegen → Über GitHub-URL. Fügen Sie dann die Ordner-URL ein und klicken Sie auf „Weiter“.
2

In einem anderen Agenten installieren

Jeder Agent, der das Agent-Skills-Format lesen kann, kann diesen Skill nutzen — kopieren Sie den Ordner in das Skill-Verzeichnis des jeweiligen Agenten.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/JonasWeinert/EconAgentSkills.git /tmp/EconAgentSkills
mkdir -p .claude/skills
cp -r /tmp/EconAgentSkills/_skills/analysis/python-panel-data .claude/skills/python-panel-data
Starten Sie Claude Code nach dem Kopieren neu, damit der neue Skill erkannt wird.

In TypingMind verwenden

Aktivieren Sie Python Panel Data in einem beliebigen Chat in TypingMind. Den Rest übernimmt das Modell. Name und Beschreibung des Skills stehen im System-Prompt. Sobald eine Anfrage passt, lädt das Modell selbstständig die vollständigen Anweisungen — Sie müssen den Skill nie manuell aufrufen, und er verbraucht erst Token, wenn er tatsächlich genutzt wird.

Das Modell lädt Python Panel Data automatisch, sobald eine passende Anfrage gestellt wird.

Funktioniert mit jedem KI-Modell

KI-Skills bestehen aus reinen Markdown-Anweisungen statt aus anbieterspezifischem Code. Daher ist Python Panel Data nicht an das Modell gebunden, für das der Skill geschrieben wurde. Installieren Sie ihn einmal in TypingMind und nutzen Sie ihn mit GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama oder einem selbst betriebenen lokalen Modell — alles mit Ihren eigenen API-Keys.

  • Wird nur bei Bedarf geladen

    Der System-Prompt enthält nur den Namen und die Beschreibung. Die Anweisungen werden bei der ersten passenden Anfrage geladen. Ein ungenutzter Skill verursacht daher keine Kosten.

  • Modell im laufenden Chat wechseln

    Da der Skill aus Anweisungen statt aus Code besteht, funktioniert er auch nach einem Modellwechsel — das nächste Modell liest dieselbe SKILL.md-Datei.

Skill-Anweisungen

Dies ist der Inhalt von SKILL.md, den das Modell lädt. Lesen Sie ihn vor der Installation — ein Skill besteht aus Anweisungen, denen Ihr Modell folgt.

Python Panel Data

Generate rigorous panel and causal-inference code in Python. The modern Python ecosystem is pyfixest for fixest-style speed and syntax, linearmodels.PanelOLS for textbook panel models, and statsmodels for general purpose. Where Python's modern-DiD support is incomplete, point the user to R.

Operating Principles

  1. Identification before code. State the estimand, the source of identifying variation, and the threats to identification before writing any model.
  2. Use pyfixest first when speed and modern syntax matter. Fall back to linearmodels.PanelOLS for textbook panel models, statsmodels for general regression and IV with simple specs.
  3. Be honest about ecosystem gaps. Python's heterogeneity-robust DiD support is weaker than R or Stata. For Callaway-Sant'Anna, BJS, or de Chaisemartin-D'Haultfoeuille, use the corresponding R or Stata skill, or call R via rpy2.
  4. Reproducibility discipline. Pin versions in pyproject.toml or requirements.txt. Use pathlib for paths, pd.read_* with dtype= arguments, and seed every random call.
  5. Tables are produced, never copy-pasted. Use pyfixest.etable, linearmodels LaTeX export, or stargazer for statsmodels.

Decision Policy

This skill follows the repo-wide Agent Policy.

ASK before proceeding (blocking):

  1. Estimand and identification strategy.
  2. Library choice when both apply: pyfixest for speed and modern syntax vs linearmodels.PanelOLS for textbook panel API.
  3. Cluster level for inference.
  4. Whether to switch language (R / Stata) for parts where Python's ecosystem is weaker (Callaway-Sant'Anna, BJS, AR weak-IV CIs).

DEFAULT + flag (use this default; tell the user how to override):

  • pyfixest.feols for panel TWFE, event studies (sunab), and IV with FE.
  • linearmodels.PanelOLS when the user wants explicit EntityEffects / TimeEffects / RandomEffects / FirstDifferenceOLS.
  • statsmodels only for cross-section logit/probit/GLM/simple OLS.
  • wildboottest package when G < 30; otherwise vcov = {"CRV1": "unit"}.
  • Outputs as parquet in data/processed/; tables to paper/tabs/ via pyfixest.etable.

DOCUMENT and proceed (write into the decisions log):

  • Library choice and the reason if non-default.
  • Panel structure (balanced / unbalanced / rotating) inferred from the data.
  • Cross-language jumps (e.g. "Used R did package via subprocess for Callaway-Sant'Anna because no mature Python equivalent").

PROCEED items: pyproject.toml + lockfile, Path(__file__).resolve().parents[N], numpy.random.default_rng(20240101), assert df.duplicated([keys]).sum() == 0 after every load.

Pre-flight Checklist

Before writing code, confirm with the user — and write the answers as a header docstring:

  • Estimand. ATT, LATE, ITT, descriptive?
  • Unit of observation and panel keys. Assert with df.duplicated(["unit", "time"]).sum() == 0.
  • Treatment timing. Single shock, simultaneous, staggered, or reversible?
  • Identifying variation. Which comparison drives the coefficient?
  • Clustering level. Where is treatment assigned, or where does within-group correlation live?
  • Sample. Document each filter with sample sizes.
  • Output target. Working paper, slides, journal submission, or exploratory.

Library Choice

NeedLibraryNotes
Panel TWFE, event studies, IV with FEpyfixestFastest; mirrors R fixest; feols, fepois, iplot
Textbook panel: PanelOLS, RandomEffects, FirstDifferenceOLS, BetweenOLSlinearmodelsRich panel API; explicit EntityEffects, TimeEffects
Cross-section IV2SLS, GMMlinearmodelsIV2SLS, IVGMM
Logit/probit, GLM, simple OLSstatsmodelsStandard, well-documented
Tables (multiple models)pyfixest.etable, stargazer, linearmodels compare()Pick one and stick with it

Install:

bash
pip install pyfixest linearmodels statsmodels pandas pyarrow stargazer

Estimator Decision Tree

Difference-in-Differences

Single shock, two groups, uniform timing
└── pyfixest.feols("y ~ treat_post | unit + time", data=df,
                   vcov={"CRV1": "unit"})

Staggered adoption (the realistic case)
├── Sun-Abraham via pyfixest:
│     pyfixest.feols("y ~ sunab(cohort, time) | unit + time",
│                    data=df, vcov={"CRV1": "unit"})
├── BJS imputation: not yet a polished package; implement manually
│   or use the `differences` package (limited).
└── Callaway-Sant'Anna: use R `did` via rpy2, or switch to the
    R or Stata skill for that estimator.

Continuous or non-binary treatment
└── No mature Python implementation. Use Stata
    `did_multiplegt_dyn` or R `DIDmultiplegt`.

Instrumental Variables

Cross-section 2SLS:
  from linearmodels import IV2SLS
  IV2SLS.from_formula("y ~ 1 + x_exog + [endog ~ z]", data=df).fit(
      cov_type="clustered", clusters=df.cluster
  )

Panel IV with high-dim FE:
  pyfixest.feols("y ~ x_exog | unit + time | endog ~ z",
                 data=df, vcov={"CRV1": "unit"})

Weak-IV diagnostics:
  - linearmodels reports Kleibergen-Paap rk Wald F.
  - For Olea-Pflueger effective F or AR sets, use R `ivDiag`,
    Stata `weakivtest`, or implement AR by hand.

Effective F:
  - F >= 100 → conventional 2SLS is fine.
  - 10 <= F < 100 → use AR or tF; do not rely on conventional t.
  - F < 10  → instrument is weak; do not interpret 2SLS causally.

Inference

Number of clusters G:
  G >= 50      → cluster-robust SE is fine
  30 <= G < 50 → consider HC3-style small-sample correction
  G < 30       → use wild cluster bootstrap (`pyfixest` supports
                 `wildboottest` via the `wildboottest` package)
                 or call Stata `boottest` / R `fwildclusterboot`.

Multi-way clustering:
  pyfixest:    vcov={"CRV1": ["unit", "year"]}
  linearmodels: cov_type="clustered", clusters=df[["unit", "year"]]

Output Skeleton

Every analysis script should follow:

python
"""
analysis_main.py
Project: ProjectABC
Purpose: Main DiD specification on outcome Y
Inputs : data/processed/analysis.parquet
Outputs: results/tables/table_did_main.tex
         results/figures/event_study.pdf
Estimand: ATT of program on Y
Cluster : at the unit level (treatment assignment)
"""
from pathlib import Path
import pandas as pd
import pyfixest as pf

PROJECT = Path(__file__).resolve().parents[2]
DATA_FINAL = PROJECT / "data" / "processed"
RESULTS    = PROJECT / "results"
RESULTS.joinpath("tables").mkdir(parents=True, exist_ok=True)
RESULTS.joinpath("figures").mkdir(parents=True, exist_ok=True)

# 1. Load and assert structure
df = pd.read_parquet(DATA_FINAL / "analysis.parquet")
assert df.duplicated(["unit_id", "year"]).sum() == 0

# 2. Sample construction
df = df.dropna(subset=["outcome"])  # log this filter

# 3. Main and robustness specs
m_main = pf.feols("outcome ~ treat_post | unit_id + year",
                  data=df, vcov={"CRV1": "unit_id"})
m_two  = pf.feols("outcome ~ treat_post | unit_id + year",
                  data=df, vcov={"CRV1": ["unit_id", "year"]})

# 4. Export
pf.etable([m_main, m_two],
          type="tex",
          file_name=str(RESULTS / "tables" / "table_did_main.tex"))

Common Pitfalls

  • Plain TWFE on staggered timing in pyfixest is just as biased as in fixest. Use sunab or switch language.
  • Forgetting to set the panel index in linearmodels. Always df.set_index(["unit", "time"]) before PanelOLS.from_formula.
  • Cluster-robust SE with very few clusters — undercoverage; use wild bootstrap.
  • Mixing pyfixest and linearmodels results in the same table — they sometimes treat absorbed FE differently. Stay within one framework per table.
  • Hardcoded paths — use pathlib.Path(__file__).resolve().parents[N].
  • df["x"] = ... after a chained operation losing .copy() — use df = df.assign(...) or explicit .copy().

Additional Resources

  • reference.md — extended code patterns for each estimator family.
  • examples/ — runnable scripts:
    • examples/twfe_pyfixest.py — TWFE with pyfixest
    • examples/twfe_linearmodels.py — TWFE with linearmodels.PanelOLS
    • examples/event_study_sun_abraham.py — Sun-Abraham via pyfixest
    • examples/iv_panel_pyfixest.py — panel IV with diagnostics
    • examples/clustered_inference.py — multi-way clustering and CR2
    • examples/balance_table.py — pandas + scipy balance tables

Requirements

  • Python >= 3.10
  • Core: pandas, pyarrow, numpy, scipy
  • Econometrics: pyfixest, linearmodels, statsmodels
  • Tables and plots: stargazer, matplotlib
bash
pip install pandas pyarrow numpy scipy pyfixest linearmodels statsmodels stargazer matplotlib

References

  • Berge (2018), fixest: Fast Fixed Effects Estimation. Original reference for the fixest/pyfixest family.
  • Sun & Abraham (2021). Estimating Dynamic Treatment Effects in Event Studies. JoE.
  • Borusyak, Jaravel & Spiess (2024). Revisiting Event Study Designs. ReStud.
  • Olea & Pflueger (2013). A Robust Test for Weak Instruments. JBES.
  • Wooldridge (2010). Econometric Analysis of Cross Section and Panel Data.
  • DIME Analytics, Reproducible Research.
  • DIME Analytics, Data Analysis.
  • pyfixest documentation: https://py-econometrics.github.io/pyfixest/
  • linearmodels documentation: https://bashtage.github.io/linearmodels/

Mitgelieferte Dateien

Das Modell liest diese Dateien bei Bedarf, während der Skill geladen ist. Sie werden als lesbare Dateien bereitgestellt und niemals ausgeführt.

Häufig gestellte Fragen

Was macht der KI-Skill Python Panel Data?

Generates rigorous panel and causal-inference code in Python using `pyfixest` (modern fixest port), `linearmodels.PanelOLS`, `statsmodels`, and pandas, with proper fixed effects, clustering, weak-IV diagnostics, event studies, and DIME-aligned reproducibility. Honest about Python's smaller modern-DiD ecosystem and routes the user to R when needed. Use when the user asks for PanelOLS, pyfixest, fixed effects, two-way clustering, IV2SLS, panel DiD, event studies, weak instruments, BJS imputation, or publication-ready Python regression output.

Warum Python Panel Data in TypingMind nutzen?

Weil Sie den Skill einmal installieren und mit jedem Modell verwenden können. Python Panel Data besteht aus reinem Markdown statt aus anbieterspezifischem Code. So funktioniert derselbe Skill mit GPT-5, Claude, Gemini, Grok oder einem lokalen Modell – und Sie können das Modell mitten im Chat wechseln, ohne dass der Skill seine Funktion verliert. TypingMind verwendet Ihre eigenen API-Schlüssel. Sie bezahlen die Anbieter daher direkt statt über ein Abonnement pro Nutzerplatz, und Ihre Skills und Chats bleiben in Ihrem eigenen Speicher.

Wie installiere ich Python Panel Data in TypingMind?

Öffnen Sie in TypingMind Plugins → Skills → Von GitHub installieren und fügen Sie https://github.com/JonasWeinert/EconAgentSkills/tree/main/_skills/analysis/python-panel-data ein. TypingMind liest die Datei SKILL.md, bündelt die zugehörigen Dateien und installiert alles als Skill, den Sie für jeden Chat einzeln aktivieren können.

Welche KI-Modelle können Python Panel Data nutzen?

Jedes Modell, das Sie in TypingMind verbinden. KI-Skills bestehen aus reinen Markdown-Anweisungen statt aus anbieterspezifischem Code. Daher können GPT, Claude, Gemini, Grok und lokale Modelle diesen Skill laden, wenn eine Anfrage dazu passt.

Wie viele KI-Modelle kann ich mit Python Panel Data verwenden?

So viele Sie möchten. Solange ein Modell Skills unterstützt, können Sie Python Panel Data damit verwenden – GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama und weitere – alles in TypingMind mit Ihren eigenen API-Schlüsseln.

Ist der KI-Skill Python Panel Data kostenlos?

Der Skill wird von JonasWeinert auf GitHub veröffentlicht. Die Lizenzbedingungen finden Sie im Repository. Sie bezahlen nur Ihren eigenen KI-Anbieter für die verwendeten Token.

Was sind KI-Skills?

Ein KI-Skill ist ein wiederverwendbares Anweisungspaket, das einem KI-Modell vermittelt, wie es eine bestimmte Aufgabe erledigt. Es folgt dem offenen Format Agent Skills: eine Datei namens SKILL.md mit einem Namen und einer Beschreibung sowie allen Skripten, Vorlagen oder Referenzdateien, die das Modell möglicherweise benötigt. Das Modell liest die Anweisungen nur, wenn Ihre Anfrage zum Skill passt. Ein installierter Skill verursacht daher erst Kosten, wenn er verwendet wird.

Wie unterscheiden sich KI-Skills von Plugins oder MCP-Servern?

Ein Plugin oder MCP-Server stellt einem Modell neue aufrufbare Tools bereit – Code, der auf einem System ausgeführt wird und ein Ergebnis zurückgibt. Ein KI-Skill vermittelt dem Modell stattdessen Wissen und Vorgehensweisen: wie es eine Aufgabe angeht, welche Schritte es befolgt und wie eine gute Ausgabe aussieht. Skills bestehen aus reinem Markdown und benötigen daher weder Server noch API-Schlüssel oder Laufzeitumgebung. Sie funktionieren mit jedem Modell.

Alle

Jetzt eigenen KI-Arbeitsbereich einrichten

Abonnieren Sie unseren Newsletter und erfahren Sie mehr über neue Funktionen und kommende Gewinnspiele 👇