Bmabmacoefsample
Bmabmacoefsample
Description
bmacoefsample simulates regression coefficients and other model parameters from their posterior
distributions after bmaregress.
Quick start
Simulate regression coefficients and other model parameters from their posterior distributions after
bmaregress, and use bayesstats summary to display posterior summaries for {y:}, all 12 regres-
sion coefficients, and the intercept, including their 90% highest posterior density (HPD) credible in-
tervals (CrIs)
bmaregress y x1-x12, saving(bmamodelmcmc)
bmacoefsample
bayesstats summary {y:}, clevel(90) hpd
Same as above, but specify a random-number seed and the size of the simulated dataset, and save the
simulated dataset in file bmacoefmcmc.dta
bmacoefsample, rseed(1234) mcmcsize(5000) saving(bmacoefmcmc)
Simulate results without saving first, but then later specify option saving() to save the previously sim-
ulated results in file bmacoefmcmc1.dta, and save a new set of results in bmacoefmcmc2.dta
bmacoefsample, rseed(1234)
bmacoefsample, saving(bmacoefmcmc1)
bmacoefsample, saving(bmacoefmcmc2)
Same as above, but save only one set of results, use option simulate to resimulate the results, and save
the new ones in bmacoefmcmc1, replacing already existing file
bmacoefsample, rseed(1234)
bmacoefsample, saving(bmacoefmcmc1, replace) simulate
Menu
Statistics > Bayesian model averaging > Posterior samples of coefficients
1
2 bmacoefsample — Posterior samples of regression coefficients
Syntax
bmacoefsample [ , coefsimopts ]
coefsimopts Description
Simulation
mcmcsize(#) Markov chain Monte Carlo (MCMC) sample size; default is
mcmcsize(10000) or as specified with bmaregress
rseed(#) random-number seed
Reporting
saving(filename[ , replace ]) save simulation results to filename.dta
[ no ]dots suppress or display dots every 1,000 iterations and iteration
numbers every 5,000 iterations; default is dots
dots(#[ , every(#) ]) display dots as simulation is performed
simulate simulate new results instead of saving existing ones
simulate does not appear in the dialog box.
Options
Simulation
mcmcsize(#) specifies the target MCMC sample size. The default is mcmcsize(10000) or as specified
in bmaregress’s mcmcsize() option.
rseed(#) sets the random-number seed. This option can be used to reproduce results. Option rseed(#)
is equivalent to typing set seed # prior to calling the bmacoefsample command; see [R] set seed.
Reporting
saving(filename[ , replace ]) saves simulation results in filename.dta. The replace option speci-
fies to overwrite filename.dta if it exists. If the saving() option is not specified, bmacoefsample
saves simulation results in a temporary file for later access. This temporary file will be overwritten
every time bmacoefsample or bmaregress is run and will be erased if the current estimation re-
sults are cleared. The simulation dataset has the same structure as described in option saving() of
[BAYES] bayesmh. The simulation results include posterior samples of regression coefficients, the
intercept, and the error variance.
If you first run bmacoefsample without option saving(), you can rerun it with this option later
to save the current simulation results in a file without having to redo a potentially time-consuming
simulation. If, for some reason, you need to simulate a new sample in this case, you should specify
option simulate in addition to saving().
dots, nodots, dots(#), and dots(#, every(#)) specify to display or suppress dots during simula-
tion. dots, the default, displays dots every 1,000 iterations and iteration numbers every 5,000 itera-
tions; it is a synonym for dots(1000, every(5000)). dots(#) displays a dot every # iterations. If
dots(. . ., every(#)) is specified, then an iteration number is displayed every #th iteration instead
of a dot. dots(, every(#)) is equivalent to dots(1, every(#)).
bmacoefsample — Posterior samples of regression coefficients 3
The following option is available with bmacoefsample but is not shown in the dialog box:
simulate is used with option saving() to simulate a new set of results and save them in a file instead
of saving the previously simulated results. This option is implied with bmacoefsample in all but one
case—when option saving() is used and simulation results from a previous run of bmacoefsample
have not been saved in a file already.
stata.com
. bmacoefsample, saving(mycoef)
Once the current results are permanently saved, the next run of bmacoefsample will automatically
produce a new sample. In fact, if you use any option with bmacoefsample other than saving(), it will
automatically trigger the generation of a new sample. You can also force the bmacoefsample command
to resample and save a new set of simulation results by specifying the simulate option together with
saving():
. bmacoefsample
4 bmacoefsample — Posterior samples of regression coefficients
Stored results
In addition to the estimation results stored by bmaregress, bmacoefsample stores the following in
e():
Scalars
e(mcmcsize2) MCMC sample size
Macros
e(cmd2) bmacoefsample
e(filename) name of the file with simulation results
e(parnames) names of model parameters
e(postvars) variable names corresponding to model parameters in e(parnames)
e(scparams) scalar model parameters
e(pareqmap) model parameters in display order
e(rngstate2) random-number state at the time of simulation
where 𝑛 is the sample size and 𝑠2𝑡,𝛿 , µ𝑡 , and 𝚺𝑡 are computed according to (1), (3), and (4) in Conditional
posterior distribution of model parameters in Methods and formulas of [BMA] bmaregress (with index
𝑗 substituted for 𝑡, that is, conditional on model 𝑀𝑡 instead of 𝑀𝑗 ). θ𝑡,𝑝𝑡 = (β′𝑡,𝑝 , 𝛼)′ is a (𝑝𝑡 + 1) × 1
𝑡
vector of the 𝑝𝑡 regression coefficients included in model 𝑀𝑡 and the intercept. Regression coefficients
that are not included in 𝑀𝑡 are assigned 0s. Then a (𝑝 + 1) × 1 vector θ𝑡 includes all 𝑝 regression
coefficients and the intercept from iteration 𝑡.
The result is a sample {θ𝑡 , 𝜎𝑡2 }𝑇𝑡=1 from the BMA posterior distribution of model parameters.
2
𝑛 − 1 𝑠𝑡,𝛿
𝜎𝑡2 |𝑔𝑡 , 𝑚𝑡 ∼ InverseGamma ( , )
2 2
θ𝑡,𝑝𝑡 |𝜎𝑡2 , 𝑔𝑡 , 𝑚𝑡 ∼ 𝑁𝑝𝑡 +1 (µ𝑡 , 𝜎𝑡2 𝚺𝑡 )
where 𝑛 is the sample size and 𝑠2𝑡,𝛿 , µ𝑡 , and 𝚺𝑡 are computed according to (1), (3), and (4) in Conditional
posterior distribution of model parameters in Methods and formulas of [BMA] bmaregress (with index
𝑗 substituted for 𝑡, that is, conditional on model 𝑚𝑡 instead of 𝑀𝑗 ).
Let θ𝑡 be a (𝑝 +1)×1 vector that includes all 𝑝 regression coefficients and the intercept from iteration
𝑡. Then the result is a sample {θ𝑡 , 𝜎𝑡2 }𝑇𝑡=1 from the BMA posterior distribution of model parameters.
6 bmacoefsample — Posterior samples of regression coefficients
Also see
[BMA] bmaregress — Bayesian model averaging for linear regression
[BMA] BMA postestimation — Postestimation tools for Bayesian model averaging
[BMA] Glossary
[BAYES] Bayesian postestimation — Postestimation tools after Bayesian estimation
Stata, Stata Press, and Mata are registered trademarks of StataCorp LLC. Stata and Stata
®
Press are registered trademarks with the World Intellectual Property Organization of the
United Nations. StataNow and NetCourseNow are trademarks of StataCorp LLC. Other
brand and product names are registered trademarks or trademarks of their respective com-
panies. Copyright © 1985–2023 StataCorp LLC, College Station, TX, USA. All rights
reserved.
For suggested citations, see the FAQ on citing Stata documentation.