Code#
Below is the documentation for the Matlab (2024b) files at this GitHub directory, which provide a pretrained NNE of a consumer search model. We suggest taking a look at the guide on the home page before reading this documentation.
Description of files#
trained_nne.mat#
This file contains a structure, nne, that stores the pretrained neural net as well as some pre-defined settings, such as the prior of the search model parameter and the range of data sizes used in pretraining.
nne_estimate.m#
This is the main function that applies the pretrained NNE to your data.
result = nne_estimate(nne, Y, Xp, Xa, Xc, consumer_idx, se = false, checks = true)
Inputs:
nne: already described above, available fromtrained_nne.mat.Y: \(nJ\) by 2 matrix. The \(((i-1)J+j)\)-th row corresponds to product \(j\) for consumer \(i\). The two values in each row indicate whether the product is: (1) searched and (2) bought, respectively.Xp: a matrix with \(nJ\) rows. The \(((i-1)J+j)\)-th row contains the product attributes of product \(j\) for consumer \(i\).Xa: a matrix with \(nJ\) rows. The \(((i-1)J+j)\)-th row contains the advertising attributes of product \(j\) for consumer \(i\).Xc: a matrix with \(n\) rows. The \(i\)-th row contains the consumer attributes of consumer \(i\).consumer_idx: a column vector with \(nJ\) values. The \(((i-1)J+j)\)-th value equals \(i\).se = false: optional input. Set it to “true” to calculate bootstrap standard errors.checks = true: optional input. Set it to “false” to omit all sanity checks.
Output:
result: a table showing the parameter estimates.
moments.m#
This function computes data moments and is used by nne_estimate.m. The moments include summary
statistics as well as coefficients of reduced-form regressions. These moments are fed into the
neural net as input.
reg_logit.m#
This function runs ridge logit or multinomial-logit regressions and is used by moments.m. It
is faster than Matlab built-in regressions. The speedup is substantial during pretraining (though it is less
noticeable when applying the pretrained NNE).
reg_linear.m#
This function runs ridge linear regression and is used by moments.m.
data_checks.m#
This function is used by nne_estimate.m to run some basic sanity checks on data. For example,
every consumer can buy at most one option; every consumer should conduct at least one (free) search.
Note: The following files are used in pretraining, but not required to apply the pretrained NNE. We provide them for reference purposes.
curve.mat#
This file contains a lookup table for the relation between search cost and reservation utility. This relation is used for computing optimal consumer choices in the sequential search model.
search_model.m#
This function codes the search model.
Y = search_model(par, curve, Xp, Xa, Xc, consumer_idx)
Inputs:
par: the search model parameter vector.curve: a lookup table described above, available fromcurve.mat.Xp,Xa,Xc, andconsumer_idx: data as described before.
Outputs:
Y: searches and purchases, as described before.
winsorize.m#
This function winsorizes data at 0.5 and 99.5 percentiles. We suggest using it on your data before
applying the pretrained NNE. For example, Xp = winsorize(Xp).