Skip to main content

Fast high dimensional fixed effect estimation following syntax of the fixest R package. Supports OLS, IV and Poisson regression and a range of inference procedures. Additionally, experimentally supports (some of) the regression based new Difference-in-Differences Estimators (Did2s).

Project description

PyFixest: Fast High-Dimensional Fixed Effects Regression in Python

PyPI - Version PyPI - Python Version PyPI - Downloads image

PyFixest is a Python implementation of the formidable fixest package for fast high-dimensional fixed effects regression. The package aims to mimic fixest syntax and functionality as closely as Python allows: if you know fixest well, the goal is that you won't have to read the docs to get started! In particular, this means that all of fixest's defaults are mirrored by PyFixest - currently with only one small exception. Nevertheless, for a quick introduction, you can take a look at the tutorial or the regression chapter of Arthur Turrell's book on Coding for Economists.

Features

  • OLS and IV Regression
  • Poisson Regression following the ppmlhdfe algorithm
  • Multiple Estimation Syntax
  • Several Robust and Cluster Robust Variance-Covariance Types
  • Wild Cluster Bootstrap Inference (via wildboottest)
  • Difference-in-Difference Estimators:
  • Multiple Hypothesis Corrections following the Procedure by Romano and Wolf

Installation

You can install the release version from PyPi by running

pip install -U pyfixest

or the development version from github by running

pip install git+https://github.com/s3alfisc/pyfixest.git

News

PyFixest 0.15.2 adds support for Romano-Wolf Corrected p-values via the rwolf() function.

Benchmarks

All benchmarks follow the fixest benchmarks. All non-pyfixest timings are taken from the fixest benchmarks.

Quickstart

import pyfixest as pf

data = pf.get_data()
pf.feols("Y ~ X1 | f1 + f2", data=data).summary()
###

Estimation:  OLS
Dep. var.: Y, Fixed effects: f1+f2
Inference:  CRV1
Observations:  997

| Coefficient   |   Estimate |   Std. Error |   t value |   Pr(>|t|) |   2.5 % |   97.5 % |
|:--------------|-----------:|-------------:|----------:|-----------:|--------:|---------:|
| X1            |     -0.919 |        0.065 |   -14.057 |      0.000 |  -1.053 |   -0.786 |
---
RMSE: 1.441   R2: 0.609   R2 Within: 0.2

Multiple Estimation

You can estimate multiple models at once by using multiple estimation syntax:

# OLS Estimation: estimate multiple models at once
fit = pf.feols("Y + Y2 ~X1 | csw0(f1, f2)", data = data, vcov = {'CRV1':'group_id'})
# Print the results
pf.etable([fit.fetch_model(i) for i in range(6)])
Model:  Y~X1
Model:  Y2~X1
Model:  Y~X1|f1
Model:  Y2~X1|f1
Model:  Y~X1|f1+f2
Model:  Y2~X1|f1+f2
                          est1               est2               est3               est4               est5               est6
------------  ----------------  -----------------  -----------------  -----------------  -----------------  -----------------
depvar                       Y                 Y2                  Y                 Y2                  Y                 Y2
-----------------------------------------------------------------------------------------------------------------------------
Intercept     0.919*** (0.121)   1.064*** (0.232)
X1             -1.0*** (0.117)  -1.322*** (0.211)  -0.949*** (0.087)  -1.266*** (0.212)  -0.919*** (0.069)  -1.228*** (0.194)
-----------------------------------------------------------------------------------------------------------------------------
f2                           -                  -                  -                  -                  x                  x
f1                           -                  -                  x                  x                  x                  x
-----------------------------------------------------------------------------------------------------------------------------
R2                       0.123              0.037              0.437              0.115              0.609              0.168
S.E. type         by: group_id       by: group_id       by: group_id       by: group_id       by: group_id       by: group_id
Observations               998                999                997                998                997                998
-----------------------------------------------------------------------------------------------------------------------------
Significance levels: * p < 0.05, ** p < 0.01, *** p < 0.001
Format of coefficient cell:
Coefficient (Std. Error)

