Skip to main content

pybdiff

Python replication of Stata's bdiff command. Tests whether regression coefficients differ across two subgroups using permutation tests, bootstrap tests, or parametric Wald tests — with optional parallel execution.

Attribution

This package is a Python reimplementation of the Stata command bdiff originally written by:

Lian, Yujun (连玉君). bdiff: Coefficient Difference Test across Two Groups. Version 1.04, 24 Nov 2020. Sun Yat-sen University. Email: arlionn@163.com · Blog: https://www.lianxh.cn

All methodological credit belongs to the original author. The bootstrap and permutation procedures follow:

Efron, B., Tibshirani, R., 1993. An Introduction to the Bootstrap. Chapman & Hall.

Installation

pip install pybdiff

Quick Start

from pybdiff import bdiff

result = bdiff(
    df      = df,
    group   = "treated",          # column with values 0 and 1
    formula = "y ~ x1 + x2 | firm + year",
    vcov    = {"CRV1": "firm"},
    method  = "permutation",      # "permutation", "bootstrap", or "wald"
    reps    = 500,
    seed    = 42,
    n_jobs  = -1,                 # use all CPU cores
)
print(result)

Methods

Method Type Description
permutation Non-parametric Randomly shuffles group labels (default)
bootstrap Non-parametric Resamples each group with replacement
wald Parametric Chi-squared test using block-diagonal VCV

Parameters

Parameter Type Default Description
df pd.DataFrame — Dataset with a 0/1 group column
group str — Name of the grouping variable
formula str — PyFixest formula, e.g. "y ~ x1 + x2 | fe"
vcov str | dict "iid" Variance-covariance type
method str "permutation" Test method
reps int 500 Resampling iterations (ignored for Wald)
seed int | None 42 Master random seed
n_jobs int 1 Parallel workers (-1 = all cores)
verbose bool True Print progress bar and results table

Returns

pd.DataFrame indexed by variable name with columns:

  • b_group0, b_group1 — estimated coefficients per group
  • diff — coefficient difference (b0 − b1)
  • stat — test statistic (frequency count or chi-squared)
  • p_value — two-sided p-value
  • se_diff — standard error of the difference (Wald only)
  • valid_reps — successful resampling iterations (resampling only)

Dependencies

  • pyfixest
  • pandas, numpy, scipy, joblib, tqdm

License

MIT

Metadata

Release files for pybdiff 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pybdiff 0.1.0
File Size Uploaded
pybdiff-0.1.0.tar.gz 9.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pybdiff 0.1.0
File Interpreter ABI Platform
pybdiff-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 19.4 kB

Release files / pybdiff-0.1.0.tar.gz

Download URL pybdiff-0.1.0.tar.gz
Size 9.1 kB
Tags Source
SHA-256 checksum
How to use checksums
46e58d638560d365a01803d8a35a568e4f5dcb7ec1ed3e3982a1c3351c9ac145
BLAKE2b-256 checksum
How to use checksums
051b277fe7eda9b29baf7d7bf85b7839cb918c73db10a953a1399eab967b9101
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 14, 2026.

Transparency log

Release files / pybdiff-0.1.0-py3-none-any.whl

Download URL pybdiff-0.1.0-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5f107703ec375cfbf6e1a927aa7ad6046ad3508cb720a901671e3695f21f17a9
BLAKE2b-256 checksum
How to use checksums
a5e9d8480528589ff920302945b67692b408f127ce5be4c811a925bc5eb89739
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 14, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page