RainbowStats command reference

DSGE_MODEL

Define a first-order linear dynamic stochastic general equilibrium model with readable equations, solve its policy rule, initialize it from numeric or time-series values, and visualize impulse responses and deterministic forecasts.

Important model limitation The current RainbowStats solver is an experimental linear policy solver based on damped Newton iteration. It is not a generalized Schur/QZ solver and does not test the full Blanchard–Kahn existence and uniqueness conditions. A result labeled stable means that the selected transition matrix has eigenvalues inside the unit circle; it does not prove that the rational-expectations equilibrium exists or is unique.

Command sequence

DSGE_MODEL()
1. Create model
2. Set parameters
3. Add shocks and equations
4. Compile and solve
5. Initialize and forecast
CommandPurpose
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:

A+1Et[xt+1] + A0xt + A−1xt−1 + Bεt + c = 0

The solver looks for a policy rule of the form:

xt = P xt−1 + Qεt + d

The transition matrix P is obtained from the quadratic matrix equation:

A+1P² + A0P + A−1 = 0

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

ConstructExampleMeaning
Current variablepiCurrent-period endogenous variable.
Expected leadLEAD(pi,1)One-period-ahead expected endogenous variable.
LagLAG(r,1)One-period lagged endogenous variable.
ParameterbetaAn identifier previously registered with SET.
ShockcostShockAn identifier previously registered with ADD_DSGE_SHOCK.
Arithmetic+ - * / ( )Linear arithmetic and grouping.
Equalitypi = beta*LEAD(pi,1)+kappa*xThe compiler moves the right side to the left and forms a zero residual.
Declare parameters before compiling An undeclared identifier is treated as an endogenous variable. For example, if 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(model,"variable",value)
FORECAST_DSGE(model,horizon)

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:

xt+1 = P xt + d

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.

Initialize the states that carry the dynamics A value assigned to a purely forward-looking control variable is displayed at period zero, but it may not affect period one. Persistent forecasts require initial values for variables that enter the model with a lag. In the five-equation Stata example below, those state variables are 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

SettingDefaultDescription
TOLERANCE1.0E-10Maximum acceptable numerical policy residual for convergence.
MAXIMUM_ITERATIONS250Maximum damped-Newton iterations for each starting value.
IMPULSE_HORIZON20Number of periods displayed after the impact period. Accepted range: 1–1000.
SOLVERCurrent implementationReserved for solver selection; the present implementation uses DAMPED_NEWTON_POLICY.

Slideshow output

Solved model slideshow

  1. Solution summary — method, iterations, residual, spectral radius, transition stability, and determinacy warning.
  2. Impulse-response charts — one animated D3 line chart for each declared shock.
  3. Parameters — the parameter names, types, and values used during compilation.
  4. Structural equations — the original human-readable model specification.
  5. Solver details — the numerical configuration used for the solution.

Forecast slideshow

  1. Initial conditions — all endogenous variables, including zero defaults for unspecified values.
  2. 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.

A one-unit shock is not automatically a one-standard-deviation shock The current model does not estimate or require a shock covariance matrix. Scale the shock coefficients in the equations if a different innovation size is economically appropriate.

Available extracts

ExpressionReturned 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

Do not interpret convergence as economic validation A very small numerical residual shows that the selected matrices approximately satisfy the equations presented to the solver. It does not show that the equations are correctly specified, the calibration is empirically credible, the equilibrium is unique, or the policy experiment is economically meaningful.

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

MessageLikely causeCorrection
Unknown parameterThe 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 supportedTwo 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 convergeNo 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 compiledA compiled matrix was requested before COMPILE_DSGE.Compile first, or call SOLVE_DSGE, which compiles when necessary.
Unknown DSGE shockThe requested IRF name does not match a declared shock.Use the name supplied to ADD_DSGE_SHOCK.
DSGE model must be solved before forecastingFORECAST_DSGE was called before a successful solution.Call M=SOLVE_DSGE(M) first.
Unknown DSGE initial variableAn initial-value name does not match a compiled endogenous variable.Use a variable appearing in the structural equations.
DSGE initial value must be finiteThe 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 1000The horizon is zero, negative, nonintegral, or too large.Supply an integer from 1 through 1000.