*! version 1.2.1 04June2017

Title

[R] alogit -- Attentive logit regression

Syntax

alogit
depvar
[indepvars]
[if] [in]
,
{default(varname)
|
consider(varname)}
group:(varname) [options]

The default-specific consideration (DSC) model (see the description below)
can be specified via model(dsc)

Model
* group(varname) individual identifier

+ default(varname) binary variable indicating a default good per individual (i.e. per group)

+ consider(varname) binary variable indicating goods with attention probability 1

avars(varlist) use varlist instead of indepvars in attention probability estimation

zvars(varlist) include varlist in attention probability estimation

exclude(varlist) exclude varlist from attention probability estimation

noconstant don't automatically add a constant when estimating P(A)

^ algorithm(str) matrix, loop (alogit only), fast (Unix only), and faster (Unix only).

model(str) model may be alogit or dsc

Computation
b0(numlist) Starting parameters for indepvars when computing P(Y)

g0(numlist) Starting parameters for indepvars or avars when computing P(A)

d0(numlist) Starting parameters for zvars and the constant when computing P(A)

exp Estimate exp(b) instead of b.

method(str) method may be exact or importance

reps(int) number of choice sets to randomly sample with method(importance)

noprob(str) noprob may be error or drop: How to handle P(A) = 0

eval(str) d0, d1, d2, d1debug, d2debug; see mf_moptimize

Reporting
checksetup Hard stops when there is a problem with the dependent variable

debug Print starting parameters

loglik Compute log-likelihood and exit

Maximization
maximize_options control the maximization process; seldom used

* group(varname) is required.

+ One of default(varname) or consider(varname) is required.

^ algorithm(str) faster depends on OpenMP (see Checking OpenMP for more).

See [R] alogit postestimation for features available after estimation.

Description

alogit computes an (in)attentive logit model for the choice
model in Abaluck and Adams (2017). An
inattentive consumer chooses a good as a function of that good's
characteristics and the probability of paying attention to that
good. depvar indicates the consumer's choice, indepvars
are covariates that affect choice and attention, and zvars are
variables that only affect attention.

Note that in the attentive logit model, consideration sets are
probabilistic. Each alternative has some probability of not being
considered, which is estimated by the model. Hence there is a non-zero
probability of a completely empty consideration set. For the model to
be well-specified, the user should say which alternative is chosen when
the consideration set is empty. The default option is specified via
default(). If it is missing then the user must specify which goods
have a probability 1 of being considered (and thus there would never be
an empty set) via consider().

alogit stores the probability of an empty set in e(mp0)
and prints a warning to the console if it is non-negligible (when
consider() is passed, it is ignored for the purposes of computing
this probability).

Alternatively alogit can also estimate a version of the model
where the probability of attention depends solely on the default good
(henceforth DSC or dsc for default-specific consideration model). In this version the
consumer either pays attention to all goods and makes a choice or
remains inattentive and defaults to the default good.

Options

Model

group(varname) is required; it specifies an identifier variable
(numeric or string) for the matched groups.

default(varname) indicates which good to use as the default good.
There must be 1 (and only 1) default good per individual (if this is not
the case, the function will exit with error). For alogit this is
the good chosen when the consideration set is empty. For dsc this
good is chosen when the consumer is inattentive.

consider(varname) indicates which goods have probability 1 of
being considered. The model sets the probability of attention to 1 for
these goods and only computes consideration sets that include the goods
indexed by this variable. This can only be specified with alogit.

avars(varlist) are variables that affect the probability of
attention but to not affect the choice probability. By default this is
indepvars. Can be set with zvars(varlist).

zvars(varlist) are additional variables that affect the
probability of attention but to not affect the choice probability.
By default this is blank. Can be set with avars(varlist).

exclude(varlist) are variables that are not to be used in the
attention probability estimation. This is meant to be used to exclude
variables specified for the utility equation from the attention
equation, but it will supersede avars(varlist) and zvars(varlist).
However, variables specified explicitly in avars(varlist) or
zvars(varlist) will be counted by the function hen determining
whether a row has wmissing values. The console will print a warning of
the variables to be excluded are not found in the estimating equations
in the first place. Last, if the user specifies starting parameters,
they must also take care to specify the correct number of parameters
after the exclusion has taken place.

noconstant suppresses automatically adding a constant when
estimating the probability of attention P(A)

algorithm(str) specifies the algorithm to use; we recommend
against changing the default for model(dsc), but model(alogit)
may see considerable speed and stability improvements by using an
alternative algorithm.
matrix, the default, performs computations at the matrix level
where each row is a consideration set. For a large number of goods,
creating a matrix will all possible consideration sets, 2^J, is
intractable. loop has no limit on the number of goods, but Stata
is very inefficient at loops so the added stability comes at the cost
of speed. To hedge against the speed loss, on Unix systems the user can
specify fast or faster to use a single or multi-threaded
C-based Stata plugin that computes the likelihood, gradient, and
Hessian. The speed comes at the loss of portability as the plugins will
only work in Unix. Further, while fast should work on any Unix
system, faster, the multi-threaded version, additionally depends
on OpenMP (see Checking OpenMP).

model(str) model may be alogit to compute the.
(in)attentive logit model or dsc to compute the DSC variation.

Computation

b0(numlist) specifies starting parameters for indepvars when
computing P(Y)

g0(numlist) specifies starting parameters for indepvars or
avars(varlist) when computing P(A)

d0(numlist) specifies starting parameters for zvars(varlist) when computing P(A); if you want to specify a starting
parameter for the constant it must be done trough d0 even if zvars(varlist) is not specified.

