Convert regression results (statsmodels or pyfixest) to publication-ready LaTeX tables. This package is highly opinionated and seeks to do exactly one thing well.
Moreover, unlike many similar packages, this one is completely free to use and imposes no requirements on users (read more here about problems with other packages).
pip install -U freetableYou'll also need either statsmodels or pyfixest (or both):
pip install statsmodels # for statsmodels support
pip install pyfixest # for pyfixest supportOr use optional dependency groups:
pip install freetable[statsmodels] # includes statsmodels
pip install freetable[pyfixest] # includes pyfixest
pip install freetable[all] # includes both- Clean, opinionated output using modern LaTeX packages
- Automatic significance stars (default: *** p < 0.001; ** p < 0.01; * p < 0.05)
- Customizable significance thresholds
- Variable renaming for clean presentation
- Standard errors in parentheses below coefficients
- R², adjusted R², and number of observations
- Extra custom rows (e.g., outcome labels, SE types, subsets)
- Grouped column headers with multicolumn support
- Customizable table placement
- Optional automatic resizing for wide tables
- Professional formatting with booktabs, siunitx, and threeparttable
Python:
- statsmodels (for statsmodels support) OR
- pyfixest (for pyfixest support)
LaTeX packages:
- threeparttable
- siunitx
- booktabs
- tabularx
- graphicx (only required if using
resize=True)
Add these to your LaTeX document preamble:
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{threeparttable}
\usepackage{tabularx}
\usepackage{graphicx} % Only needed for resize=TrueOr just use paper!
freetable supports regression results from:
- statsmodels - OLS, WLS, GLS, and other linear models
- pyfixest - High-performance fixed effects estimation
You can use models from either library interchangeably, or even mix them in the same table!
See examples/ for the output generated by the following code.
import pandas as pd
import statsmodels.formula.api as smf
from freetable import tabularx
df = pd.read_csv("output.csv")
# Fit your models
m1 = smf.ols("y ~ x1", data=df).fit()
m2 = smf.ols("y ~ x1 + x2", data=df).fit()
# Generate LaTeX table
latex = tabularx(
[m1, m2],
model_names=["Model 1", "Model 2"],
caption="Regression Results",
label="tab:regression",
digits=3,
rename={"x1[T.Male]": "Male", "x2": "Age"},
stars=(0.1, 0.05, 0.01), # Order doesn't matter - automatically sorted
)
print(latex)Did you know? You can replace tabularx by tabularray!
import pandas as pd
import statsmodels.formula.api as smf
from freetable import tabularx
df = pd.read_csv("data.csv")
# Fit three models
m1 = smf.ols("outcome ~ treatment", data=df).fit(cov_type="HC3")
m2 = smf.ols("outcome ~ treatment + control1", data=df).fit(cov_type="HC3")
m3 = smf.ols("outcome ~ treatment + control1 + control2", data=df).fit(
cov_type="cluster",
cov_kwds={"groups": df["cluster_id"]},
)
# Create comprehensive table
latex = tabularx(
[m1, m2, m3],
model_names=["Model 1", "Model 2", "Model 3"],
caption="Treatment Effects on Outcomes",
label="tab:treatment",
digits=3,
rename={"treatment": "Treatment", "control1": "Control 1", "control2": "Control 2"},
extra_rows={
"Outcome": ["Y", "Y", "Y"],
"Subset": ["All", "All", "All"],
"SE type": ["HC3", "HC3", "Clustered"],
},
custom_header=[("Main Effects", 2), ("Full Model", 1)],
placement="h!",
resize=False,
)
print(latex)This package uses the following tools for code quality and consistency:
- black: Code formatting
- ruff: Fast Python linting
- isort: Import sorting
- mypy: Static type checking
- pytest: Testing framework
Install development dependencies:
pip install -Ue ".[dev]"Run tests:
pytestRun type checking:
mypy src/freetable/Everything in this repository is licensed under CC0 1.0 Universal, or (at your option) any later version. See LICENSE for details. Note that there is absolutely no warranty.
