# pyblp.DiversionCovarianceMoment¶

class pyblp.DiversionCovarianceMoment(X2_index1, X2_index2, values, market_ids=None)

Configuration for micro moments that match covariances between product characteristics of first and second choices.

For example, survey data can sometimes be used to compute the sample covariance between a product characteristic $$x_{jt}^{(1)}$$ of an agent’s first choice $$j$$ and either the same or a different product characteristic $$x_{kt}^{(2)}$$ of the agent’s second choice $$k$$ if $$j$$ were removed from the choice set, amongst those agents whose first and second choices are both inside goods. 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}(z_{it}^{(1)}, z_{it}^{(2)})$

where conditional on purchasing inside goods, the expected values of $$x_{jt}^{(1)}$$ and $$x_{kt}^{(2)}$$ for agent $$i$$ are

(2)$z_{it}^{(1)} = \sum_{j \in J_t} x_{jt}^{(1)} s_{ij(-0)t}, \quad z_{it}^{(2)} = \sum_{j, k \in J_t} x_{kt}^{(2)} s_{ik(-0,j)t} s_{ij(-0)t}$

where $$s_{ij(-0)t}$$ is the probability of choosing $$j$$ when the outside option is removed from the choice set and $$s_{ik(-0,j)t}$$ is the probability of choosing $$k$$ when both the outside option and $$j$$ are 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_index1 (int) – Column index of $$x_{jt}^{(1)}$$ in the matrix of demand-side nonlinear product characteristics, $$X_2$$. This should be between zero and $$K_2 - 1$$, inclusive.

• X2_index2 (int) – Column index of $$x_{kt}^{(2)}$$ in the matrix of demand-side nonlinear product characteristics, $$X_2$$. This should be between zero and $$K_2 - 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