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 groupdiff— coefficient difference (b0 − b1)stat— test statistic (frequency count or chi-squared)p_value— two-sided p-valuese_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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
46e58d638560d365a01803d8a35a568e4f5dcb7ec1ed3e3982a1c3351c9ac145
|
|
| MD5 |
09350b522b14aaca8a768d2f029cb9a2
|
|
| BLAKE2b-256 |
051b277fe7eda9b29baf7d7bf85b7839cb918c73db10a953a1399eab967b9101
|
Provenance
The following attestation bundles were made for pybdiff-0.1.0.tar.gz:
Publisher:
publish.yml on luzhiyu-econ/pybdiff
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pybdiff-0.1.0.tar.gz -
Subject digest:
46e58d638560d365a01803d8a35a568e4f5dcb7ec1ed3e3982a1c3351c9ac145 - Sigstore transparency entry: 1293393379
- Sigstore integration time:
-
Permalink:
luzhiyu-econ/pybdiff@24924b1388b04d3f3bf3788fbdc5e5e681fee975 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/luzhiyu-econ
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@24924b1388b04d3f3bf3788fbdc5e5e681fee975 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f107703ec375cfbf6e1a927aa7ad6046ad3508cb720a901671e3695f21f17a9
|
|
| MD5 |
8585763b37a5e0cf174b6e5533de0cac
|
|
| BLAKE2b-256 |
a5e9d8480528589ff920302945b67692b408f127ce5be4c811a925bc5eb89739
|
Provenance
The following attestation bundles were made for pybdiff-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on luzhiyu-econ/pybdiff
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pybdiff-0.1.0-py3-none-any.whl -
Subject digest:
5f107703ec375cfbf6e1a927aa7ad6046ad3508cb720a901671e3695f21f17a9 - Sigstore transparency entry: 1293393422
- Sigstore integration time:
-
Permalink:
luzhiyu-econ/pybdiff@24924b1388b04d3f3bf3788fbdc5e5e681fee975 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/luzhiyu-econ
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@24924b1388b04d3f3bf3788fbdc5e5e681fee975 -
Trigger Event:
push
-
Statement type: