ORDER STATA
## Bayesian analysis

Fit Bayesian regression models using one of the Markov chain Monte Carlo
(MCMC) methods. You can choose from a variety of supported models or even
program your own. Extensive tools are available to check convergence,
including multiple chains. Compute posterior mean estimates and credible
intervals for model parameters and functions of model parameters. You can
perform both interval- and model-based hypothesis testing. Compare models
using Bayes factors. Compute model fit using posterior predictive p-values.
Generate predictions. And much more.

Learn about Bayesian analysis and see examples of Bayesian features.

Estimation Updated

- Thousands of built-in models, by combining
- over 50 likelihood models, including univariate and multivariate normal, logit, probit, ordered logit, ordered probit, Poisson ...
- Many prior distributions, including normal, lognormal, multivariate normal, gamma, beta, Wishart ...
- Continuous, binary, ordinal, and count outcomes
- Univariate, multivariate, and multiple-equation models
- Linear and nonlinear models
- Continuous univariate, multivariate, and discrete priors

**bayes:**prefix- Simply type
**bayes:**in front of any of 46 estimation commands to fit Bayesian regression models - Change any of the default priors
- Change any of the simulation or sampling settings
- Time-series operators
- Control Panel lets you specify and fit models from an easy-to-use interface

- Simply type
- Multiple chains New
- Use GUI to fit models
- Use command language to fit models

Watch bayes: prefix for fitting Bayesian regressions.

Watch Graphical user interface for Bayesian analysis in Stata.

Watch Graphical user interface for Bayesian analysis in Stata.

- Linear regression
- Nonlinear regression
- Multivariate regression
- Multivariate nonlinear regression
- Generalized linear models
- Generalized nonlinear models with canonical links
- Zero-inflated models
- Sample-selection models
- Survival models
- Panel-data models
- Multilevel models
- Autoregressive models
- Multiple-equation models

- Normal
- Student's
*t* - Lognormal
- Exponential
- Probit
- Logit/Logistic
- Binomial
- Ordered probit
- Ordered logistic
- Poisson
- Negative binomial
- Multivariate normal (MVN)
- User-defined
- Multilevel
- Normal
- Probit, logit/logistic, complementary log-log
- Ordered probit and logit
- Poisson and negative binomial
- Generalized linear models
- Survival

- Normal
- Generalized (location-scale) t
- Lognormal
- Uniform
- Gamma
- Inverse gamma
- Exponential
- Laplace
- Cauchy
- Beta
- Chi-squared
- Pareto New
- Multivariate normal
- Dirichlet New
- Wishart
- Inverse Wishart
- Bernoulli
- Geometric New
- Discrete
- Poisson
- User-defined density
- User-defined log density
- Specialized priors
- Flat
- Jeffreys
- Multivariate Jeffreys
- Zellner's g

- Write your own programs to calculate likelihood function and choose built-in priors
- Write your own programs to calculate posterior density directly
- Use built-in adaptive MH sampling to simulate marginal posterior

**Markov chain Monte Carlo (MCMC) methods**

- Adaptive Metropolis-Hastings (MH)
- Hybrid MH (adaptive MH with Gibbs updates)
- Full Gibbs sampling for some models

- Produce multiple chains New
- Three MCMC methods
- Control burn-in iterations
- Control MCMC iterations
- Thinning
- Review model summary before simulation
- Save simulation results for future use

- Blocking of parameters
- Adaptation within each block
- Diminishing adaptation
- Random-effects parameters
- Control scale and covariance of the proposal distribution
- Control adaptation
- Length of adaptation
- Maximum and minimum numbers of adaptive iterations
- Acceptance rate
- Adaptation rate
- Target acceptance rate
- Acceptance rate tolerance

- Automatic
- May specify for some or all parameters
- May specify for some or all chains New

- View and run all postestimation features for your command
- Automatically updated as estimation commands are run

Watch Postestimation Selector.

**Tools to check MCMC convergence**

- Diagnostics plots in compact form
- Trace plots
- Autocorrelation plots
- Histograms
- Density plots
- Cumulative sum plots
- Bivariate scatterplots
- Produce any of above for parameters or functions of parameters
- Multiple separate graphs or multiple plots on one graph
- Pause between multiple graphs
- Customize the look of each graph
- Multiple chains New
- Use any of the above graphical tools
- Gelman–Rubin convergence diagnostic

**Tools to check MCMC efficiency**

- Effective sample sizes
- Autocorrelation times
- Efficiencies
- Compute any of above for parameters or functions of parameters

- Means
- Medians
- Standard deviations
- Monte Carlo standard errors (MCSEs)
- Credible intervals (CrIs)
- Compute any of above for parameters or functions of parameters
- Summaries for log likelihood and log posterior
- Compute any of above using multiple chains New
- Summaries for simulated outcomes and their functions New

- Interval-based by computing probability of an interval hypothesis
- Linear and nonlinear
- Single and joint
- Continuous parameters
- Discrete parameters
- Model-based by computing model posterior probabilities
- Perform tests for simulated outcomes and their functions New

Predictions New

- Generate predictions: simulate outcome values and their functions
- Save all or subset of predictions in a separate dataset
- Save posterior summaries of predictions as variables in current dataset
- Save a subset of MCMC replicates as variables in current dataset
- Obtain graphical and posterior summaries, perform hypothesis tests, and more
- Use built-in tools to create functions of predictions or write your own Mata functions and Stata programs
- Generate replicated data for posterior predictive checks

- Deviance information criterion (DIC)
- Bayes factors
- Model posterior probabilities
- Nested and nonnested models

Model goodness of fit New

- Posterior predictive p-values
- MCMC replicates
- Predictions

Save your MCMC and estimation results for future use

- Automatically create indicators based on categorical variables
- Form interactions among discrete and continuous variables Updated
- Include polynomial terms

Watch **Introduction to Factor Variables in Stata** tutorials

**Additional resources**

- New in Bayesian analysis
*Bayesian Analysis Reference Manual*- In the Spotlight: Bayesian "random effects" models
- In the Spotlight: Bayesian logistic models and Cauchy priors—Why and how
- The Stata Blog: Fitting distributions using bayesmh
- The Stata Blog: Bayesian binary item response theory models using bayesmh
- The Stata Blog: Bayesian modeling: Beyond Stata's built-in models
- The Stata Blog: Bayesian logistic regression with Cauchy priors using the bayes prefix
- FAQ: How can I run multiple Markov chains in parallel?
- Introduction to Bayesian Analysis Using Stata training course

Watch
Bayesian analysis in Stata

Watch Introduction to Bayesian analysis, part 1: The basic concepts

Watch Introduction to Bayesian analysis, part 2: MCMC and the Metropolis–Hastings algorithm

Watch bayes: prefix for fitting Bayesian regressions

Watch Bayesian linear regression using the bayes prefix

Watch Bayesian linear regression using the bayes prefix: How to specify custom priors

Watch Introduction to Bayesian analysis, part 1: The basic concepts

Watch Introduction to Bayesian analysis, part 2: MCMC and the Metropolis–Hastings algorithm

Watch bayes: prefix for fitting Bayesian regressions

Watch Bayesian linear regression using the bayes prefix

Watch Bayesian linear regression using the bayes prefix: How to specify custom priors

See
**New in Stata 16**
for more about what was added in Stata 16.