| name | pyfixest-latex |
| description | Use when generating publication-quality LaTeX tables and figures from PyFixest econometric models, including regression tables, event study plots, and summary statistics for academic research papers. |
| triggers | ["PyFixest","LaTeX tables","econometric","regression table","event study","DiD","difference-in-differences","fixed effects","panel regression","research paper","academic publication"] |
| role | specialist |
| scope | implementation |
| output-format | code |
PyFixest LaTeX Generator
7 functions for converting PyFixest models to publication-quality LaTeX tables and figures.
Tables (4): regression, dynamic/event study, robustness (grouped), summary statistics
Figures (3): event study plot, treatment assignment heatmap, coefficient comparison
Setup
Option A: Run setup script
python <skill-path>/scripts/setup_module.py /path/to/project
Option B: Manual copy
- Copy
assets/pyfixest_latex/ to your project root
- Install dependencies:
pip install pyfixest pandas numpy scipy matplotlib
- Create output dirs:
output/tables/ and output/figures/
Configure paths (required before generating output)
from pyfixest_latex import set_output_path, set_figure_output_path
set_output_path("Results/Tables")
set_figure_output_path("Results/Figures")
Core Workflow
import pyfixest as pf
from pyfixest_latex import (
set_output_path, set_figure_output_path,
create_regression_table, create_event_study_plot,
create_summary_statistics_table
)
set_output_path("Results/Tables")
set_figure_output_path("Results/Figures")
m1 = pf.feols("Y ~ treat | unit + year", data, vcov={"CRV1": "unit"})
m2 = pf.feols("Y ~ treat + X1 | unit + year", data, vcov={"CRV1": "unit"})
create_regression_table(
models=[m1, m2],
model_names=["Basic", "Controls"],
title="Treatment Effects",
label="tab:main",
variable_labels={"treat": "Treatment Effect", "X1": "Control Variable"},
depvar_labels={"Y": "Outcome Variable"},
felabels={"unit": "Unit FE", "year": "Year FE"}
)
Function Quick Reference
Tables
| Function | Purpose | Key Params |
|---|
create_regression_table() | Multi-model comparison | models, model_names, title, label |
create_dynamic_table() | Event study coefficients | models, time_var, treat_var, reference_period, treatment_period |
create_robustness_table() | Grouped specifications | model_groups, group_names |
create_summary_statistics_table() | Descriptive stats | data (DataFrame), variables, variable_labels |
Figures
| Function | Purpose | Key Params |
|---|
create_event_study_plot() | Dynamic effects plot | model, style (errorbar/filled/step), confidence_level |
create_treatment_assignment_plot() | Treatment timing heatmap | data, unit, time, treat |
create_coefficient_comparison_plot() | Forest plot across specs | models, model_names, use_ci |
Utilities
| Function | Purpose |
|---|
set_output_path(path) | Configure table output directory |
set_figure_output_path(path) | Configure figure output directory |
list_saved_tables() | List generated .tex files |
list_saved_figures() | List generated .png/.pdf files |
Full API: See references/tables-api.md and references/figures-api.md
Example Templates & Assets
Complete DiD Analysis Template (849 lines):
Modular Function Examples:
assets/1---example_summary_statistics.py - Standalone summary stats demonstration
assets/2---example_figure_usage.py - Standalone figure generation examples
assets/3---example_enhanced_table_generator.py - Standalone table generation examples
assets/4---run_all_examples.py - Orchestrator to run all modular examples
Which to use?
- DiD template: Copy for complete analysis workflow (data → tables → figures)
- Modular examples: Learn individual functions in isolation, mix-and-match
Reference Documentation
Use these guides to learn specific patterns and troubleshoot issues:
Starting Out?
Preparing Data?
Need Usage Examples?
- Read common-patterns.md for 10 complete patterns (DiD, event studies, robustness checks, multiple outcomes)
DiD Template Documentation?
Customizing Functions?
Troubleshooting?
Using Statsmodels Instead of PyFixest?
Critical Rules
- Set output paths BEFORE calling any generation function — paths are resolved at call time
- Use
type="tex" in PyFixest — the module calls pf.etable(..., type="tex") internally
- Pass
treatment_period to create_dynamic_table() and create_event_study_plot() for correct relative-time labels ($t_{-2}$, $t_0$, $t_{+1}$)
- Unit FE before Time FE — automatic reordering in all tables (recognizes 25+ FE naming patterns)
- CI distribution — t-distribution for n<30, normal for n>=30 (proper small-sample inference)
- Figure backend — uses matplotlib 'Agg' (non-interactive); no GUI required
- Windows — UTF-8 encoding handled automatically in figure generator
- Filenames — auto-generated from
label parameter: {label}_regression.tex, {label}_dynamic.tex, etc.
LaTeX Integration
Required packages in preamble
\usepackage{booktabs}
\usepackage{threeparttable}
\usepackage{graphicx}
\usepackage{makecell} % for multi-line cells with \makecell
Include generated outputs
% Tables
\input{Results/Tables/main_regression.tex}
\input{Results/Tables/event_study_dynamic.tex}
% Figures
\begin{figure}[ht!]
\centering
\includegraphics[width=0.9\textwidth]{Results/Figures/event_study.png}
\caption{Event Study: Treatment Effects Over Time}
\label{fig:event_study}
\end{figure}
Table output structure
All tables use this LaTeX structure:
\begin{table}[ht!]
\centering
\caption{\\Title}
\parbox{\linewidth}{\footnotesize Notes text here}
\label{tab:label}
\footnotesize
\begin{threeparttable}
\begin{tabular}{lccc}
...
\end{tabular}
\end{threeparttable}
\end{table}