generate_blp_panel#
- pymc_marketing.customer_choice.synthetic_data.generate_blp_panel(*, T=50, J=4, K=2, L=2, R_geo=1, true_alpha=-2.0, true_beta=None, sigma_alpha=0.5, sigma_beta=None, instrument_strength=0.7, price_xi_corr=0.6, xi_sigma=0.3, xi_product_sigma=0.5, sigma_eta=1.0, market_size=5000, n_dgp_draws=5000, region_heterogeneity=0.0, return_truth=False, random_seed=None)[source]#
Generate a synthetic BLP-style aggregate-share panel.
Produces a long-format DataFrame suitable for fitting
pymc_marketing.customer_choice.BayesianBLP(and for unit tests of the same), together with — whenreturn_truth=True— the latent parameters that generated it. The data-generating process explicitly induces correlation between the price residualη_jtand the structural errorξ_jt(controlled byprice_xi_corr), so that no-IV fits exhibit the expected endogeneity bias on the price coefficient and IV fits can be shown to recover it.- Parameters:
T (
int) – Number of periods per region.J (
int) – Number of inside products. An outside good (row label"outside") is added on top.K (
int) – Number of product characteristicsx_jt.L (
int) – Number of instrumentsz_jt.R_geo (
int) – Number of regions. Defaults to 1; set>1together withregion_heterogeneity > 0to test hierarchical pooling.true_alpha (
float) – Population-level price coefficient (should be negative).true_beta (
ndarray|None) – Population-level characteristic coefficients, shape(K,). Defaults to a vector of ones.sigma_alpha (
float) – Across-consumer SD of the price coefficient.sigma_beta (
ndarray|None) – Across-consumer SD of each characteristic coefficient, shape(K,). Zero entries indicate no heterogeneity on that characteristic. Defaults to all zeros (heterogeneity only on price).instrument_strength (
float) – Magnitude of the first-stage instrument loadingπ_z = instrument_strength / sqrt(L). Set small (e.g. 0.1) to simulate weak instruments.price_xi_corr (
float) – CorrelationCor(η_jt, ξ̃_jt)of the joint price-residual / structural-error draws. Drives the endogeneity bias.xi_sigma (
float) – SD of the time-varying partξ̃_jt.xi_product_sigma (
float) – SD of the product fixed effectξ_j.sigma_eta (
float) – SD of the price first-stage residualη_jt.market_size (
int) – Total category volume per market. Used both to scale the Multinomial draws of observed shares and as thencolumn on the returned panel.n_dgp_draws (
int) – Number of QMC draws used to compute the true mixed-logit shares. Should be much larger than the number of draws the model itself uses so that the DGP is essentially exact.region_heterogeneity (
float) – Across-region SD applied toα_randβ_r. Zero (default) produces homogeneous regions; positive values produce heterogeneous ones.return_truth (
bool) – IfTrue, return(df, truth_dict); otherwise returndf.random_seed (
Generator|int|None) – Seed ornp.random.Generator.
- Returns:
df (
pd.DataFrame) – Long-format panel with columns["region", "market", "period", "product", "share", "n", "price", "x_0", ..., "x_{K-1}", "z_0", ..., "z_{L-1}"]. The outside good appears once per market withpriceand all characteristics / instruments set to zero.marketis a global integer;periodis the integer time index within a region (0..T-1);regionis a string label. Passtime_col="period"topymc_marketing.customer_choice.BayesianBLPto make the time dimension first-class for counterfactuals.truth (
dict, optional) – Returned only whenreturn_truth=True. Contains the population and per-cell parameters that generated the panel — useful for recovery tests. See source for the exact keys.
Examples
Generate a small panel with strong instruments and a bias-inducing price/structural-error correlation:
from pymc_marketing.customer_choice import generate_blp_panel df, truth = generate_blp_panel( T=30, J=3, K=2, L=2, true_alpha=-2.0, price_xi_corr=0.6, random_seed=42, return_truth=True, )