»  Home »  Stata News »  Vol 36 No 5 »  In the spotlight: Bayesian DSGE models
The Stata News

«Back to main page

In the spotlight: Bayesian DSGE models

Dynamic stochastic general equilibrium (DSGE) models are used in macroeconomics for policy analysis and forecasting. These models consist of systems of equations that represent the structure of some aspect of the economy. The equations are based on economic theory and describe very specific nonlinear relationships among observed and unobserved variables. Because of the structure of the model, some of the parameters have a direct economic interpretation.

DSGE models lend themselves to Bayesian estimation because we often have prior knowledge about some of the parameters in the model. Bayesian priors capture information about parameters that is not reflected in the current dataset. For example, a parameter that is interpreted as representing price stickiness might have a prior informed by firm-level surveys of price adjustment. More informative priors can be specified for parameters about which much is known, and flatter priors can be specified for parameters for which less is known.

Below, I demonstrate Bayesian estimation using a small DSGE model that shares features with larger models used to analyze monetary policy. After introducing the model, I discuss priors for the model parameters and then use the new bayes: dsge command to simulate posterior densities. Finally, I'll show how you can easily interpret the results—I will use bayesirf to look at the response of the model to an impulse (sudden change) in monetary policy.


The model has equations for the output gap, inflation, and interest rate.

\begin{align} x_t &= E_t x_{t+1} - (r_t - p_{t+1} - z_t) \tag{1} \\ p_t &= \beta E_t p_{t+1} + \kappa x_t \tag{2}\\ r_t &= \rho_r r_{t-1} + \frac{(1 - \rho_r)}{\delta}p_t + m_t \tag{3}\\ z_{t+1} &= \rho_z z_t + e_{t+1} \tag{4}\\ m_{t+1} &= \rho_m m_t + \epsilon_{t+1} \tag{5}\\ \end{align}

The model has considerable structure. The first equation relates the output gap \(x_t\) to the expected future output gap \(E_t x_{t+1}\), the current interest rate \(r_t\), the expected future inflation rate \(p_{t+1}\), and a disturbance term \(z_t\). The second equation relates inflation \(p_t\) to expected future inflation rate \(E_t p_{t+1}\) and the current output gap \(x_t\). The third equation relates the current interest rate \(r_t\) to its own lagged value \(r_{t-1}\), the current inflation rate \(p_t\), and a disturbance term \(m_t\). The fourth and fifth equations specify autoregressive processes for the disturbance terms \(z_t\) and \(m_t\), respectively. The shocks \(e_t\) and \(\epsilon_t\) are white noise processes.

The disturbance terms capture exogenous economic processes; \(m_{t}\) captures monetary policy, while \(z_{t}\) can be interpreted as a "real" (nonmonetary) disturbance. The disturbance terms are also known as state variables. The shocks (\(e_t\) and \(\epsilon_t\)) feed into the state variables (\(z_t\) and \(m_t\)), which then feed into the control variables (\(x_t\), \(p_t\), and \(r_t\)).

Parameters can appear nonlinearly, more than once, and across equations. Equation (1) has no parameters; all of its coefficients are constrained to either 1 or \(-1\). Equation (2) has two parameters: \(\beta\) on expected future inflation and \(\kappa\) on the output gap. Equation (3) has two parameters: \(p_r\) on the lagged interest rate and \((1 - p_r)/\delta\) on the inflation rate. Equations (4) and (5) have autoregressive parameters for the state variables.


To perform Bayesian estimation of the model in our example, we need to specify priors for the parameters.

Parameters in a DSGE model typically have economic interpretation. I use those interpretations to specify informative priors. The model has six structural parameters (\(\beta\), \(\kappa\), \(\delta\), \(p_r\), \(p_z\), and \(p_m\)) and two standard deviation parameters (\(\sigma_e\) ano \(\sigma_{\epsilon}\)). Parameter \(\beta\) is the coefficient on expected inflation in the inflation equation. It is linked to the discount factor. It must lie between 0 and 1 and is probably in the higher end of that range. I use a prior of a beta distribution with parameters (95, 5). These parameters are consistent with a prior mean of 0.95.

Parameter \(\kappa\) is the coefficient on the output gap in the inflation equation. Some theories predict this parameter to be positive; others predict it to be 0. I use a beta density prior with parameters (30, 70), placing the prior mean at 0.3 with a standard deviation of roughly 0.05.

Parameter \(\delta\) appears as the inverse of the inflation coefficient in the interest rate equation. I use a beta density prior with parameters (50, 50), which places the prior mean of \(\delta\) at 0.5 (and the prior mean of its inverse \(1/\delta\) at 2).

Parameters (\(\rho_r\), \(\rho_z\), and \(p_m\)) are all autoregressive parameters. Each must lie in the range (−1, 1), and all are likely positive. I give \(\rho_r\) a beta density prior with a prior mean of 0.7. The other two autoregressive parameters are given beta density priors with prior mean 0.5 and prior standard deviation 0.1.


All this information is collected in a bayes: dsge command. For data, I use inflation and interest rates, treating the output gap as unobserved.

. webuse usmacro2
(Federal Reserve Economic Data - St. Louis Fed, 2017-01-15)

. bayes,  prior({beta},  beta(95,5))   prior({kappa}, beta(30,70))
          prior({delta}, beta(50,50))  prior({rhoz}, beta(10,10))  
          prior({rhom},  beta(10,10))  prior({rhor}, beta(70,30))  
          dots rseed(20) saving(dsgesim.dta, replace):             
          dsge (x = F.x - (r - F.p - z),         unobserved) 
               (p = {beta}*F.p + {kappa}*x                 ) 
               (r = {rhor}*Lr + (1-{rhor})/{delta}*p + m   )  
               (F.z = {rhoz}*z, state                      ) 
               (F.m = {rhom}*m, state                      ) 
               (F.Lr = r, state noshock                    )
