Skip to main content

BLP demand estimation with Python 3

Project description

An overview of the model, examples, references, and other documentation can be found on Read the Docs.

PyBLP is a Python 3 implementation of routines for estimating the demand for differentiated products with BLP-type random coefficients logit models. This package was created by Jeff Gortmaker in collaboration with Chris Conlon.

Development of the package has been guided by the work of many researchers and practitioners. For a full list of references, including the original work of Berry, Levinsohn, and Pakes (1995), refer to the references section of the documentation.

Citation

If you use PyBLP in your research, we ask that you also cite Conlon and Gortmaker (2020), which describes the advances implemented in the package.

@article{PyBLP,
    author={Conlon, Christopher and Gortmaker, Jeff},
    title={Best practices for differentiated products demand estimation with {PyBLP}},
    journal={RAND Journal of Economics},
    volume={51},
    number={4},
    pages={1108-1161},
    year={2020}
}

If you use micro moments with PyBLP, we ask that you also cite Conlon and Gortmaker (2025), which describes the standardized framework implemented by PyBLP for incorporating micro data into BLP-style estimation.

@article{MicroPyBLP,
    author={Conlon, Christopher and Gortmaker, Jeff},
    title={Incorporating micro data into differentiated products demand estimation with {PyBLP}},
    journal={Journal of Econometrics},
    pages={105926},
    year={2025}
}

Installation

The PyBLP package has been tested on Python versions 3.6 through 3.9. The SciPy instructions for installing related packages is a good guide for how to install a scientific Python environment. A good choice is the Anaconda Distribution, since it comes packaged with the following PyBLP dependencies: NumPy, SciPy, SymPy, and Patsy. For absorption of high dimension fixed effects, PyBLP also depends on its companion package PyHDFE, which will be installed when PyBLP is installed.

However, PyBLP may not work with old versions of its dependencies. You can update PyBLP’s Anaconda dependencies with:

conda update numpy scipy sympy patsy

You can update PyHDFE with:

pip install --upgrade pyhdfe

You can install the current release of PyBLP with pip:

pip install pyblp

You can upgrade to a newer release with the --upgrade flag:

pip install --upgrade pyblp

If you lack permissions, you can install PyBLP in your user directory with the --user flag:

pip install --user pyblp

Alternatively, you can download a wheel or source archive from PyPI. You can find the latest development code on GitHub and the latest development documentation here.

Other Languages

Once installed, PyBLP can be incorporated into projects written in many other languages with the help of various tools that enable interoperability with Python.

For example, the reticulate package makes interacting with PyBLP in R straightforward (when supported, Python objects can be converted to their R counterparts with the py_to_r function, which needs to be used manually because we set convert=FALSE to get rid of errors about trying to automatically convert unsupported objects):

library(reticulate)
pyblp <- import("pyblp", convert=FALSE)
pyblp$options$flush_output <- TRUE

Similarly, PyCall can be used to incorporate PyBLP into a Julia workflow:

using PyCall
pyblp = pyimport("pyblp")

The py command serves a similar purpose in MATLAB:

py.pyblp

Features

  • R-style formula interface

  • Bertrand-Nash supply-side moments

  • Multiple equation GMM

  • Demographic interactions

  • Product-specific demographics

  • Consumer-specific product availability

  • Flexible micro moments that can match statistics based on survey data

  • Support for micro moments based on second choice data

  • Support for optimal micro moments that match micro data scores

  • Fixed effect absorption

  • Nonlinear functions of product characteristics

  • Concentrating out linear parameters

  • Flexible random coefficient distributions

  • Parameter bounds and constraints

  • Random coefficients nested logit (RCNL)

  • Approximation to the pure characteristics model

  • Varying nesting parameters across groups

  • Logit and nested logit benchmarks

  • Classic BLP instruments

  • Differentiation instruments

  • Optimal instruments

  • Covariance restrictions

  • Adjustments for simulation error

  • Tests of overidentifying and model restrictions

  • Parametric boostrapping post-estimation outputs

  • Elasticities and diversion ratios

  • Marginal costs and markups

  • Passthrough calculations

  • Profits and consumer surplus

  • Newton and fixed point methods for computing pricing equilibria

  • Merger simulation

  • Custom counterfactual simulation

  • Synthetic data construction

  • SciPy or Artleys Knitro optimization

  • Fixed point acceleration

  • Monte Carlo, quasi-random sequences, quadrature, and sparse grids

  • Importance sampling

  • Custom optimization and iteration routines

  • Robust and clustered errors

  • Linear or log-linear marginal costs

  • Partial ownership matrices

  • Analytic gradients

  • Finite difference Hessians

  • Market-by-market parallelization

  • Extended floating point precision

  • Robust error handling

Bugs and Requests

Please use the GitHub issue tracker to submit bugs or to request features.

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

pyblp-1.1.2.tar.gz (2.3 MB view details)

Uploaded Source

Built Distribution

pyblp-1.1.2-py3-none-any.whl (2.0 MB view details)

Uploaded Python 3

File details

Details for the file pyblp-1.1.2.tar.gz.

File metadata

  • Download URL: pyblp-1.1.2.tar.gz
  • Upload date:
  • Size: 2.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.10.0 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/1.0.0 urllib3/1.26.20 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.13

File hashes

Hashes for pyblp-1.1.2.tar.gz
Algorithm Hash digest
SHA256 1f593e2453381a6d427af0f51a4718bfeca32631c3cd71ecc68583c0249dcd51
MD5 4e4f564eedf4f194132553f0aea6d044
BLAKE2b-256 d3ce36824f34e40f66a91295717b02139d387e846404bca951288a29d397ab1d

See more details on using hashes here.

File details

Details for the file pyblp-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: pyblp-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.10.0 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/1.0.0 urllib3/1.26.20 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.13

File hashes

Hashes for pyblp-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 da56e235b108544b87a37e989a07733a59985f1803d59c4107ef2ed6e67199fb
MD5 abb514004de10880b4c8c96e544e0aa0
BLAKE2b-256 13fa6094a2672482bb7a176d0d3dad5b8a095299e2127b5f2e029fb250db3cf3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page