------------------------------------------------------------------------------- help formcmcreg-------------------------------------------------------------------------------

Syntax

mcmcregdepvar[indepvars] [if] [in] [weight],saving(filename)d0(#)[options]

optionsDescription ------------------------------------------------------------------------- Modeld0(#)prior variance of regression errornoconstantsuppress 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.

Description

mcmcreguses Markov chain Monte Carlo (MCMC) to sample from the posterior distribution of a normal linear regression model ofdepvaronindepvars.

mcmcregproduces 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).sigma2Variance of regression error.The variable

iterin the output file keeps track of iterations;iter=0 is the initial condition used to start the chain.

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.

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.

Methods

mcmcreguses the Gibbs sampler. Standard uninformative conjugate priors are used: The prior for the regression coefficients is uninformative, while the prior for the error variancesigma^2is InverseGamma(1/2,d0/2). See Chib (2001, algorithm 5) for a textbook exposition.The sampler is initialized with a guess for

sigma^2drawn 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 squared residuals from the frequentist least squares regression ofdepvaronindepvars.

. sysuse auto. mcmcreg mpg weight foreign, saving(mcmcreg_auto.dta) d0(0.01). use mcmcreg_auto.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.

mcmcregwill generate different chains when run repeatedly with different values ofseed(#).

. sysuse auto. tempfile temp. mcmcreg mpg weight foreign, saving(`temp') d0(0.01) seed(12345). use `temp', clear. gen byte chain=1. save mcmcreg_auto.dta. sysuse auto, clear. mcmcreg mpg weight foreign, saving(`temp') d0(0.01) seed(54321)replace. use `temp', clear. gen byte chain=2. append using mcmcreg_auto.dta. save mcmcreg_auto.dta, replace. by chain, sort: summarize *See mcmcconverge, available in the SSC package

mcmcstats, 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

mcmcregsaves 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.