Command sequence
| Command | Purpose |
|---|---|
M=DSGE_MODEL() | Create an empty DSGE model. |
M=SET(M,"name",value) | Declare or update a numeric structural parameter. |
M=ADD_DSGE_SHOCK(M,"name") | Declare an identifier as an exogenous innovation. |
M=ADD_DSGE_EQUATION(M,"equation") | Add one structural equation. |
M=CONFIGURE(M,"setting",value) | Set a numerical solver option. |
M=COMPILE_DSGE(M) | Parse the equations and build the linear coefficient matrices. |
M=SOLVE_DSGE(M) | Solve the compiled model, compiling first when necessary. |
M=SET_DSGE_INITIAL(M,"variable",value) | Set a finite numeric period-zero value for an endogenous variable. |
F=FORECAST_DSGE(M,horizon) | Return a D3 slideshow containing the initial conditions and deterministic forecast. |
SLIDESHOW(M) | Display solver diagnostics, D3 impulse responses, parameters, equations, and settings. |
Linear model representation
RainbowStats compiles the equations into residual form:
The solver looks for a policy rule of the form:
The transition matrix P is obtained from the quadratic matrix equation:
A damped Newton iteration searches for a numerical solution. When several converged candidates are available, the solver favors a stable candidate with a small policy residual.
Supported equation syntax
| Construct | Example | Meaning |
|---|---|---|
| Current variable | pi | Current-period endogenous variable. |
| Expected lead | LEAD(pi,1) | One-period-ahead expected endogenous variable. |
| Lag | LAG(r,1) | One-period lagged endogenous variable. |
| Parameter | beta | An identifier previously registered with SET. |
| Shock | costShock | An identifier previously registered with ADD_DSGE_SHOCK. |
| Arithmetic | + - * / ( ) | Linear arithmetic and grouping. |
| Equality | pi = beta*LEAD(pi,1)+kappa*x | The compiler moves the right side to the left and forms a zero residual. |
sigma has not been registered with SET, the expression sigma*(...) appears to be a nonlinear product of variables and compilation will fail.
Complete New Keynesian example
M=DSGE_MODEL();
M=SET(M,"sigma",1.0);
M=SET(M,"beta",0.99);
M=SET(M,"kappa",0.10);
M=SET(M,"rho",0.80);
M=SET(M,"phiPi",1.50);
M=SET(M,"phiX",0.50);
M=ADD_DSGE_SHOCK(M,"rn");
M=ADD_DSGE_SHOCK(M,"costShock");
M=ADD_DSGE_SHOCK(M,"policyShock");
M=ADD_DSGE_EQUATION(M,
"x = LEAD(x,1) - sigma*(r - LEAD(pi,1) - rn)");
M=ADD_DSGE_EQUATION(M,
"pi = beta*LEAD(pi,1) + kappa*x + costShock");
M=ADD_DSGE_EQUATION(M,
"r = rho*LAG(r,1) + (1-rho)*(phiPi*pi + phiX*x) + policyShock");
M=CONFIGURE(M,"TOLERANCE",0.0000000001);
M=CONFIGURE(M,"MAXIMUM_ITERATIONS",250);
M=CONFIGURE(M,"IMPULSE_HORIZON",20);
M=COMPILE_DSGE(M);
M=SOLVE_DSGE(M);
SLIDESHOW(M);
This three-equation illustration contains an intertemporal demand equation, a forward-looking Phillips curve, and an interest-rate rule. It is a compact teaching model, not a fully estimated representation of a particular economy.
Initial conditions and deterministic forecasts
SET_DSGE_INITIAL supplies a period-zero value for an endogenous variable. The value must be numeric and finite. It can be typed directly or produced by another command that returns a NumberOperator, including END_VALUE(series) and its LAST_VALUE(series) alias.
Pi0=END_VALUE(Inflation)-2.0;
M=SET_DSGE_INITIAL(M,"pi",Pi0);
The model must be solved before calling FORECAST_DSGE. With all future innovations set to zero, the forecast advances the solved policy rule:
The returned object is a D3ComboOperator. Its first panel lists every endogenous variable and its period-zero value; its second panel charts the path from period zero through the requested horizon. Variables without supplied initial values start at zero. The accepted forecast horizon is 1–1000 periods.
u and g.
FRED-initialized Stata example
This example uses actual FRED observations for inflation, the federal funds rate, and the output gap. Inflation is expressed relative to a 2% target, the interest rate relative to an assumed 4% steady-state nominal rate, and real GDP relative to CBO potential GDP. These centering choices are economic assumptions, not estimates produced by the DSGE solver.
Inflation=400*LOGDIFF(TO_QUARTERLY(GDPDEF));
Rate=TO_QUARTERLY(FEDFUNDS);
OutputGap=100*LOG(GDPC1/GDPPOT);
Data=SAME_DATE_RANGE(LIST(Inflation,Rate,OutputGap));
Inflation=EX(Data,series:0);
Rate=EX(Data,series:1);
OutputGap=EX(Data,series:2);
Pi0=END_VALUE(Inflation)-2.0;
R0=END_VALUE(Rate)-4.0;
X0=END_VALUE(OutputGap);
M=DSGE_MODEL();
M=SET(M,"beta",0.5112881);
M=SET(M,"kappa",0.1696296);
M=SET(M,"rhoU",0.6989189);
M=SET(M,"rhoG",0.9556407);
M=ADD_DSGE_SHOCK(M,"epsU");
M=ADD_DSGE_SHOCK(M,"epsG");
M=ADD_DSGE_EQUATION(M,"x = LEAD(x,1) - (r - LEAD(pi,1) - g)");
M=ADD_DSGE_EQUATION(M,"pi = beta*LEAD(pi,1) + kappa*x");
M=ADD_DSGE_EQUATION(M,"r = (1/beta)*pi + u");
M=ADD_DSGE_EQUATION(M,"u = rhoU*LAG(u,1) + epsU");
M=ADD_DSGE_EQUATION(M,"g = rhoG*LAG(g,1) + epsG");
M=SOLVE_DSGE(M);
Det=(-0.4170858559*1.7248273928)-(0.8818837205*0.1842449376);
U0=(1.7248273928*Pi0-0.8818837205*R0)/Det;
G0=(-0.1842449376*Pi0-0.4170858559*R0)/Det;
M=SET_DSGE_INITIAL(M,"pi",Pi0);
M=SET_DSGE_INITIAL(M,"r",R0);
M=SET_DSGE_INITIAL(M,"x",X0);
M=SET_DSGE_INITIAL(M,"u",U0);
M=SET_DSGE_INITIAL(M,"g",G0);
F=FORECAST_DSGE(M,20);
SLIDESHOW(F);
The period-zero values of pi, r, and x preserve the observed FRED conditions. The inferred values U0 and G0 initialize the persistent state processes so that the current conditions carry into later periods.
Solver settings
| Setting | Default | Description |
|---|---|---|
TOLERANCE | 1.0E-10 | Maximum acceptable numerical policy residual for convergence. |
MAXIMUM_ITERATIONS | 250 | Maximum damped-Newton iterations for each starting value. |
IMPULSE_HORIZON | 20 | Number of periods displayed after the impact period. Accepted range: 1–1000. |
SOLVER | Current implementation | Reserved for solver selection; the present implementation uses DAMPED_NEWTON_POLICY. |
Slideshow output
Solved model slideshow
- Solution summary — method, iterations, residual, spectral radius, transition stability, and determinacy warning.
- Impulse-response charts — one animated D3 line chart for each declared shock.
- Parameters — the parameter names, types, and values used during compilation.
- Structural equations — the original human-readable model specification.
- Solver details — the numerical configuration used for the solution.
Forecast slideshow
- Initial conditions — all endogenous variables, including zero defaults for unspecified values.
- Deterministic forecast — one line per endogenous variable from period zero through the requested horizon.
Impulse-response interpretation
For shock j, the response at horizon h is calculated as PhQj. Period zero is the immediate response to a one-unit innovation. Responses are deviations from the deterministic steady state, so the intercept is not included.
Available extracts
| Expression | Returned result |
|---|---|
EXTRACT(M,"solver_summary") | Solver summary panel. |
EXTRACT(M,"transition_matrix") | Policy transition matrix P. |
EXTRACT(M,"shock_impact_matrix") | Contemporaneous shock-impact matrix Q. |
EXTRACT(M,"intercept_vector") | Policy-rule intercept d. |
EXTRACT(M,"eigenvalues") | Real and imaginary parts of the transition eigenvalues. |
EXTRACT(M,"spectral_radius") | Largest absolute transition eigenvalue. |
EXTRACT(M,"stability") | STABLE, NEAR_UNIT_ROOT, or UNSTABLE. |
EXTRACT(M,"policy_residual") | Numerical residual of the quadratic policy equation. |
EXTRACT(M,"solver_iterations") | Iterations used by the selected Newton solution. |
EXTRACT(M,"impulse_response_chart_rn") | D3 chart for the named shock. |
EXTRACT(M,"impulse_response_data_rn") | Numeric IRF matrix: period followed by one column per endogenous variable. |
EXTRACT(M,"lead_matrix") | Lead coefficient matrix A+1. |
EXTRACT(M,"current_matrix") | Current coefficient matrix A0. |
EXTRACT(M,"lag_matrix") | Lag coefficient matrix A−1. |
EXTRACT(M,"shock_matrix") | Structural shock coefficient matrix B. |
Replace rn with any declared shock name when extracting its chart or data.
What the current implementation does not do
- No nonlinear solution. Products of endogenous variables, powers of variables, nonlinear functions, and division by variable-bearing expressions are rejected.
- No automatic linearization. Supply equations that are already linear or log-linearized around a steady state.
- No steady-state calculation. The user is responsible for the economic steady state and the interpretation of deviations from it.
- First-order timing only. The parser currently supports
LEAD(variable,1)andLAG(variable,1), not arbitrary lead or lag orders. - No QZ decomposition or full determinacy test. Transition stability is not the same as satisfying the Blanchard–Kahn conditions.
- No estimation. Parameters are calibrated by the user; they are not estimated from observed time-series data.
- No shock distribution model. The implementation does not presently estimate covariance matrices, likelihoods, or posterior distributions.
- No confidence intervals. Impulse responses are deterministic responses at the supplied calibration and do not include parameter or shock uncertainty bands.
- No estimated or stochastic forecast.
FORECAST_DSGEsets future shocks to zero and does not produce forecast confidence intervals. - No forecast-error variance decomposition or historical decomposition. The current output focuses on policy matrices, impulse responses, and deterministic initialized forecasts.
Recommended use
DSGE_MODEL is best used for transparent teaching examples, rapid experiments with small first-order linear systems, verification of equation signs and timing, exploratory impulse-response analysis, and deterministic scenarios initialized from observed data. For research-grade rational-expectations work, compare the results with an established QZ-based DSGE package and document the equilibrium conditions, calibration, shock scaling, steady-state transformation, and initialization method.
Common errors
| Message | Likely cause | Correction |
|---|---|---|
| Unknown parameter | The model does not support set-or-declare parameters, or an older class is installed. | Use the current DSGEModelOperator and call SET before compilation. |
| Nonlinear multiplication is not supported | Two variable-bearing expressions were multiplied, or a parameter was not declared. | Linearize the equation and verify every scalar parameter was registered with SET. |
| Policy iteration did not converge | No starting value found a sufficiently accurate matrix root. | Check signs, timing, equation count, calibration, and whether the intended model has a suitable solution under this solver. |
| Model has not been compiled | A compiled matrix was requested before COMPILE_DSGE. | Compile first, or call SOLVE_DSGE, which compiles when necessary. |
| Unknown DSGE shock | The requested IRF name does not match a declared shock. | Use the name supplied to ADD_DSGE_SHOCK. |
| DSGE model must be solved before forecasting | FORECAST_DSGE was called before a successful solution. | Call M=SOLVE_DSGE(M) first. |
| Unknown DSGE initial variable | An initial-value name does not match a compiled endogenous variable. | Use a variable appearing in the structural equations. |
| DSGE initial value must be finite | The supplied value is missing, infinite, or not numeric. | Pass a typed number or a numeric result such as END_VALUE(series). |
| DSGE forecast horizon must be between 1 and 1000 | The horizon is zero, negative, nonintegral, or too large. | Supply an integer from 1 through 1000. |