Skip to main content

Python replication of Stata's bdiff command — tests whether regression coefficients differ across two subgroups

Project description

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

Project details


Download files

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

Source Distribution

pybdiff-0.1.0.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

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

pybdiff-0.1.0-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file pybdiff-0.1.0.tar.gz.

File metadata

  • Download URL: pybdiff-0.1.0.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pybdiff-0.1.0.tar.gz
Algorithm Hash digest
SHA256 46e58d638560d365a01803d8a35a568e4f5dcb7ec1ed3e3982a1c3351c9ac145
MD5 09350b522b14aaca8a768d2f029cb9a2
BLAKE2b-256 051b277fe7eda9b29baf7d7bf85b7839cb918c73db10a953a1399eab967b9101

See more details on using hashes here.

Provenance

The following attestation bundles were made for pybdiff-0.1.0.tar.gz:

Publisher: publish.yml on luzhiyu-econ/pybdiff

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pybdiff-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pybdiff-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pybdiff-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5f107703ec375cfbf6e1a927aa7ad6046ad3508cb720a901671e3695f21f17a9
MD5 8585763b37a5e0cf174b6e5533de0cac
BLAKE2b-256 a5e9d8480528589ff920302945b67692b408f127ce5be4c811a925bc5eb89739

See more details on using hashes here.

Provenance

The following attestation bundles were made for pybdiff-0.1.0-py3-none-any.whl:

Publisher: publish.yml on luzhiyu-econ/pybdiff

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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