2. First model
A three-equation New Keynesian model, end to end, in fewer than twenty lines.
2.1. The model file
Save the following as nk.rs:
@endogenous x pi i
@exogenous eps_m
@parameters beta sigma kappa phi_pi phi_y rho_m std_eps_m
@model
x{t} = x{t+1} - (1/sigma)*(i{t} - pi{t+1});
pi{t} = beta*pi{t+1} + kappa*x{t};
i{t} = phi_pi*pi{t} + phi_y*x{t} + std_eps_m*eps_m{t};
2.2. Build and solve
In MATLAB:
p = struct( ...
'beta', 0.99, ...
'sigma', 1.0, ...
'kappa', 0.30, ...
'phi_pi', 1.50, ...
'phi_y', 0.125, ...
'std_eps_m', 0.0025);
m = dsge_model('nk.rs');
m = set(m, parameters = p);
[m, retcode] = solve(m);
assert(retcode == 0, decipher(retcode));
2.3. Inspect
print_solution(m);
myirfs = irf(m, irf_periods = 20);
plot(myirfs.eps_m.pi, LineWidth = 2);
2.4. What just happened
dsge_model(...)parsednk.rsinto a model object describing the state-space, with no class-specific metadata stashed away.dsge_modelis the DSGE-shape factory; the VAR family has its own (rfvar_model,svar_model,proxy_svar_model,prfvar_model,dsge_var_model).set(m, parameters = ...)bound numerical values to the declared parameters. The model file declared the model; this call parameterized it. See the Modern architecture chapter for why these are kept separate.solve(m)ran the perturbation engine and returned the model with the solution attached. The retcode is always captured and checked.irfreturned a struct of time series objects (one per shock, one per variable).plotis overloaded for the time series type – no need to extract the underlying numeric array.
2.5. Next steps
Modeling -> Model file language for the full
.rsgrammar.Modeling -> Solving for the solver options exposed on
solve.Modeling -> Estimation for taking the model to data.