Skip to content

pyfixest

High-dimensional fixed-effects estimation in Python with pyfixest (fixest/reghdfe grammar) for firm-year and firm-quarter panels: multi-way FE with firm clustering, fixest-style multiple specifications, IV with FE, and staggered DiD through did2s and Sun-Abraham instead of naive TWFE. Its iron law is to fix the clustering level and the FE structure before estimating. It adds accounting and finance defaults and pf.etable output for journal tables, and routes simple two-way FE work to python-panel-data and R/Stata users to the sibling skills.

Category: analysis
Field: econometrics
License: MIT (repo LICENSE, "Copyright (c) 2026 John Barrios"). The vendored third-party skills keep their own terms: the Anthropic document skills say "Proprietary. LICENSE.txt has complete terms", and the K-Dense skills carry per-library licence lines.
Updated: 2026-07-23
Stages: data-analysis · code-generation

Barrios Skills — John Barrios's curated workflow for economists and accountants. Prioritize reproducible empirical work, clear identification language, and journal-ready output.

PyFixest for empirical accounting & finance

When to use

  • Firm–year / firm–quarter panels with firm and year (or industry×year) fixed effects
  • High-dimensional FE that are slow in linearmodels or plain statsmodels
  • IV with FE, Poisson/PPML with FE, or modern DiD helpers in Python
  • You already know Stata reghdfe / R fixest and want the same grammar in Python

Prefer python-panel-data when the design is a simple two-way FE / RE with linearmodels and you want textbook panel diagnostics. Prefer r-econometrics / Stata skills when the paper's replication package is R/Stata-first.

Install

Bash
python -m pip install pyfixest
## optional: python -m pip install "pyfixest[plots]"

Docs: pyfixest.org

Iron law: specify clustering and FE before estimating

  1. State the unit of treatment / residual correlation (usually firm, sometimes industry or CEO)
  2. State fixed effects that absorb the design (firm + year; firm + industry×year; etc.)
  3. Estimate with matching vcov / cluster
  4. Inspect N, absorbed FE counts, and a coefficient sample before writing results into a paper

Quick patterns

OLS with multi-way FE + firm clustering

Python
import pyfixest as pf

fit = pf.feols(
    "roa ~ treat + size + mb | gvkey + fyear",
    data=df,
    vcov={"CRV1": "gvkey"},
)
fit.summary()

Multiple specs (fixest-style)

Python
fit = pf.feols(
    "roa ~ treat + size | gvkey + fyear",
    data=df,
    vcov={"CRV1": "gvkey"},
)
## Compare specs with pf.etable([...]) for paper tables

IV with FE

Python
fit = pf.feols(
    "y ~ 1 | gvkey + fyear | endog ~ instrument",
    data=df,
    vcov={"CRV1": "gvkey"},
)

Staggered DiD / event study

Prefer package DiD helpers (did2s, Sun-Abraham / local projections as documented upstream) over naive TWFE when adoption is staggered. Report an event-study plot from a robust estimator, not only TWFE — see econ-writing-plus for narrative conventions.

Accounting / finance defaults

Design Typical FE Cluster
Firm–year treatment gvkey + fyear firm (gvkey)
Industry shock gvkey + fyear or gvkey + industry^fyear firm; sometimes industry
CEO / executive panel exec + year or firm + year firm or exec (justify)
State policy firm + year firm; often state×year FE debate in text

Journal-ready output

  • Export LaTeX via pyfixest / maketables helpers; pair with latex-tables for house style
  • Report within R² / FE set / cluster level in table notes
  • Never paste coefficients without SE and N

Checklist before claiming results

  • Sample filters documented (Compustat indfmt/datafmt/popsrc/consol if from WRDS)
  • FE and cluster match the identification story
  • Staggered timing → not only TWFE
  • One exhibit inspected (sign, magnitude, N) against a raw crosstab