Skip to content

Bring an IRIS or Dynare model across, then check and solve it

Read a model file written for IRIS or Dynare, check that pymetrix reads it as you meant (the equations, parameters, shocks and their sizes), and solve it to first order under rational expectations. Neither IRIS nor Dynare (nor MATLAB) is needed: the file is read as text.

The rational-expectations solution's Graph view: the responses of the New Keynesian model's variables to a one-unit shock in each of its shocks, panel by panel.
The imported model's solution: responses to each shock.

Before you start

  • The model file. This page uses a three-equation New Keynesian model, in IRIS's syntax as nk.model:

```text nk.model % A three-equation New Keynesian model !transition_variables "Output gap" y, "Inflation" pi, "Policy rate" i !transition_shocks ey, epi, ei !parameters sig = 1, bet = 0.99, kap = 0.1, rho = 0.8, phi std_ey = 0.5, std_epi = 0.3, std_ei = 0.2 !measurement_variables obs_pi !transition_equations "IS curve" y = y{+1} - sig(i - pi{+1}) + ey; "Phillips curve" pi = betpi{+1} + kapy + epi; "Policy rule" i = rhoi{-1} + (1-rho)(phipi + 0.5y) + ei; !measurement_equations obs_pi = 2 + 4pi;

and in Dynare's as `nk.mod`:

```text nk.mod
// The same model in Dynare
var y pi i;
varexo ey epi ei;
parameters sig bet kap rho phi;
sig = 1; bet = 0.99; kap = 0.1; rho = 0.8; phi = 1.5;
model;
y = y(+1) - sig*(i - pi(+1)) + ey;
pi = bet*pi(+1) + kap*y + epi;
i = rho*i(-1) + (1-rho)*(phi*pi + 0.5*y) + ei;
end;
shocks;
var ey; stderr 0.5;
var epi; stderr 0.3;
var ei; stderr 0.2;
end;
steady;
check;
stoch_simul(order=1, irf=20) y pi i;

  • The values of parameters the IRIS file leaves out. IRIS models often set them in code (m.phi = 1.5); here phi has no value in the file.

In the app, or in code

The Import IRIS file dialog with the file nk.model, the parameter phi=1.5 and Save as nk.
Model → Import → IRIS file…, as in step 1.

Follow this step by step in the app

View → Guide → How do I → Bring an IRIS or Dynare model across, then check and solve it. The Guide panel takes you through these steps one at a time: Open… opens each step's dialog filled in, Show me runs it, and each step is ticked when its result is there. In the app's help, the page's Walk me through this opens it. The Guide is in the pymetrix-guide plugin, which is experimental (pip install --pre "pymetrix[guide]"; the walkthroughs come with its release after 0.1.0a1).

  1. Model → Import → IRIS file…, with IRIS file: nk.model, Parameters: phi=1.5 and Save as: nk. A parameter still without a value stops the step and is named.
  2. In the model's window, read the views: Equations (as pymetrix reads them, y{+1} written y[+1]), Parameters, Measurement (obs_pi) and Shocks (their standard deviations, from the std_ parameters).
  3. Model → Solution → Rational expectations…, with Equations: nk and Save as: sol. Leave Shocks and Parameters empty: an imported model has its own. The solve finds the steady state and checks the Blanchard-Kahn conditions; if there is no stable solution, or more than one, the step stops and says which.
  4. In the solution's window: Decision rules (each variable on the predetermined variables and the shocks), Graph (the responses to a one-unit shock), Steady state and Roots (with the Blanchard-Kahn count).
  5. For the Dynare file: Model → Import → Dynare file…, with Dynare file: nk.mod and Save as: mod, then Rational expectations… with Equations: mod. The model's window lists the file's commands (steady, check, stoch_simul) under Commands: they are read, not run.

To look for problems in the file itself before importing it: Model → Model editor…, Syntax: IRIS (.model) or Dynare (.mod), and paste the text. Problems lists each at its line and column; Check solution finds the steady state and the roots and draws the responses to one-standard-deviation shocks.

import numpy as np
from pymetrix import read_iris, read_mod

nk = read_iris("nk.model", params={"phi": 1.5})       # values the file leaves out
nk.check()                                              # equations, parameters, timing, steady state, Blanchard-Kahn
nk.steady_state()                                       # zero: the model is in deviations
sol = nk.solve()                                        # first order: the unique stable solution
sol.roots()                                             # 1 stable root for 1 predetermined variable
sol.rules()                                             # y, pi and i on i[-1] and the three shocks
irf = sol.irf(20, shock_sd=nk.shock_sd)                 # one standard deviation of each shock
irf.plot()

The Dynare file gives the same model:

mod = read_mod("nk.mod")
mod.commands                                            # ('steady', 'check', 'stoch_simul(order=1, irf=20) y pi i')
dyn = mod.solve()
assert np.allclose(dyn.irf(20).values, sol.irf(20).values)

Check the result

  • The Roots view: "Blanchard-Kahn: stable roots 1 (unit roots included), predetermined variables 1". The stable root is 0.54; the other two are outside the unit circle.
  • The Decision rules against IRIS's or Dynare's own: the response of y to ei on impact is -1.97 for a unit shock. Dynare's stoch_simul prints the same numbers as its policy and transition functions, with the variables as columns.
  • The impulse responses against IRIS's srf or Dynare's stoch_simul (both one standard deviation): y to ei on impact is -0.394 (-1.97 times 0.2).
  • The steady state against IRIS's sstate or Dynare's steady: here zero for every variable.

Pitfalls

  • One unit or one standard deviation. sol.irf(20) and the solution's Graph view give responses to a one-unit shock; IRIS's srf and Dynare's stoch_simul to one standard deviation. Pass shock_sd=nk.shock_sd to compare, or use the model editor's Check solution.
  • "The solution is not unique". Too many stable roots: indeterminacy, often a policy rule that responds less than one for one to inflation (phi=0.8 here gives it). Too few: no stable solution, often a sign error.
  • !log_variables. Those variables are solved in logs, so their responses are log deviations, as in IRIS; a Dynare model of the same variables in levels gives level deviations.
  • Commands in a .mod file are not run. estimated_params, varobs and estimation are read for estimation (Model → Estimation → Estimate model…); stoch_simul's options are not applied.
  • Decision rules in Dynare's own output are in its order. oo_.dr.ghx and oo_.dr.ghu have their rows in oo_.dr.order_var's order, not the declaration order pymetrix uses.

See also