------------------------------------------------------------------------------- help formcmcmixed-------------------------------------------------------------------------------

Syntax

mcmcmixeddepvar[fe_equation] [||re_equation],saving(filename)d0(#)delta0(name)[options]where the syntax of

fe_equationis[

indepvars] [if] [in] [weight] [,noconstant]and the syntax of

re_equationis

levelvarlist:[varlist] [,noconstant]

optionsDescription ------------------------------------------------------------------------- Modeld0(#)prior variance of regression errordelta0(name)scalar or matrix specifying prior variance of random effects; relevant only ifre_equationis specifiednoconstantsuppress constant termResults

saving(filename)filename where results should be storedreplaceoverwrite existingfilenameMarkov chain

iterate(#)number of iterations in chain; default isiterate(100)seed(#)random number generator seed; default isseed(12345)nologsuppress iteration log -------------------------------------------------------------------------

aweights andfweights are allowed; see weight, and see methods for an important note on howaweights are interpreted.

Description

mcmcmixeduses Markov chain Monte Carlo (MCMC) to sample from the posterior distribution of a normal linear mixed model. Ifre_equationis not specified,mcmcmixedis identical tomcmcreg, which estimates a normal linear regression. Ifre_equationis specified, the model allows the coefficients to vary across groups defined bylevelvarlist.

mcmcmixedproduces a file of draws from the posterior distribution of the model parameters. Each observation in the file corresponds to an iteration of the sampler; each variable represents a different scalar parameter. These variables are named as follows:

beta_*Coefficient on independent variable *.beta__consIntercept (omitted ifnoconstantis specified infe_equation).sigma2Variance of regression error.theta`i'_*Coefficient on independent variable * for group `i' oflevelvarlist.theta`i'__consIntercept for group `i' oflevelvarlist(omitted ifnoconstantis specified inre_equation).Sigma_`j'_`j'Variance across groups of the `j'th coefficient inre_equation(where the constant, if included, is the final coefficient).Sigma_`j'_`k'Covariance across groups of the `j'th and `k'th coefficients inre_equation.The variable

iterin the output file keeps track of iterations;iter=0 is the initial condition used to start the chain.Right-hand-side variables can appear in

fe_equation,re_equationor both. If a variable appears only infe_equation, it has the same coefficient for all groups, and this coefficient is reported inbeta_*. If a variable appears in bothfe_equationandre_equation, it has a different coefficient for each group; the mean across groups is reported inbeta_*, and the group-specific deviation from the mean is reported intheta`i'_*. If a variable appears only inre_equation, it has a different coefficient for each group, reported intheta`i'_*; the mean across groups is assumed be zero.The group indexes

`i'intheta`i'_*are obtained fromegeni=group(levelvarlist).

Options+-------+ ----+ Model +------------------------------------------------------------

d0(#)sets the prior variance of the regression errors. Because results are potentially sensitive to this prior, you are required to specify it yourself; there is no default value.

delta0(name)sets the prior variance-covariance matrix of the group-specific coefficients. Because results are potentially sensitive to this prior, you are required to specify it yourself; there is no default value.delta0must be the name of a scalar, vector or matrix containing the prior. Ifdelta0is a scalar, the prior isdelta0*I(Nz), whereNzis the number of group-specific coefficients (including the intercept, unlessnoconstantis specified inre_equation);delta0must be positive. Ifdelta0is anNzx1 or 1xNzvector, the prior isdiag(delta0); all elements ofdelta0must be positive. Ifdelta0is anNzxNzmatrix, the prior isdelta0; this matrix must be symmetric and positive definite. It is an error fordelta0to be anything except a positive scalar; anNzx1 or 1xNzvector containing only positive numbers; or anNzxNzsymmetric, positive-definite matrix. The order of elements indelta0is the same as the order of thevarlistspecified inre_equation, with the intercept last if there is an intercept.

noconstant; see[R] estimation options. Ifnoconstantis specified, there must be at least one independent variable.+---------+ ----+ Results +----------------------------------------------------------

saving(filename)designates the location where the results should be saved.

replacespecifies that you want to overwritefilenameif it already exists.+--------------+ ----+ Markov chain +-----------------------------------------------------

iterate(#)specifies how many iterations the chain should continue for.

seed(#)sets the random number generator seed. Random numbers are used to initialize the sampler; thus, multiple independent chains can be obtained by runningmcmcregwith different values ofseed.

nologsuppresses printing of an iteration log.

mcmcreguses the Gibbs sampler. Standard uninformative conjugate priors are used: The prior for the regression coefficients is uninformative, the prior for the error variancesigma^2is InverseGamma(1/2,d0/2), and the prior for the variance-covariance matrix of group-specific coefficientsSigmais InverseWishart(1+Ng,delta0), whereNgis the number of groups. See Chib (2001, algorithm 16) for a textbook exposition.The sampler is initialized with guesses for

sigma^2andSigmaobtained as follows. Letybe the dependent variable, letxbe the independent variables infe_equation, and letzbe the independent variables inre_equation. Letbetabe the estimated coefficient vector in a frequentist pooled least squares regression ofyonx. For each groupi, lettheta_ibe the posterior mean of the coefficient vector in a Bayesian least squares regression ofy-x*betaonzusing the data from groupi, where the prior fortheta_iis N(0,delta0). The initial guess for the inverse ofSigmais drawn from Wishart(1+Ng,inv(inv(delta0)+S*Ng)), whereSis the observed variance-covariance matrix of thetheta_i's. The initial guess forsigma^2is drawn from InverseGamma((1+df)/2,(d0+SSR)/2), wheredfis the number of observations (or the sum of weights if you usefweights) andSSRis the sum of squares ofy-x*beta-z*theta_i.

aweights are interpreted as scaling the variances of the regression error and all of the random effects. That is, if you specifyaweights, they apply to bothfe_equationandre_equation. A future version may provide the ability to specifyaweights separately for the two equations.

ExamplesManufacturer-specific intercepts:

. scalar mydelta0=0.01. sysuse auto. generate manuf=cond(strpos(make," ")>0,substr(make,1,strpos(make,"")-1),make). mcmcmixed mpg weight foreign || manuf:, saving(mcmcmixed_auto1.dta)d0(0.01) delta0(mydelta0). use mcmcmixed_auto1.dta, clear. list in 1/5. summarize *Manufacturer-specific intercept and manufacturer-specific coefficient on

weight, same prior variance on each manufacturer-specific parameter:

. scalar mydelta0=0.01. sysuse auto. generate manuf=cond(strpos(make," ")>0,substr(make,1,strpos(make,"")-1),make). mcmcmixed mpg weight foreign || manuf:weight,saving(mcmcmixed_auto2.dta) d0(0.01) delta0(mydelta0). use mcmcmixed_auto2.dta, clear. list in 1/5. summarize *Manufacturer-specific intercept and manufacturer-specific coefficient on

weight, different prior variance on each manufacturer-specific parameter:

. matrix mydelta0=(1,0.01). sysuse auto. generate manuf=cond(strpos(make," ")>0,substr(make,1,strpos(make,"")-1),make). mcmcmixed mpg weight foreign || manuf:weight,saving(mcmcmixed_auto3.dta) d0(0.01) delta0(mydelta0). use mcmcmixed_auto3.dta, clear. list in 1/5. summarize *When estimating models by MCMC, it is good practice to check for convergence by running multiple independent chains.

mcmcmixedwill generate different chains when run repeatedly with different values ofseed(#); see mcmcreg##examples for an example of how to run multiple chains, and see mcmcconverge, available in the SSC packagemcmcstats, for useful statistics for checking convergence once you have run multiple chains.It is also good practice to drop early iterations, before convergence was achieved, when describing the posterior distribution. See mcmcsummarize, available in the SSC package

mcmcstats, for a convenient way to describe the posterior distribution.

Saved results

mcmcmixedsaves the following ine():Scalars

e(N)number of observationsMacros

e(cmd)mcmcrege(cmdline)command as typede(depvar)name of dependent variablee(wtype)weight typee(wexp)weight expressionFunctions

e(sample)marks estimation sample

AuthorSam Schulhofer-Wohl, Federal Reserve Bank of Minneapolis, sschulh1.work@gmail.com. The views expressed herein are those of the author and not necessarily those of the Federal Reserve Bank of Minneapolis or the Federal Reserve System.

ReferenceChib, Siddhartha, 2001. "Markov Chain Monte Carlo Methods: Computation and Inference." In

Handbook of Econometrics, vol. 5, ed. James J. Heckman and Edward Leamer, 3569-649. Amsterdam: Elsevier.