frac_blp
FRAC for macro-BLP (Salanie-Wolak).
- Github repository: https://github.com/bsalanie/frac-blp/
- Documentation https://bsalanie.github.io/frac-blp/
Overview
The package estimates a second-order approximation to the macro BLP model with random coefficients using the FRAC method of Salanie and Wolak.
At this early stage, the package only implements the basic version of the model without demographics. The random coefficients are assumed to be independently distributed.
The user should be familiar with the macro BLP model (Berry, Levinsohn, and Pakes, 1995). We use very similar notation to that of Conlon and Gortmaker in their pyblp package.
inputs
The user must provide the inputs in a TOML configuration file. Here is an example:
[data]
source = "real" # indicates that it is data from observations
file = "data/simulated_data.csv" # must be .csv or .parquet
shares = "shares" # the name of the column that contains the market shares $S_{jt}$
# the names of the columns that have the instrumments. A constant is added automatically; do not list one
instruments = ["z_1", "z_2", "z_3"]
#
X1_exo = ["constant"]
X1_endo = ["x_1", "x_2", "x_3"]
X2_exo = [] # must be a subset of X1_exo
X2_endo = ["x_1", "x_2"] # must be a subset of X1_endo
T = 500 # number of markets
J = 10 # number of products on each market
[estimation]
degree_Z = 2
# we create instruments from interactions of the `instruments` up to `degree_Z`
degree_X1 = 2 # interacted with powers of `X1_exo` up to `degree_X1`
optimal_instruments = true # if `true`, we use the optimal instruments
run_projections = true # if `true`, some information about the first stage is printed
results_file = "estimation_results.txt" # this is the default value.
The file must have one row per product and market, stacked by market (N=T * J rows, where T is the number of markets and J is the number of products per market) The observations should be ordered by market, i.e., the first J rows correspond to market 1, the next J rows to market 2, etc. The path of file is relative to that of the configuration file.
The names of the variables must correspond to column names in the header of file.
The program will construct the following Numpy matrices from the data, using the column names indicated in the configuration file:
X1_exo, the matrix of exogenous variables with fixed coefficientsX1_endo, the matrix of endogenous variables with fixed coefficientsX2_exo, the matrix of exogenous variables with fixed coefficientsX1_endo, the matrix of endogenous variables with fixed coefficients.
X2_exo must be a subset of X1_exo, and X2_endo must be a subset of X1_endo (i.e., all variables with random coefficients must also have fixed coefficients). Any of these four matrices can be None if there are no variables of that type.
A constant term will not be added automatically. If one is desired, the user must include a column of ones in X1_exo, and in X2_exo if the coefficient of the constant is random.
On the other hand, a constant will be added automatically to the instruments. If degree_Z=d is provided, then all interactions of the $n_Z$ columns of Z up to degree d, plus the constant, will be used as instruments. This gives ${n_Z+d\choose d}$ instruments. If degree_X1=d' is provided, then all interactions of the $n_{1x}$ columns of X1_exo up to degree d' will also be used, on their own and multiplied by the interactions of Z up to degree d. That gives an additional $({n_Z+d\choose d}-1)\times ({n_{1x}+d^\prime\choose d^\prime}-1)+1$ instruments.
The default has degree_Z=2 and degree_X1=2; the total number of instruments then is:
$$
\frac{(n_{1x}+1)(n_{1x}+2)}{2} \times \left(\frac{(n_{Z}+1)(n_{Z}+2)}{2}-1\right).
$$
running the program
After you download the package, frac_nodemog --example will run an example that both simulates and estimates a model.
To run the estimation on your own data and configuration: create a my_data.csv (or Parquet) file; a my_model_config.toml configuration file that has data="my_data.csv", and run
frac_nodemog my_model_config.toml
outputs
The outputs are:
betas_sigmas2_est: the estimates of the mean coefficients on the variablesX1_exoandX1_endo, then the estimated variances of the coefficients onX2_exoandX2_endo, in that order.stderrs_est: the estimated standard errors of these estimates.xi_est: the estimated product effects, a vector of sizeN, ordered by market
They are saved in the text file indicated as results_file in the configuration file. If no results_file is indicated, the results are written in estimation_results.txt. Its path is relative to where the program was run.
Release notes
0.6 (November 2, 2026)
Improved the printing and created the frac_nodemog script.
0.5 (October 31, 2026)
Improved and accelerated. Uses a TOML configuration file for the parameters.
0.4 (June 1, 2026)
Added higher-order regressors (not used for estimation yet).
0.3 (November 7, 2025)
Improved interface for data input. Still no demographics.
0.2 (October 27, 2025)
Improved README.
0.1 (October 26, 2025)
First working version, no demographics.
TODO October 31, 2026
- do up to 4th order with $E(X\vert Z)$ and $E(K_l+\sum_m W_{lm} \hat{\sigma}^2_m$ and $E(T_3\vert Z)$ and $E(T_4^\kappa\vert Z)$ and $\Omega_2$. This should give estimates of all 4 moments.
- update $\Omega$ and the optimal instruments and run again (and perhaps again).
Metadata
Release files for frac-blp 0.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| frac_blp-0.6.0.tar.gz | 358.1 kB | Without provenance | Details for frac_blp-0.6.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| frac_blp-0.6.0-py3-none-any.whl | Python 3 | none | any | Details for frac_blp-0.6.0-py3-none-any.whl |
Total release size: 716.6 kB
Release files / frac_blp-0.6.0.tar.gz
| Download URL | frac_blp-0.6.0.tar.gz |
|---|---|
| Size | 358.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
675469dd1887ffab665dc4287962602ba6235c636fc397f563301faa5b75398c
|
|
BLAKE2b-256 checksum How to use checksums |
305c34d3e90cfa1b05d5623dafe72bf62931041bc5be86d1726b087733c1b8ac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / frac_blp-0.6.0-py3-none-any.whl
| Download URL | frac_blp-0.6.0-py3-none-any.whl |
|---|---|
| Size | 358.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
275bca775096afa0f1786a94d982928c2d71aa730218c351a85c082acf74e7da
|
|
BLAKE2b-256 checksum How to use checksums |
5a9c048b12c5e0fc30d128e13a5d718d6bd6c40a85ac6e8331dfafcd0ffd2b5d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for frac-blp 0.6.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.