Metadata-Version: 2.5
Name: maketables
Version: 0.2.0
Summary: Publication-ready tables from regression results (pyfixest, statsmodels, linearmodels, lifelines, Stata, or any package via a plug-in interface), descriptive statistics, and balance tables, with output to LaTeX, Word, Typst, and HTML (via Great Tables)
Project-URL: Homepage, https://py-econometrics.github.io/maketables/
Project-URL: Documentation, https://py-econometrics.github.io/maketables/
Project-URL: Repository, https://github.com/py-econometrics/maketables
Project-URL: Issues, https://github.com/py-econometrics/maketables/issues
Author-email: Alexander Fischer <alexander-fischer1801@t-online.de>, Dirk Sliwka <dirk.sliwka@uni-koeln.de>
License: MIT
License-File: LICENSE
Keywords: balance table,descriptive statistics,docx,econometrics,etable,great-tables,html,latex,lifelines,linearmodels,plugin,publication,pyfixest,regression,regression table,results table,stargazer,stata,statistics,statsmodels,summary statistics,tables,typst,word
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: great-tables>=0.2
Requires-Dist: ipython>=7
Requires-Dist: numpy>=1.20
Requires-Dist: pandas>=1.3
Requires-Dist: python-docx>=0.8.11
Requires-Dist: tabulate>=0.9
Provides-Extra: dev
Requires-Dist: linearmodels>=4; extra == 'dev'
Requires-Dist: pre-commit<5,>=4.3; extra == 'dev'
Requires-Dist: pyfixest>=0.13; extra == 'dev'
Requires-Dist: pytest-cov>=4; extra == 'dev'
Requires-Dist: pytest<10,>=9.0.3; extra == 'dev'
Requires-Dist: quartodoc>=0.7; extra == 'dev'
Requires-Dist: statsmodels>=0.13; extra == 'dev'
Requires-Dist: syrupy>=4; extra == 'dev'
Requires-Dist: ty>=0.0.1a20; extra == 'dev'
Provides-Extra: docs
Requires-Dist: ipykernel<7,>=6; extra == 'docs'
Requires-Dist: nbconvert>=7; extra == 'docs'
Requires-Dist: pyfixest>=0.13; extra == 'docs'
Requires-Dist: pylatex<2,>=1.4.2; extra == 'docs'
Requires-Dist: pyyaml<7,>=6; extra == 'docs'
Requires-Dist: sphinx-rtd-theme>=1; extra == 'docs'
Requires-Dist: sphinx>=5; extra == 'docs'
Requires-Dist: statsmodels>=0.13; extra == 'docs'
Provides-Extra: lifelines
Requires-Dist: lifelines>=0.27; extra == 'lifelines'
Provides-Extra: linearmodels
Requires-Dist: linearmodels>=4; extra == 'linearmodels'
Requires-Dist: statsmodels>=0.13; extra == 'linearmodels'
Provides-Extra: pystata
Requires-Dist: pystata>=0.0.1; extra == 'pystata'
Requires-Dist: stata-setup>=0.1; extra == 'pystata'
Description-Content-Type: text/markdown

# MakeTables

