pyblp.MicroMoment

class pyblp.MicroMoment(name, value, parts, compute_value=None, compute_gradient=None)

Configuration for a micro moment \(m\).

Each micro moment \(m\) matches a function \(f_m(v)\) of one or more micro moment parts \(v\) in (34). For example, \(f_m(v) = v_p\) with \(v_{pijt} = y_{it} x_{jt}\) matches the mean of an interaction between some demographic \(y_{it}\) and some product characteristic \(x_{jt}\).

Non-simple averages such as conditional means, covariances, correlations, or regression coefficients can be matched by choosing an appropriate function \(f_m\). For example, \(f_m(v) = v_1 / v_2\) with \(v_{1ijt} = y_{it}x_{jt}1\{j \neq 0\}\) and \(v_{2ijt} = 1\{j \neq 0\}\) matches the conditional mean of an interaction between \(y_{it}\) and \(x_{jt}\) among those who do not choose the outside option \(j = 0\).

See Conlon and Gortmaker (2023) for a more in-depth discussion of the standardized framework used by PyBLP for incorporating micro data into BLP-style estimation.

Parameters
  • name (str) – The unique name of the micro moment, which will be used for outputting information about micro moments.

  • value (float) – The observed value \(f_m(\bar{v})\).

  • parts (MicroPart or sequence of MicroPart) – The MicroPart configurations on which \(f_m(\cdot)\) depends. If this is just a single part \(p\) and not a sequence, it is assumed that \(f_m = v_p\) so that the micro moment matches \(v_p\). If this is a sequence, both compute_value and compute_gradient need to be specified.

  • compute_value (callable, optional) –

    Function for computing the simulated micro value \(f_m(v)\) (only if parts is a sequence) of the following form:

    compute_value(part_values) --> value
    

    where part_values is the array \(v\) with as many values as there are parts and the returned value is the scalar \(f_m(v)\).

  • compute_gradient (callable, optional) –

    Function for computing the gradient of the simulated micro value with respect to its parts (only required if parts is a sequence) of the following form:

    compute_gradient(part_values) --> gradient
    

    where part_values is the array \(v\) with as many value as there are parts and the returned gradient is \(\frac{\partial f_m(v)}{\partial v}\), an array of the same shape. This is used to compute both analytic gradients and moment covariances.

Examples

Methods