agentleFS
Barrios88Barrios88/barrios-skills/skills/econometrics/pyfixest/SKILL.md

pyfixest

Skill63 starsChanged 5 months agoMITView on GitHub

Fast high-dimensional fixed-effects regression in Python with pyfixest (fixest-like syntax). Use for OLS/IV/Poisson with many FEs, cluster-robust SEs, modern DiD (did2s, Sun-Abraham), and publication tables — the Python counterpart to Stata reghdfe/fixest for accounting and finance panels.

  • Installs packages

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Prefer package DiD helpers (did2s, Sun-Abraham / local projections as documented upstream) over naive TWFE when adoption is staggered.

    line 75
  2. Distinctive:

    Never paste coefficients without SE and N

    line 90

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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

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

import pyfixest as pf

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

Multiple specs (fixest-style)

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

IV with FE

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

DesignTypical FECluster
Firm–year treatmentgvkey + fyearfirm (gvkey)
Industry shockgvkey + fyear or gvkey + industry^fyearfirm; sometimes industry
CEO / executive panelexec + year or firm + yearfirm or exec (justify)
State policyfirm + yearfirm; 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

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.