pyblp.DemographicCovarianceMoment

class pyblp.DemographicCovarianceMoment(X2_index, demographics_index, values, market_ids=None)

Configuration for micro moments that match covariances between product characteristics and demographics.

For example, micro data can sometimes be used to compute the sample covariance between a product characteristic \(x_{jt}\) of an agent’s choice \(j\), and a demographic such as income, \(y_{it}\), amongst those agents who purchase an inside good. With the value \(\mathscr{V}_{mt}\) of this sample covariance, a micro moment \(m\) in market \(t\) can be defined by \(g_{M,mt} = \mathscr{V}_{mt} - v_{mt}\) where

(1)\[v_{mt} = \text{Cov}(y_{it}, z_{it})\]

where conditional on choosing an inside good, the expected value of \(x_{jt}\) for agent \(i\) is

(2)\[z_{it} = \sum_{j \in J_t} x_{jt}s_{ij(-0)t}\]

where \(s_{ij(-0)t} = s_{ijt} / (1 - s_{i0t})\) is the probability of \(i\) choosing \(j\) when the outside option is removed from the choice set.

Integrals of these micro moments are averaged across a set \(T_m\) of markets, which gives \(\bar{g}_{M,m}\) in (34).

Parameters
  • X2_index (int) – Column index of \(x_{jt}\) in the matrix of demand-side nonlinear product characteristics, \(X_2\). This should be between zero and \(K_2 - 1\), inclusive.

  • demographics_index (int) – Column index of the demographic \(y_{it}\) (which can be any demographic, not just income) in the matrix of agent demographics, \(d\). This should be between zero and \(D - 1\), inclusive.

  • values (float) – Values \(\mathscr{V}_{mt}\) of the statistic estimated from micro data. If a scalar is specified, then \(\mathscr{V}_{mt} = \mathscr{V}_m\) is assumed to be constant across all markets in which the moment is relevant. Otherwise, this should have as many elements as market_ids, or as the total number of markets if market_ids is None.

  • market_ids (array-like, optional) – Distinct market IDs over which the micro moments will be averaged to get \(\bar{g}_{M,m}\). These are also the only markets in which the moments will be computed. By default, the moments are computed for and averaged across all markets.

Examples

Methods