exp Specifies alogit should estimate exp(b) instead of b. If
the user passes starting parameters, they must b and not exp(b).
However, for the post-estimation any parameters passed via fit()
must be exp(b).

method(str) method may be exact to compute the
likelihood by iterating over all possible 2^J choice sets, or
importance in order to sample reps choice sets and compute
the likelihood using an importance sampler to weight the estimated
P(Y). For this latter method we sample once and then vary the choice
sets alongside the parameters (i.e. we sample a set of random uniform
variables once, and through the optimization the choice sets will be
given by phi = exp(xg + zd) / (1 + exp(xg + zd)) > u0, where g and d
change but u0 is fixed)

reps(int) are the number of choice sets to draw when using
method(importance); defaults to 100.

noprob(str) specifies how to handle attention probabilities P(A) = 0
with method(importance): error gives an error message and exits;
drop drops them from the likelihood. Defaults is error.

eval(str) d0, d1, d2, d1debug, d2debug; see mf_moptimize

Reporting

loglik Compute log-likelihood, print to log, and exit. The results
are available in -e(loglik)-.

debug prints the log likelihood at each function call (it also
prints the starting parameters).

checksetup Hard stops when there is a problem detected with the
dependent variable; namely it should be 0/1 and specify a single choice
per individual

Maximization

maximize_options:
difficult,
technique(maximize##algorithm_spec:algorithm_spec),
iterate(#), [no]log, trace,
gradient, showstep,
hessian,
showtolerance,
tolerance(#),
ltolerance(#),
norescale(#),
nrtolerance(#), and
nonrtolerance; see [R] maximize. These options are seldom used.

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

. alogit y x*, avars(x1 z1) group(ind) def(defgood) noc

Get the log-likelihood at the starting parameters

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

The starting parameters can be manually set

. alogit y x*, zvars(z*) group(ind) loglik def(defgood) b0(12 -2) g0(-3 4) d0(21 3 0)

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*, group(ind) def(defgood) model(dsc)

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

. alogit y x*, avars(x1 z1) group(ind) def(defgood) noc model(dsc)

Stored results

alogit stores the following in e():

Scalars

e(N) number of observations

e(ic) number of iterations

e(k) number of parameters

e(k_eq) number of equations

e(k_dv) number of dependent variables

e(mp0) Average P(empty choice set) (for DSC, P(Inattention))

e(mp1) Average P(Attention) (DSC only)

e(rank) rank of e(V)

e(converged) 1 if converged, 0 otherwise

e(rc) return code

e(loglik0) log-likelihood at starting parameters

e(loglik) log-likelihood at converged parameters

Macros

e(model) alogit or dsc.

e(method) optimization method: importance or exact

e(algorithm) algorithm used: matrix, loop, fast, faster.

e(group) name of group() variable

e(default) name of default() variable, if specified

e(consider) name of consider() variable, if specified

e(indepvars) utility variables

e(avars) attention variables

e(afit) loglik if it was requested; full otherwise.

e(predict) program used to implement predict

e(cmd) alogit

e(opt) type of optimization

e(predict) program used to implement predict

e(user) name of likelihood-evaluator program

e(ml_method) type of ml method

e(technique) maximization technique

e(which) max or min; whether optimizer is to perform
maximization or minimization

e(depvar) name of dependent variable

e(properties) b V

Matrices

e(b) coefficient vector

e(V) variance-covariance matrix of the estimators

e(b0) starting parameters

e(Hessian) Hessian matrix

e(ilog) iteration log (up to 20 iterations)

e(gradient) gradient vector

Functions

e(sample) marks estimation sample

Checking OpenMP

algorithm(faster) depends on OpenMP for multithreading (since
operations run in parallel, the speed gains can be very significant).
While this is a very common library on Unix, you can check the plugin
will find it by running, from a shell,

$ ldconfig -p | grep libgomp

$ echo $LD_LIBRARY_PATH

The first command will print the path to libgomp.so (or
libgomp.so.1), which is the relevant file. The second will print
the paths where your system looks for such libraries. If the path to
libgomp.so is not in LD_LIBRARY_PATH, run (in bash or zsh)

$ export LD_LIBRARY_PATH=/path/to/libgomp:$LD_LIBRARY_PATH

where /path/to/libgomp is the folder containing libgomp.so. In case
your shell is csh or tcsh, run

$ setenv LD_LIBRARY_PATH /path/to/libgomp:$LD_LIBRARY_PATH

To make this change permanent, add to your ~/.bashrc or ~/.zshrc

if [[ ! "$LD_LIBRARY_PATH" == */path/to/libgomp* ]]; then
export LD_LIBRARY_PATH=/path/to/libgomp:$LD_LIBRARY_PATH
fi

or your ~/.cshrc or ~/.tcshrc

if !($?LD_LIBRARY_PATH) then
setenv LD_LIBRARY_PATH /path/to/libgomp
else
if !($LD_LIBRARY_PATH:q =~ */path/to/libgomp*) then
setenv LD_LIBRARY_PATH /path/to/libgomp:$LD_LIBRARY_PATH
endif
endif

One last note: If you are working on a remote server, there is a
chance the snippet will not work if your system administrator sets
LD_LIBRARY_PATH after your ~/.*rc files are processed. In this
case, append the above snippet to ~/.profile if using bash or
zsh and ~/.login if using csh or tcsh.

References

Abaluck, J. and Adams, A. 2017. What do consumers consider before they choose? Identification from asymmetric demand responses. Working paper.