/wildboottest

python module for wild cluster bootstrapping

Primary LanguagePythonMIT LicenseMIT

wildboottest

PyPI PyPI - Downloads

wildboottest implements multiple fast wild cluster bootstrap algorithms as developed in Roodman et al (2019) and MacKinnon, Nielsen & Webb (2022).

It has similar, but more limited functionality than Stata's boottest, R's fwildcusterboot or Julia's WildBootTests.jl. It supports

At the moment, wildboottest only computes wild cluster bootstrapped p-values, and no confidence intervals.

Other features that are currently not supported:

  • The subcluster bootstrap (MacKinnon and Webb 2018).
  • Confidence intervals formed by inverting the test and iteratively searching for bounds.
  • Multiway clustering.

Direct support for statsmodels and linearmodels is work in progress.

If you'd like to cooperate, either send us an email or comment in the issues section!

Installation

You can install wildboottest from PyPi by running

pip install wildboottest

Example

import pandas as pd
import statsmodels.formula.api as sm
from wildboottest.wildboottest import wildboottest

df = pd.read_csv("https://raw.github.com/vincentarelbundock/Rdatasets/master/csv/sandwich/PetersenCL.csv")
model = sm.ols(formula='y ~ x', data=df)

wildboottest(model, param = "x", cluster = df.firm, B = 9999, bootstrap_type = '11')
# | param   |   statistic |   p-value |
# |:--------|------------:|----------:|
# | x       |      20.453 |     0.000 |

wildboottest(model, param = "x", cluster = df.firm, B = 9999, bootstrap_type = '31')
# | param   |   statistic |   p-value |
# |:--------|------------:|----------:|
# | x       |      30.993 |     0.000 |

# bootstrap inference for all coefficients
wildboottest(model, cluster = df.firm, B = 9999, bootstrap_type = '31')
# | param     |   statistic |   p-value |
# |:----------|------------:|----------:|
# | Intercept |       0.443 |     0.655 |
# | x         |      20.453 |     0.000 |

# non-clustered wild bootstrap inference
wildboottest(model, B = 9999, bootstrap_type = '11')
# | param     |   statistic |   p-value |
# |:----------|------------:|----------:|
# | Intercept |       1.047 |     0.295 |
# | x         |      36.448 |     0.000 |