*! version 1.1.0 31May2017

Title

[R] alogit postestimation -- Postestimation tools for
alogit

Description

The following standard postestimation commands are available after alogit:

Command Description

predict predictions, residuals, influence statistics, and other diagnostic measures

(2) The prediction statistics py pyc pa a u cannot be correctly
handled by margins; however, margins can be used after alogit
with predict(xb).

Syntax for predict

predict
[type]
newvar
[if] [in]
[, statistic nooffset]

statistic

Main
py unconditional probability of choosing each option

pyc probability of choosing each option given all are considered

pa probability of paying attention to each good

a fitted latent attention variable

u fitted utility level

p0 P(empty choice set) for each individual

mp0 Average P(empty choice set) (for DSC, average P(inattention))

mp1 Average P(Attention) (DSC only)

xb linear prediction

stdp standard error of the linear prediction

dydx(varname, [elasticity]) dP(Y) / dx or d log(P(Y)) / d log x

fit([b0(numlist) g0(numlist) last]) fit at custom parameter set

counterfactual([counterfactual_options]) counterfactual P(Y); see counterfactual_options

sorted notes the data is already sorted and no sorting is done.

Options for predict

Main

py unconditional probability of choosing each option

pyc probability of choosing each option given all are considered;
that is, P(Y | c) where c is a J-dimensional vector of 1s.

pa probability of paying attention to each good; that is, P(A | x, z)