[![PyPI - Version](https://img.shields.io/pypi/v/maketables)](https://pypi.org/project/maketables/)
[![Python Versions](https://img.shields.io/pypi/pyversions/maketables)](https://pypi.org/project/maketables/)
[![License](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/license/mit)
[![Tests](https://github.com/py-econometrics/maketables/actions/workflows/tests.yml/badge.svg)](https://github.com/py-econometrics/maketables/actions/workflows/tests.yml)
[![Downloads](https://static.pepy.tech/badge/maketables)](https://pepy.tech/project/maketables)
[![Downloads](https://static.pepy.tech/badge/maketables/month)](https://pepy.tech/project/maketables)
[![File an Issue](https://img.shields.io/github/issues/py-econometrics/maketables)](https://github.com/py-econometrics/maketables/issues)

[Docs](https://py-econometrics.github.io/maketables/docs/getting-started.html) ·
[Function & API Reference](https://py-econometrics.github.io/maketables/reference/) ·
[Report Bugs & Request Features](https://github.com/py-econometrics/maketables/issues) ·
[Adding Support for new Model Classes](https://py-econometrics.github.io/maketables/docs/AddingModelClasses.html)

A Python package for creating publication-ready tables from regression results
(`statsmodels`, `pyfixest`, `linearmodels`), descriptive statistics, and balance tables
with output to *LaTeX*, *Word*, *Typst* and *HTML* (HTML tables are created with
[Great Tables](https://github.com/posit-dev/great-tables)). To get started, check out
the
[Getting Started Notebook](https://py-econometrics.github.io/maketables/docs/getting-started.html).

## Overview

MakeTables provides a unified interface for generating tables such as:

- Regression tables from [Statsmodels](https://www.statsmodels.org/stable/index.html),
  [PyFixest](https://py-econometrics.github.io/pyfixest/pyfixest.html),
  [Linearmodels](https://bashtage.github.io/linearmodels/) and
  [Stata](https://www.stata.com/python/pystata19/)
- Descriptive statistics
- Balance tables

The package supports multiple output formats including:

- *Great Tables (HTML)*
- *LaTeX*
- *Microsoft Word (docx)* documents
- *Typst*

## Model Support

`maketables` supports creating regression tables for models from the following packages:

- [PyFixest](https://github.com/py-econometrics/pyfixest)
- [statsmodels](https://github.com/statsmodels/statsmodels)
- [linearmodels](https://github.com/bashtage/linearmodels)
- [lifelines](https://github.com/CamDavidsonPilon/lifelines)

It is very easy to add support for new models - either in the `maketables` code base, or
from within your own package via a maketables **plug-in**. For example,
[ModernDiD](https://github.com/jordandeklerk/moderndid) supports `maketables` for its
difference-in-differences estimators this way (see its guide on
[publication tables](https://moderndid.readthedocs.io/en/latest/user_guide/publication_tables.html)).
Take a look at the
[docs](https://py-econometrics.github.io/maketables/docs/AddingModelClasses.html) to get
started, and please feel free to reach out for help!

### Supporting maketables in your own package

Add these attributes to your result class; your package does not need to import
maketables:

```python
@property
def __maketables_coef_table__(self) -> pd.DataFrame:  # required
    # index: coefficient names; columns: b, se, p (optional: t, ci95l, ci95u, ...)
    return pd.DataFrame({"b": self.params, "se": self.bse, "p": self.pvalues})


def __maketables_stat__(self, key: str):  # optional, e.g. "N", "r2"
    return {"N": self.nobs, "r2": self.rsquared}.get(key)


@property
def __maketables_depvar__(self) -> str:  # optional
    return self.depvar
```

Users can then pass your results directly to `mt.ETable([...])`. All attributes,
statistic keys and a runnable example are in the
[plug-in specification](https://github.com/py-econometrics/maketables/blob/main/PLUGIN_EXTRACTOR_FORMAT.md).

## Origin

MakeTables originated as the table output functionality within the
[pyfixest](https://github.com/py-econometrics/pyfixest) package and has been moved to
this standalone package to provide broader table creation capabilities also supporting
other statistical packages.

## Authors

- Alexander Fischer [https://github.com/s3alfisc](https://github.com/s3alfisc)
- Dirk Sliwka [https://dsliwka.github.io/](https://dsliwka.github.io)

## Installation

### From PyPI

```bash
pip install maketables
```

### Development Installation

```bash
# Clone the repository
git clone https://github.com/yourusername/maketables.git
cd maketables

# Install in development mode
pip install -e .
```

## Quick Start

### Descriptive Statistics Table

```python
import pandas as pd
import maketables as mt

# Load your data (here using a sample Stata dataset with the import_dta function that also stores variable labels)
df = mt.import_dta("https://www.stata-press.com/data/r18/auto.dta")


# Create descriptive statistics table
mt.DTable(df, vars=["mpg", "weight", "length"], bycol=["foreign"])
```

### Regression Tables

#### with pyfixest

```python
import pyfixest as pf

# Fit your models here using pyfixest
est1 = pf.feols("mpg ~ weight", data=df)
est2 = pf.feols("mpg ~ weight + length", data=df)

# Make the table
mt.ETable([est1, est2])
```

#### with statsmodels

```python
import statsmodels.formula.api as smf

# Generate a dummy variable and label it
df["foreign_i"] = (df["foreign"] == "Foreign") * 1
mt.set_var_labels(df, {"foreign_i": "Foreign (indicator)"})

# Fit your models
est1 = smf.ols("foreign_i ~ weight + length + price", data=df).fit()
est2 = smf.probit("foreign_i ~ weight + length + price", data=df).fit(disp=0)

# Make the table
mt.ETable(
    [est1, est2],
    model_stats=["N", "r2", "pseudo_r2", ""],
    model_heads=["OLS", "Probit"],
)
```

## Main Classes

### `MTable`

Base class for all table types with common functionality:

- Multiple output formats (Great Tables, LaTeX, Word)
- Flexible styling and formatting options
- Save and export capabilities
- Can also update tables in existing word documents
- Adapted for use in Jupyter Notebooks and for quarto use (tables automatically rendered
  as html in notebooks and as latex when rendering to pdf in quarto)

### `DTable`

Extends MTable for descriptive statistics:

- Automatic calculation of summary statistics
- Grouping by categorical variables (rows and columns)
- Customizable statistic labels and formatting

### `ETable`

Extends MTable for econometric model results:

- Support for statsmodels, pyfixest, and (more experimental) linearmodels
- Many layout options (relabelling of variables, keep/drop, choice of reported
  statistics, column headings,...)

### `BTable`

Extends MTable for simple balance tables.

## License

This project is licensed under the MIT License - see the LICENSE file for details.

## Acknowledgments

- Built on the excellent [pyfixest](https://github.com/py-econometrics/pyfixest) package
  for econometric models. We gratefully acknowledge the contributors to pyfixest's
  etable: [@s3alfisc](https://github.com/s3alfisc),
  [@dsliwka](https://github.com/dsliwka),
  [@Wenzhi-Ding](https://github.com/Wenzhi-Ding),
  [@juanitorduz](https://github.com/juanitorduz),
  [@NKeleher](https://github.com/NKeleher), [@blucap](https://github.com/blucap),
  [@mortizm1988](https://github.com/mortizm1988), [@jsr-p](https://github.com/jsr-p),
  [@IshwaraHegde97](https://github.com/IshwaraHegde97),
  [@Erica-Ryan](https://github.com/Erica-Ryan),
  [@Dpananos](https://github.com/Dpananos), and
  [@AronNemeth](https://github.com/AronNemeth).
- Uses [Great Tables](https://github.com/posit-dev/great-tables) for beautiful HTML
  table output
