Skip to main content

Cross-backend binscatter plots.

Project description

Dataframe agnostic binscatter plots

This package implements binscatter plots following:

Cattaneo, Crump, Farrell and Feng (2024)
"On Binscatter"
American Economic Review, 114(5), pp. 1488-1514
DOI: 10.1257/aer.20221576

  • Uses narwhals as dataframe layer binscatter.
    • Currently supports: pandas, Polars, DuckDB, Dask, and PySpark
    • All other Narwhals backends fall back to a generic quantile handler if a native path is unavailable
  • Lightweight - little dependencies
  • Uses plotly as graphics backend - because: (1) its great (2) it uses narwhals as well, minimizing dependencies
  • Pythonic alternative to the excellent binsreg package

Example

We made this noisy scatterplot:

Noisy scatterplot

This is how we make a nice binscatter plot, controlling for a set of features:

from binscatter import binscatter

p_binscatter_controls = binscatter(
    df,
    "mtr90_lag3",
    "lnpat",
    [
        "top_corp_lag3",
        "real_gdp_pc",
        "population_density",
        "rd_credit_lag3",
        "statenum",
        "year",
    ],
    num_bins=35,
)

Binscatter with controls (35 bins)

The data originates from:

Akcigit, Ufuk; Grigsby, John; Nicholas, Tom; Stantcheva, Stefanie, 2021, "Replication Data for: 'Taxation and Innovation in the 20th Century'", https://doi.org/10.7910/DVN/SR410I, Harvard Dataverse, V1

Tests

  • Run the full backend matrix, including PySpark: just test
  • Use the faster run without PySpark: just test-fast

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

binscatter-0.1.0.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

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

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: binscatter-0.1.0.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.14

File hashes

Hashes for binscatter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b27bdc2737d89a2320953ecdc31ff3b52c9a6930bbd01d2f5c05e395957db984
MD5 61de77bf25e627354436f6317b8c57b4
BLAKE2b-256 0cccf95b66e42f96177029e5bb4438cdd9d6a0d1b09ce77212ebce4459a51cd7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: binscatter-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.14

File hashes

Hashes for binscatter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c349d69441391e8f886d9da0765ddd3262ec30e2c7ac03a95f45d1b88802510f
MD5 c727766e61f30689aea6814f451a2467
BLAKE2b-256 7ff69f1e63ca07f7b65dd0da91735ab37831074a9191e15b18d2024419b6dffb

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