u fitted utility level (also xb using eqation(#1))

a fitted latent attention variable (also xb using eqation(#2))

p0 fitted probability of paying attention to none of the goods

mp0 average probability of an empty set (for DSC, average probability of inattention) stored in scalar newvar

mp1 DSC only, average probability of attention stored in scalar newvar

xb calculates the linear prediction.

stdp calculates the standard error of the linear prediction.

dydx(varname, [elasticity]) dP(Y) / dx at x_ij, where
x is varname; if elasticity is specified then the
function outputs d log(P(Y)) / d log(x). Note that if
y = f(x) then log(y) = log(f(exp(log(x)))) so that the
elasticity is just d log(y) / d log(x) = (dy / dx) (x / f(x))

fit([b0(numlist) g0(numlist) last]) fit at custom parameter set. The
option tolerates fewer parameters than there are variables, and will
simply pad b0 and g0 with the fitted parameters until the we
have the correct number. The model will not accept more parameters than
variables, however. If last is specified, then the last parameters
are replaced as opposed to the first (i.e. pass -1 2- to vector -5 6 7-
with last gives -5 1 2- instead of -1 2 7-)

counterfactual([u_ij(varname) phi_ij(varname) GRoup(varname) DEFault(varname) CONSider(varname) checksetup])
fit P(Y) while specifying utility u_ij and attention probabilites
phi_ij. If group(varname) and one of default(varname) or consider(varname)
are not specified, e(group), e(default), or e(consider) are used.

sorted Because the underlying computations are done in Mata
or C, the data must be sorted. Observations to be used (in case an
if-condition is passed) must appear first, and then be sorted by group.
(e.g. Suppose a variable touse contains 0, 1 indicators, then the
sorting must be gsort -touse e(group); if consider(varname) is
passed instead of default(varname), sorting must be gsort -touse e(group) e(consider)).
Sorting is expensive, and for large data even checking whether the data
is sorted can take a long time. Hence the user can pre-sort the data and
then pass this option for predict to skip sorting the data. It is
specially useful if several predict statements need to be used in
succession. However, if the data is not properly sorted then there will
be errors in the computation.

Warning

Though out-of-sample predictions are possible with method(exact),
alogit may yield off results if the chosen good, default good, or
considered good(s) are excluded.

Out of sample predictions are not possible with method(importance).
This happens because method(importance) draws reps choice
sets for each group are simulated once at the starting parameters and
the same choice sets are used throughout the optimization; all the
output generated by predict uses the same choice sets.

Neither are a problem if predict uses the sample used by
alogit or a sub-sample thereof. However, if predict uses a
different subset or different data then the results will be incorrect.
Furthermore, it is not possible to make predictions for supersets of the
sample used by alogit (or larger samples) as it would require more
choice sets than were simulated.

Examples

Setup

. set seed 42

. alogit_sim, n(200) j(4 8) b0(3.8 1.5) g0(0.6 -0.1) d0(-2.3 -1.1) zs(2)

Fit (in)attentive logit regression

. alogit y x*, zvars(z*) group(ind) def(defgood) noc

Basic post-estimation fits

. predict py_exact, py

. predict py_givenc_exact, pyc

. predict pa_exact, pa

. predict attn_latent_exact, a

. predict utility_exact, u

. predict pempty_exact, p0

Derivatives and elasticities with respect to a variable

. predict dydx1_exact, dydx(x1)

. predict dydx2_exact, dydx(x2)

. predict dydz1_exact, dydx(z1)

. predict dydz2_exact, dydx(z2)

. predict dlogy_dlogx1_exact, dydx(x1, elasticity)

. predict dlogy_dlogx2_exact, dydx(x2, elasticity)

. predict dlogy_dlogz1_exact, dydx(z1, elasticity)

. predict dlogy_dlogz2_exact, dydx(z2, elasticity)

Predict at arbitrary coefficient values

. predict f_py_exact, py fit(b0(12 -2) g0(-3 4) d0(3 -4))

. predict f_py_givenc_exact, pyc fit(b0(12 -2) g0(-3 4) d0(3 -4))

. predict f_pa_exact, pa fit(b0(12 -2) g0(-3 4) d0(3 -4))

. predict f_attn_latent_exact, a fit(b0(-2) g0(-3) d0(-4))

. predict f_utility_exact, u fit(b0(-2) g0(-3) d0(-4))

. predict f_pempty_exact, p0 fit(b0(-2) g0(-3) d0(-4))

. predict f_dydx1_exact, dydx(x1) fit(b0(12 -2) g0(-3 4))

. predict f_dydx2_exact, dydx(x2) fit(b0(12 -2) g0(-3 4))

. predict f_dydz1_exact, dydx(z1) fit(b0(12 -2) g0(-3 4) d0(3 -4))

. predict f_dydz2_exact, dydx(z2) fit(b0(12 -2) g0(-3 4) d0(3 -4))

. predict f_dlogy_dlogx1_exact, dydx(x1, elasticity) fit(b0(12 -2) g0(-3 4))

. predict f_dlogy_dlogx2_exact, dydx(x2, elasticity) fit(b0(12 -2) g0(-3 4))

. predict f_dlogy_dlogz1_exact, dydx(z1, elasticity) fit(b0(12 -2) g0(-3 4) d0(3 -4))

. predict f_dlogy_dlogz2_exact, dydx(z2, elasticity) fit(b0(12 -2) g0(-3 4) d0(3 -4))

Counterfactuals (alternative utility, probability of attention)

. gen alt_u = runiform()

. gen alt_p = runiform()

. predict fit_u, u

. predict fit_p, pa

. predict fit_py, py

. predict counter_py_u, counterfactual(u_ij(alt_u) phi_ij(alt_p))

. predict counter_py_f, counterfactual(u_ij(fit_u) phi_ij(fit_p))

Setup

. set seed 42

. alogit_sim, n(200) j(4 8) b0(3.8 1.5) g0(0.6 -0.1) d0(-2.3 -1.1) zs(2) dsc

Fit (in)attentive logit regression, DSC version

. alogit y x*, zvars(z*) group(ind) def(defgood) noc model(dsc)

Basic post-estimation fits

. predict py_exact, py

. predict py_given_attention, pyc

. predict pa_default, pa

. predict attn_latent_default, a

. predict utility_exact, u

. predict inattention_default, p0

Derivatives and elasticities with respect to a variable

. predict dydx1_exact, dydx(x1)

. predict dydx2_exact, dydx(x2)

. predict dydz1_exact, dydx(z1)

. predict dydz2_exact, dydx(z2)

. predict dlogy_dlogx1_exact, dydx(x1, elasticity)

. predict dlogy_dlogx2_exact, dydx(x2, elasticity)

. predict dlogy_dlogz1_exact, dydx(z1, elasticity)

. predict dlogy_dlogz2_exact, dydx(z2, elasticity)

Predict at arbitrary coefficient values

. predict f_py_exact, py fit(b0(12 -2) g0(-3 4) d0(3 -4))

. predict f_py_given_attention, pyc fit(b0(12 -2) g0(-3 4) d0(3 -4))

. predict f_pa_default, pa fit(b0(12 -2) g0(-3 4) d0(3 -4))

. predict f_attn_latent_default, a fit(b0(-2) g0(-3) d0(-4))

. predict f_utility_exact, u fit(b0(-2) g0(-3) d0(-4))

. predict f_inattention_default, p0 fit(b0(-2) g0(-3) d0(-4))

. predict f_dydx1_exact, dydx(x1) fit(b0(12 -2) g0(-3 4))

. predict f_dydx2_exact, dydx(x2) fit(b0(12 -2) g0(-3 4))

. predict f_dydz1_exact, dydx(z1) fit(b0(12 -2) g0(-3 4) d0(3 -4))

. predict f_dydz2_exact, dydx(z2) fit(b0(12 -2) g0(-3 4) d0(3 -4))

. predict f_dlogy_dlogx1_exact, dydx(x1, elasticity) fit(b0(12 -2) g0(-3 4))

. predict f_dlogy_dlogx2_exact, dydx(x2, elasticity) fit(b0(12 -2) g0(-3 4))

. predict f_dlogy_dlogz1_exact, dydx(z1, elasticity) fit(b0(12 -2) g0(-3 4) d0(3 -4))

. predict f_dlogy_dlogz2_exact, dydx(z2, elasticity) fit(b0(12 -2) g0(-3 4) d0(3 -4))

Counterfactuals (alternative utility, probability of attention)

. gen alt_u = runiform()

. gen alt_p = runiform()

. predict fit_u, u

. predict fit_p, pa

. predict fit_py, py

. predict counter_py_u, counterfactual(u_ij(alt_u) phi_ij(alt_p))

. predict counter_py_f, counterfactual(u_ij(fit_u) phi_ij(fit_p))