note: initial parameter vector set to means of priors.

Burn-in ...
Simulation ...

Model summary
Likelihood: p r ~ dsgell({beta},{kappa},{rhor},{delta},{rhoz},{rhom},{sd(e.z)},{sd(e.m)}) Priors: {beta} ~ beta(95,5) {kappa} ~ beta(30,70) {rhor} ~ beta(70,30) {delta} ~ beta(50,50) {rhoz rhom} ~ beta(10,10) {sd(e.z) sd(e.m)} ~ igamma(.01,.01)
Bayesian linear DSGE model MCMC iterations = 12,500 Random-walk Metropolis–Hastings sampling Burn-in = 2,500 MCMC sample size = 10,000 Sample: 1955q1 thru 2015q4 Number of obs = 244 Acceptance rate = .2263 Efficiency: min = .005324 avg = .02431 Log marginal-likelihood = -812.34811 max = .05677
Mean Std. dev. MCSE Median [95% cred. interval]
beta .9425961 .0242996 .00129 .9449948 .8856144 .9804352
kappa .1745316 .0329312 .004513 .1691739 .1218941 .2502198
rhor .5618614 .0392734 .001648 .5638762 .4780712 .6361862
delta .5016381 .0356965 .002542 .5030397 .4324766 .5731499
rhoz .8898251 .019323 .001002 .8905575 .8487836 .925779
rhom .3048201 .0550579 .005443 .304038 .1981819 .4147763
sd(e.z) .9574072 .1091821 .007076 .9473704 .7585204 1.204371
sd(e.m) 1.52041 .0993582 .012936 1.50863 1.353584 1.751129

This command splits into two parts. The first part, before the colon, specifies the prior densities and some Bayesian options. I set the seed with rseed() for reproducibility and save the MCMC simulation in the file dsgesim.dta. The second part, after the colon, contains the DSGE model specification. The first, second, and third equations are the output gap, inflation, and interest rate equations. The fourth and fifth equations specify laws of motion for the state variables. Finally, the sixth equation is an identity that creates a state variable Lr and defines it to be the lagged interest rate.

The estimation header provides information about the MCMC process. The default number of burn-in periods (2,500) and MCMC sample periods (10,000) were used. The acceptance rate was 22.63%, which is typical for the Metropolis–Hastings sampling method. Efficiencies range from 0.005 to 0.05.

The estimation table provides posterior mean, median, standard deviation, and 95% credible intervals. The posterior mean for beta is 0.94, not very far from its prior mean of 0.95. The posterior mean for kappa is 0.17, half its prior mean. The posterior mean of rhor is 0.56, indicating a moderate degree of autocorrelation. The posterior mean for delta is 0.5, again not far from its prior mean. The posterior mean of rhoz is 0.89, indicating considerable autocorrelation, while the posterior mean of rhom is 0.3, indicating mild autocorrelation.

It is often useful to compare the posterior densities with the prior densities. I do so for \(\kappa\):

. bayesgraph kdensity kappa, addplot(function Prior = betaden(30,70,x),
          legend(on) legend(label(1 "Posterior")))

This produces the following graph:


I can repeat this process for all six structural parameters:


Parameters beta and delta show little updating, indicating that the likelihood of the model is flat along those dimensions. The posterior densities for rhor and rhom indicate somewhat lower autocorrelation than was posited in the prior. By contrast, rhoz is highly autocorrelated.

Impulse responses

An impulse–response function traces out the effect of a shock on the model variables. In this section, I compute and discuss the responses to a monetary shock. The experiment in mind is a sudden, unexpected increase to the interest rate.

To create a set of impulse responses, I use bayesirf.

. bayesirf set bayesdsge, replace
(file bayesdsge.irf created)
(file bayesdsge.irf now active)

. bayesirf create model1
(file bayesdsge.irf updated)

. bayesirf graph irf, impulse(m) response(x p r m) byopts(yrescale)

The first line sets the active IRF file to bayesdsge.irf; all IRF results will be stored there. The second line computes the IRFs. The third line produces a graph of an impulse to m, with responses of x, p, r, and m.

Each panel graphs the response of one variable to the shock. The x axis is in quarters, so eight steps indicates the response two years after the shock. The top left panel graphs the response of m to a shock to itself. The bottom left panel graphs the response of the interest rate r: it rises, and because of the dependence of r on its own lagged value, its response is slightly more persistent than the shock itself. The top right panel graphs the response of inflation, and the bottom right panel graphs the response of the output gap. Both inflation and output fall, returning gradually to their steady-state values as the effects of the shock dissipate.


In my example of this small monetary model, I've demonstrated how you can easily estimate parameters of a DSGE model by using the new bayes: dsge command. I've also shown you how to explore the posterior estimates and better understand the results of the model by using impulse responses. To learn more about Bayesian DSGE models and see additional examples, you can go to [DSGE] Intro 9.

— by David Schenck
Senior Econometrician and Software Developer

«Back to main page





The Stata Blog: Not Elsewhere Classified Find us on Facebook Follow us on Twitter LinkedIn YouTube Instagram
© Copyright 1996–2021 StataCorp LLC   •   Terms of use   •   Privacy   •   Contact us
× 20% off Gift Shop purchases! Sale ends 12/11 at 11:59 PM CT. Use code GIFT20.