Adjust Standard Errors "on-the-fly"

Standard Errors can be adjusted after estimation, "on-the-fly":

fit1 = fit.fetch_model(0)
fit1.vcov("hetero").summary()
Model:  Y~X1
###

Estimation:  OLS
Dep. var.: Y
Inference:  hetero
Observations:  998

| Coefficient   |   Estimate |   Std. Error |   t value |   Pr(>|t|) |   2.5 % |   97.5 % |
|:--------------|-----------:|-------------:|----------:|-----------:|--------:|---------:|
| Intercept     |      0.919 |        0.112 |     8.223 |      0.000 |   0.699 |    1.138 |
| X1            |     -1.000 |        0.082 |   -12.134 |      0.000 |  -1.162 |   -0.838 |
---
RMSE: 2.158   R2: 0.123

Poisson Regression via fepois()

You can estimate Poisson Regressions via the fepois() function:

poisson_data = pf.get_data(model = "Fepois")
pf.fepois("Y ~ X1 + X2 | f1 + f2", data = poisson_data).summary()
###

Estimation:  Poisson
Dep. var.: Y, Fixed effects: f1+f2
Inference:  CRV1
Observations:  997

| Coefficient   |   Estimate |   Std. Error |   t value |   Pr(>|t|) |   2.5 % |   97.5 % |
|:--------------|-----------:|-------------:|----------:|-----------:|--------:|---------:|
| X1            |     -0.008 |        0.035 |    -0.239 |      0.811 |  -0.076 |    0.060 |
| X2            |     -0.015 |        0.010 |    -1.471 |      0.141 |  -0.035 |    0.005 |
---
Deviance: 1068.836

IV Estimation via three-part formulas

Last, PyFixest also supports IV estimation via three part formula syntax:

fit_iv = pf.feols("Y ~ 1 | f1 | X1 ~ Z1", data = data)
fit_iv.summary()
###

Estimation:  IV
Dep. var.: Y, Fixed effects: f1
Inference:  CRV1
Observations:  997

| Coefficient   |   Estimate |   Std. Error |   t value |   Pr(>|t|) |   2.5 % |   97.5 % |
|:--------------|-----------:|-------------:|----------:|-----------:|--------:|---------:|
| X1            |     -1.025 |        0.115 |    -8.930 |      0.000 |  -1.259 |   -0.790 |
---

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyfixest-0.17.1.tar.gz (2.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyfixest-0.17.1-py3-none-any.whl (2.1 MB view details)

Uploaded Python 3

File details

Details for the file pyfixest-0.17.1.tar.gz.

File metadata

  • Download URL: pyfixest-0.17.1.tar.gz
  • Upload date:
  • Size: 2.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for pyfixest-0.17.1.tar.gz
Algorithm Hash digest
SHA256 69bebdb96e2aa883a4892b299b7e4e48674a73e4f857d4f0e8175899c8a8a9ac
MD5 4d93688a6f8e8aacbfa5a04e00728bf7
BLAKE2b-256 08fb76942530fe7ace9c569881e85674b821653f2349da7a709c74f10aa2bdaa

See more details on using hashes here.

File details

Details for the file pyfixest-0.17.1-py3-none-any.whl.

File metadata

  • Download URL: pyfixest-0.17.1-py3-none-any.whl
  • Upload date:
  • Size: 2.1 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for pyfixest-0.17.1-py3-none-any.whl
Algorithm Hash digest
SHA256 144ea378c910fc75ed3f2169ddcaff04b2a2295186d9111feb6d705cc6c85979
MD5 b6120009d10254acb57c74b0e0771467
BLAKE2b-256 1f1efaf6c339b711aac2b8290e0a1050a6226e22d2e7f3a91fb4af7385b89037

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page