Package: pyblp
An overview of the model, examples, references, and other documentation can be found onRead 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 byJeff Gortmakerin collaboration withChris 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 ofBerry, Levinsohn, and Pakes (1995), refer to thereferencessection of the documentation.CitationIf you use PyBLP in your research, we ask that you also citeConlon 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 = {The RAND Journal of Economics},
    volume = {51},
    number = {4},
    pages = {1108-1161},
    doi = {https://doi.org/10.1111/1756-2171.12352},
    url = {https://onlinelibrary.wiley.com/doi/abs/10.1111/1756-2171.12352},
    eprint = {https://onlinelibrary.wiley.com/doi/pdf/10.1111/1756-2171.12352},
    year = {2020}
}If you use PyBLP’s micro moments functionality, we ask that you also citeConlon and Gortmaker (2023), which describes the standardized framework implemented by PyBLP for incorporating micro data into BLP-style estimation.@misc{MicroPyBLP,
    author = {Conlon, Christopher and Gortmaker, Jeff},
    title = {Incorporating micro data into differentiated products demand estimation with {PyBLP}},
    note = {Working paper},
    year = {2023}
}InstallationThe PyBLP package has been tested onPythonversions 3.6 through 3.9. TheSciPy instructionsfor installing related packages is a good guide for how to install a scientific Python environment. A good choice is theAnaconda Distribution, since it comes packaged with the following PyBLP dependencies:NumPy,SciPy,SymPy, andPatsy. For absorption of high dimension fixed effects, PyBLP also depends on its companion packagePyHDFE, 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 patsyYou can update PyHDFE with:pip install --upgrade pyhdfeYou can install the current release of PyBLP withpip:pip install pyblpYou can upgrade to a newer release with the--upgradeflag:pip install --upgrade pyblpIf you lack permissions, you can install PyBLP in your user directory with the--userflag:pip install --user pyblpAlternatively, you can download a wheel or source archive fromPyPI. You can find the latest development code onGitHuband the latest development documentationhere.Other LanguagesOnce 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, thereticulatepackage makes interacting with PyBLP in R straightforward (when supported, Python objects can be converted to their R counterparts with thepy_to_rfunction, which needs to be used manually because we setconvert=FALSEto get rid of errors about trying to automatically convert unsupported objects):library(reticulate)
pyblp <- import("pyblp", convert=FALSE)
pyblp$options$flush_output <- TRUESimilarly,PyCallcan be used to incorporate PyBLP into a Julia workflow:using PyCall
pyblp = pyimport("pyblp")Thepy commandserves a similar purpose in MATLAB:py.pyblpFeaturesR-style formula interfaceBertrand-Nash supply-side momentsMultiple equation GMMDemographic interactionsProduct-specific demographicsConsumer-specific product availabilityFlexible micro moments that can match statistics based on survey dataSupport for micro moments based on second choice dataSupport for optimal micro moments that match micro data scoresFixed effect absorptionNonlinear functions of product characteristicsConcentrating out linear parametersFlexible random coefficient distributionsParameter bounds and constraintsRandom coefficients nested logit (RCNL)Approximation to the pure characteristics modelVarying nesting parameters across groupsLogit and nested logit benchmarksClassic BLP instrumentsDifferentiation instrumentsOptimal instrumentsCovariance restrictionsAdjustments for simulation errorTests of overidentifying and model restrictionsParametric boostrapping post-estimation outputsElasticities and diversion ratiosMarginal costs and markupsPassthrough calculationsProfits and consumer surplusNewton and fixed point methods for computing pricing equilibriaMerger simulationCustom counterfactual simulationSynthetic data constructionSciPy or Artleys Knitro optimizationFixed point accelerationMonte Carlo, quasi-random sequences, quadrature, and sparse gridsImportance samplingCustom optimization and iteration routinesRobust and clustered errorsLinear or log-linear marginal costsPartial ownership matricesAnalytic gradientsFinite difference HessiansMarket-by-market parallelizationExtended floating point precisionRobust error handlingBugs and RequestsPlease use theGitHub issue trackerto submit bugs or to request features.