Dear Statalist,
Thanks to Kit Baum, I am pleased to announce version 4.3.2 of bayeshmc, a Stata package for
Bayesian estimation via Hamiltonian Monte Carlo using CmdStan's NUTS
sampler.
WHAT'S NEW IN 4.3.2
--------------------
This release is a major rewrite. The Python/CmdStanPy dependency has been
removed entirely -- bayeshmc is now pure Stata/Mata, communicating with
CmdStan directly via the operating system shell. The only external
requirement is CmdStan itself (free, open source).
INSTALLATION
------------
ssc install bayeshmc, replace
bayeshmc, setup path(C:\Users\username\.cmdstan\cmdstan-2.38.0)
For automatic setup each session, add to your profile.do:
global CMDSTAN_HOME "C:\Users\username\.cmdstan\cmdstan-2.38.0"
48 SUPPORTED MODELS
-------------------
Single-level (18): regress, logit, probit, poisson, nbreg, ologit,
oprobit, cloglog, tobit, truncreg, betareg, streg, heckman,
heckprobit, zip, zinb, glm, mlogit, hetregress, hetprobit
Panel RE (7): xtreg, xtlogit, xtprobit, xtpoisson, xtnbreg,
xtologit, xtoprobit
Multilevel (13): mixed, melogit, meprobit, mecloglog, mepoisson,
menbreg, meologit, meoprobit, meglm, metobit, mestreg,
mehetregress, mehetoprobit
SYNTAX
------
bayeshmc [, options] : estimation_command [arguments]
The syntax mirrors Stata's bayes: prefix -- specify the estimation
command after the colon, just as you would with bayes: or without
the Bayesian wrapper.
EXAMPLE
-------
sysuse auto, clear
bayeshmc, iter(2000) seed(12345) : regress price mpg weight
bayeshmc bayesplot
bayeshmc summary
bayeshmc ess
KEY FEATURES
------------
* Pure Stata/Mata -- no Python, no R, no external scripts
* 4 parallel chains by default with automatic convergence diagnostics
* Customizable priors on all parameters:
- normalprior(#) for regression coefficients
- sigmaprior(), tauprior(), phiprior(), gammaprior()
accepting any Stan distribution (e.g., student_t(4,0,5))
* Five covariance priors for multilevel RE: LKJ (default),
Inverse-Wishart, Scaled IW, Huang-Wand, Spherical
* Non-centered parameterization (reparam) for efficient multilevel sampling
* New bayesplot command: comprehensive 5-panel diagnostic display
showing trace, density, autocorrelation, and R-hat per parameter
* Model comparison via WAIC and PSIS-LOO
* Model caching: compiled Stan binaries reused across runs
* Binomial grouped data for diagnostic test accuracy meta-analysis
* Defaults follow current Stan recommendations (half-normal priors,
Gelman & Vehtari 2025)
WHY bayeshmc?
-------------
Stata's built-in bayes: prefix uses adaptive Metropolis-Hastings, which
works well for simple models but can struggle with correlated parameters,
multilevel funnels, and high-dimensional posteriors. bayeshmc uses
gradient-based HMC/NUTS sampling, which:
- Scales as O(d^{5/4}) vs O(d^2) for random-walk MH
- Handles correlated posteriors efficiently
- Produces near-independent draws (high ESS per iteration)
- Automatically detects and avoids problematic regions (divergences)
For models where bayes: converges, both should give similar posteriors.
For complex models (heteroscedastic, multilevel with small variance
components, zero-inflated, selection), bayeshmc often succeeds where
bayes: struggles.
COMPANION BOOK
--------------
"Bayesian Regression with Hamiltonian Monte Carlo in Stata" (310 pages)
is in the works as a companion reference covering all 48 model families
with worked examples, mathematical formulations, and prior specification
guidance.
REQUIREMENTS
------------
- Stata 16.0 or later
- CmdStan 2.33 or later (https://mc-stan.org/users/interfaces/cmdstan)
- On Windows: RTools for C++ compilation
AUTHOR
------
Ben Adarkwa Dwamena, MD
Clinical Associate Professor Emeritus of Radiology
University of Michigan, Ann Arbor
[email protected]
I welcome feedback, bug reports, and feature requests.
Best regards,
Ben Dwamena

Comment