help bayesmlogit

Title

bayesmlogit -- Bayesian mixed logit model

Syntax

bayesmlogit
depvar
[indepvars] [if] [in] ,
group(varname)
identifier(varname)
rand(varlist)
[draws(#)
drawsrandom(#)
drawsfixed(#)
burn(#)
thin(#)
araterandom(#)
aratefixed(#)
samplerfixed(string)
samplerrandom(string)
dampparmfixed(#)
dampparmrandom(#)
from(rowvector)
fromvariance(matrix)
jumble
noisy
saving(filename)
replace
]

Description

bayesmlogit can be used to "fit" mixed logit models using Bayesian methods - more precisely bayesmlogit
produces draws from the posterior parameter distribution, and then presents summary and other statistics describing the
results of the drawing. Detailed analysis of the draws is by and large left to the discretion of the user.

Implementation of bayesmlogit
follows Train (2009, chapter 12), and details of how the algorithm works are described in Baker (2013).
A diffuse prior for the mean values of the random coefficients is assumed,
and the prior distribution on the covariance matrix of random coefficients is taken to be an identity inverse Wishart.
bayesmlogit employs the Mata routines amcmc (if not installed search online)
for adaptive Markov chain Monte Carlo sampling
from the posterior distribution of individual level coefficients and fixed coefficients. The data setup for bayesmlogit
is the same as for clogit. Much of the syntax follows that used by Hole(2008) in development of the command mixlogit.

Syntax

group(varname) is required and specifies a numeric identifier variable
for choice occasions.

identifier(varname) is required and identifies coefficient sets; those observations for which a set of coefficients apply.
Thus, in a situation in which a person is observed
making choices over multiple occasions, one would use group(varname) to specify the choice occasions, while
identifier(varname) would identify the person.

rand(varlist) is required and specifies independent variables with random coefficients. The
variables immediately following the dependent variable in the syntax are
considered to have fixed coefficients (see the examples below). While a model can be run without any independent variables with
fixed coefficients, at least one random-coefficient independent variable is required for bayesmlogit to work.

Options

draws(#) specifies the number of draws that are to be taken from the posterior distribution of the parameters. The default is 1000.

drawsrandom(#) is an advanced option. The drawing algorithm treats each set of random coefficients as a Gibbs step in sampling from the joint posterior
distribution of parameters, and in difficult, large-dimensional problems
it might be desirable to let individual Gibbs steps run for more than one draw to achieve better mixing and convergence of the
algorithm.

drawsfixed(#) is a more advanced option. The drawing algorithm treats fixed coefficients as a Gibbs step in sampling from the joint posterior
distribution of parameters, and in difficult, large-dimensional problems it might be desirable to let this step in Gibbs sampling run for more than
a single draw. The default is 1.

burn(#) specifies the length of the burn-in period; the first # draws are discarded upon completion
of the algorithm and before further results
are computed.

thin(#) specifies that only every #th draw is to be retained, so if thin(3) is specified, only every third draw is retained.
This option is designed to help ease autocorrelation in the resulting draws, as is the option jumble, which randomly mixes draws.
Both options may be applied.

araterandom(#) specifies the desired acceptance rate for random coefficients, and should be a number between zero and one.
As an adaptive
acceptance-rejection method is used to
sample random coefficients, by specifying the desired acceptance rate, the user has some control over adaptation
of the algorithm to the problem. The default is .234.

aratefixed(#) specifies the desired acceptance rate for fixed coefficients, and works in the same fashion as araterrandom(#).

samplerrandom(string) specifies the type of sampler that is to be used when random parameters are drawn. It may be set to either
global or mwg. The default is global, which means that proposed changes
to random parameters are drawn all at once; if mwg - an acronym for "metropolis within Gibbs" - is instead chosen,
each random parameter is drawn separately as an independent
step conditional on other random parameters in a nested Gibbs step. The default is global, but
mwg might be useful in situations in which initial values are poorly scaled. The workings of these options are described in greater detail
in Baker (2013).

samplerfixed(string) specifies the type of sampler that is used when fixed parameters are drawn. Options are exactly as those
described under samplerrandom(string).

dampparmrandom(#) is a parameter that controls how aggressively the proposal distribution(s) for random parameters is adapted
as drawing continues. If set close to one, adaptation is agressive in its early phases in trying to achieve the acceptance rate specified
in araterandom(#). If set closer to zero, adaptation is more gradual.

dampparmfixed(#) works exactly as option dampparmrandom(#) but applied to drawing fixed parameters.

from(string) specifies a row vector of starting values for all parameters in order.
In the even that these are not specified, starting
values are obtained via estimation of a conditional logit model via clogit.

fromVariance(string) specifies a matrix of starting values for the random parameters.

saving(string) specifies a location to store the draws from the distribution. The file will contain just the draws after any burn in period
or thinning of values is applied. replace specifies that an existing file is to be overwritten, while append specifies that
an existing file is to be appended, which might be useful if multiple runs need to be combined.

noisy specifies that a dot be produced every time a complete pass through the algorithm is finished. After 50 iterations, a "function value"
ln_fc(p) will be produced, which gives the joint log of the value of the posterior choice probabilities evaluated at the latest parameters. While
not an objective function per se, the author has found that drift in the value of this function indicates that the algorithm has not yet converged
or other problems.

Examples

A single random coefficient, one decision per group. The random parameter rate is set to .4 and a total of 4000 draws are taken.
The first 1000 draws are dropped, and then every fifth draw is retained. Draws are saved as choice_draws.dta:

. webuse choice, clear

. bayesmlogit choice, rand(dealer) group(id) id(id) draws(4000) burn(1000) thin(5) arater(.4) saving(choice_draws) replace

Estimating a mixed logit model using bayesmlogit, using the methods as described in Long and Freese (2006, sec. 7.2.4). The data must first be
rendered into the correct format, which can be done using the command case2alt, which is part of the package spost9_ado; if not installed,
type net describe spost9_ado from the Stata prompt, or found online by clicking here. The example first arranges the
data, and then generates and summarizes posterior draws from a mixed logit model. The model uses bangladesh.dta, which has information on
contraceptive choice by a series of families. Coefficients of explanatory variables vary at the district level.

. webuse bangladesh, clear
(Bangladesh Fertility Survey, 1989)

. case2alt, casevars(urban age) choice(c_use) gen(choice)
(note: variable _id used since case() not specified)
(note: variable _altnum used since altnum() not specified)

choice indicated by: choice
case identifier: _id
case-specific interactions: no* yes*

. bayesmlogit choice, rand(yesXurban yesXage yes) group(_id) id(district) draws(10000) burn(5000) saving(bdesh_draws) replace

Saved results

bayesmlogit saves the following in e():

Scalars

e(N) number of observations

e(df_r) Degrees of freedom for summarizing draws (equal to number of retained draws)

e(krnd) Number of random parameters

e(kfix) Number of fixed parameters

e(draws) Number of draws

e(burn) Burn-in observations

e(thin) Thinning parameter

e(random_draws) Number of draws of each set of random parameters per pass

e(fixed_draws) Number of draws of fixed paramaters per pass

e(damper_fixed) Damping parameter - fixed parameters

e(damper_random) Damping parameter - random parameters

e(opt_arate_fixed) Desired acceptance rate - fixed parameters

e(opt_arate_random) Desired acceptance rate - random parameters

e(N_groups) Number of groups

e(N_choices) Number of choice occasions

e(arates_fa) Acceptance rate - fixed parameters

e(arates_ra) Ave. acceptance rate - random parameters

e(arates_rmax) Max. acceptance rate - random parameters

e(arates_rmin) Min. acceptance rate - random parameters

Macros

e(saving) File containing results

e(fixed_sampler) Sampler type for fixed parameters

e(random_sampler) Sampler type for random parameters

e(random) Random parameter names

e(fixed) Fixed parameter names

e(identifier) Identifer for individuals

e(group) Identifier for choice occasions

e(depvar) Dependent variable

e(indepvars) Independent variables

e(cmd) "bayesmlogit"

e(title) "Bayesian Mixed Logit Model"

e(properties) "b V"

Matrices

e(b) mean parameter values

e(V) variance-covariance matrix of parameters

e(V_init) Initial variance covariance matrix of random parameters

e(b_init) Initial mean vector of random parameters

e(arates_fixed) Row vector of acceptance rates of fixed parameters

e(arates_rand) Vector/Matrix of acceptance rates of random parameters

Functions

e(sample) marks estimation sample

Comments

The basic algorithms used in drawing are described in some detail in Baker (2013). The user might gain a fuller understanding of the options
aratefixed, araterandom, damperfixed, damperrandom, and other options controlling adaptation of the proposal distribution
from a reading of this document.

bayesmlogit requires that the package of Mata functions amcmc be installed, and also requires installation of Ben Jann's moremata
set of extended Mata functions.

Caution!!! - While summary statistics of the results of a drawing are presented in the usual Stata format,
bayesmlogit provides no guidance as to how one should actually go about selecting the number of draws, how draws should be processed,
monitoring convergence of the algorithm, or presenting and interpreting results. One would do well to consult Train (2009), and
a good source on Bayesian methods such as Gelman et. al. (2009). Fortunately, Stata provides a wealth of tools for summarizing and plotting
the results of a drawing.

Reference

Baker, M. J. 2013. Adaptive Markov chain Monte Carlo sampling and estimation in Mata. Hunter College working paper 440.

Gelman, A., J. B. Carlin, H. S. Stern, and D. B. Rubin. 2009. Bayesian data analysis, 2nd. ed. Boca Raton: Chapman and Hall.

Hole, A. R. 2007. Fitting mixed logit models by using maximum simulated likelihood. Stata Journal: 7:388-401, 1-14.

Long, J. S., and J. Freese. 2006. Regression models for categorical dependent variables using Stata. College Station: Stata Press.

Train, K. E. 2009. Discrete Choice Methods with Simulation.
Cambridge: Cambridge University Press.

Author

This command was written by Matthew J. Baker (matthew.baker@hunter.cuny.edu),
Hunter College and The Graduate Center, CUNY. Comments, criticisms, and suggestions for improvement are welcome.

Also see

Manual: [R] clogit

Online: spost9_ado, amcmc, moremata

Other: (if installed)
mf_amcmc, moremata