2011-10-12 21:46:50 +02:00
|
|
|
function [steady_state,params,check] = dyn_ramsey_static(x,M,options_,oo)
|
2009-12-16 18:17:34 +01:00
|
|
|
|
2011-10-12 21:46:50 +02:00
|
|
|
% function [steady_state,params,check] = dyn_ramsey_static_(x)
|
2009-12-16 18:17:34 +01:00
|
|
|
% Computes the static first order conditions for optimal policy
|
|
|
|
%
|
|
|
|
% INPUTS
|
2011-10-12 21:46:50 +02:00
|
|
|
% x: vector of endogenous variables or instruments
|
2009-12-16 18:17:34 +01:00
|
|
|
%
|
|
|
|
% OUTPUTS
|
|
|
|
% resids: residuals of non linear equations
|
|
|
|
% rJ: Jacobian
|
|
|
|
% mult: Lagrangian multipliers
|
|
|
|
%
|
|
|
|
% SPECIAL REQUIREMENTS
|
|
|
|
% none
|
|
|
|
|
2011-02-04 17:27:33 +01:00
|
|
|
% Copyright (C) 2003-2010 Dynare Team
|
2009-12-16 18:17:34 +01:00
|
|
|
%
|
|
|
|
% This file is part of Dynare.
|
|
|
|
%
|
|
|
|
% Dynare is free software: you can redistribute it and/or modify
|
|
|
|
% it under the terms of the GNU General Public License as published by
|
|
|
|
% the Free Software Foundation, either version 3 of the License, or
|
|
|
|
% (at your option) any later version.
|
|
|
|
%
|
|
|
|
% Dynare is distributed in the hope that it will be useful,
|
|
|
|
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
% GNU General Public License for more details.
|
|
|
|
%
|
|
|
|
% You should have received a copy of the GNU General Public License
|
|
|
|
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
2011-10-12 21:46:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
steady_state = [];
|
|
|
|
params = M.params;
|
|
|
|
check = 0;
|
|
|
|
nl_func = @(x) dyn_ramsey_static_1(x,M,options_,oo);
|
|
|
|
|
|
|
|
if options_.steadystate_flag
|
|
|
|
k_inst = [];
|
|
|
|
instruments = options_.instruments;
|
|
|
|
inst_nbr = size(options_.instruments);
|
|
|
|
for i = 1:inst_nbr
|
|
|
|
k_inst = [k_inst; strmatch(options_.instruments(i,:), ...
|
|
|
|
M.endo_names,'exact')];
|
|
|
|
end
|
|
|
|
ys = oo.steady_state;
|
|
|
|
if inst_nbr == 1
|
2011-11-14 21:58:53 +01:00
|
|
|
inst_val = csolve(nl_func,oo.steady_state(k_inst),'',options_.solve_tolf,100);
|
2011-10-12 21:46:50 +02:00
|
|
|
else
|
|
|
|
[inst_val,info1] = dynare_solve(nl_func,ys(k_inst),0);
|
|
|
|
end
|
|
|
|
ys(k_inst) = inst_val;
|
2011-11-14 21:58:53 +01:00
|
|
|
exo_ss = [oo.exo_steady_state oo.exo_det_steady_state];
|
|
|
|
[x,params,check] = evaluate_steady_state_file(ys,exo_ss,params,...
|
|
|
|
M.fname,options_.steadystate_flag);
|
2011-10-12 21:46:50 +02:00
|
|
|
if size(x,1) < M.endo_nbr
|
|
|
|
if length(M.aux_vars) > 0
|
|
|
|
x = feval([M.fname '_set_auxiliary_variables'],xx,...
|
|
|
|
M.params);
|
|
|
|
else
|
|
|
|
error([M.fname '_steadystate.m doesn''t match the model']);
|
|
|
|
end
|
|
|
|
end
|
2011-11-14 21:58:53 +01:00
|
|
|
[junk,junk,multbar] = dyn_ramsey_static_1(x(k_inst),M,options_,oo);
|
2011-10-12 21:46:50 +02:00
|
|
|
steady_state = [x(1:M.orig_endo_nbr); multbar];
|
|
|
|
else
|
|
|
|
xx = oo.steady_state(1:M.orig_endo_nbr);
|
|
|
|
[xx,info1] = dynare_solve(nl_func,xx,0);
|
|
|
|
[junk,junk,multbar] = nl_func(xx);
|
|
|
|
steady_state = [xx; multbar];
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function [resids, rJ,mult] = dyn_ramsey_static_1(x,M,options_,oo)
|
|
|
|
resids = [];
|
|
|
|
rJ = [];
|
|
|
|
mult = [];
|
2009-12-16 18:17:34 +01:00
|
|
|
|
|
|
|
% recovering usefull fields
|
2010-05-29 07:48:00 +02:00
|
|
|
endo_nbr = M.endo_nbr;
|
|
|
|
exo_nbr = M.exo_nbr;
|
2011-10-12 21:46:50 +02:00
|
|
|
orig_endo_nbr = M.orig_endo_nbr;
|
|
|
|
orig_eq_nbr = M.orig_eq_nbr;
|
2011-03-27 16:54:49 +02:00
|
|
|
inst_nbr = orig_endo_nbr - orig_eq_nbr;
|
|
|
|
% indices of Lagrange multipliers
|
|
|
|
i_mult = [orig_endo_nbr+(1:orig_eq_nbr)]';
|
2010-05-29 07:48:00 +02:00
|
|
|
fname = M.fname;
|
|
|
|
max_lead = M.maximum_lead;
|
|
|
|
max_lag = M.maximum_lag;
|
2009-12-16 18:17:34 +01:00
|
|
|
|
|
|
|
% indices of all endogenous variables
|
|
|
|
i_endo = [1:endo_nbr]';
|
|
|
|
% indices of endogenous variable except instruments
|
2010-05-29 07:48:00 +02:00
|
|
|
% i_inst = M.instruments;
|
2009-12-16 18:17:34 +01:00
|
|
|
% lead_lag incidence matrix for endogenous variables
|
2010-05-29 07:48:00 +02:00
|
|
|
i_lag = M.lead_lag_incidence;
|
2009-12-16 18:17:34 +01:00
|
|
|
|
|
|
|
if options_.steadystate_flag
|
|
|
|
k_inst = [];
|
|
|
|
instruments = options_.instruments;
|
|
|
|
for i = 1:size(instruments,1)
|
|
|
|
k_inst = [k_inst; strmatch(options_.instruments(i,:), ...
|
2010-05-29 07:48:00 +02:00
|
|
|
M.endo_names,'exact')];
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
2010-05-29 07:48:00 +02:00
|
|
|
oo.steady_state(k_inst) = x;
|
2011-11-14 21:58:53 +01:00
|
|
|
[x,params,check] = evaluate_steady_state_file(oo.steady_state,...
|
|
|
|
[oo.exo_steady_state; ...
|
|
|
|
oo.exo_det_steady_state] ...
|
|
|
|
,M.params,M.fname,...
|
|
|
|
options_.steadystate_flag);
|
2011-10-12 21:46:50 +02:00
|
|
|
end
|
2011-07-24 20:52:28 +02:00
|
|
|
|
2011-10-12 21:46:50 +02:00
|
|
|
% setting steady state of auxiliary variables
|
|
|
|
xx = zeros(endo_nbr,1);
|
|
|
|
xx(1:orig_endo_nbr) = x(1:orig_endo_nbr);
|
2011-07-24 20:52:28 +02:00
|
|
|
|
2011-10-12 21:46:50 +02:00
|
|
|
x = feval([M.fname '_set_auxiliary_variables'],xx,...
|
|
|
|
[oo.exo_steady_state,...
|
|
|
|
oo.exo_det_steady_state],...
|
|
|
|
M.params);
|
2009-12-16 18:17:34 +01:00
|
|
|
|
|
|
|
% value and Jacobian of objective function
|
2010-05-29 07:48:00 +02:00
|
|
|
ex = zeros(1,M.exo_nbr);
|
2011-10-12 21:46:50 +02:00
|
|
|
[U,Uy,Uyy] = feval([fname '_objective_static'],x,ex, M.params);
|
2009-12-16 18:17:34 +01:00
|
|
|
Uy = Uy';
|
|
|
|
Uyy = reshape(Uyy,endo_nbr,endo_nbr);
|
|
|
|
|
2011-03-27 16:54:49 +02:00
|
|
|
% set multipliers to 0 to compute residuals
|
2011-10-12 21:46:50 +02:00
|
|
|
[f,fJ] = feval([fname '_static'],x,[oo.exo_simul oo.exo_det_simul], ...
|
|
|
|
M.params);
|
2009-12-16 18:17:34 +01:00
|
|
|
|
2011-07-24 20:52:28 +02:00
|
|
|
aux_eq = [1:orig_endo_nbr orig_endo_nbr+orig_eq_nbr+1:size(fJ,1)];
|
|
|
|
A = fJ(aux_eq,orig_endo_nbr+1:end);
|
|
|
|
y = f(aux_eq);
|
2011-03-27 16:54:49 +02:00
|
|
|
mult = -A\y;
|
2009-12-16 18:17:34 +01:00
|
|
|
|
2011-03-27 16:54:49 +02:00
|
|
|
resids1 = y+A*mult;
|
2011-06-22 11:31:35 +02:00
|
|
|
if inst_nbr == 1
|
|
|
|
r1 = sqrt(resids1'*resids1);
|
|
|
|
else
|
|
|
|
[q,r,e] = qr([A y]');
|
|
|
|
r1 = r(end,(orig_endo_nbr-inst_nbr+1:end))';
|
|
|
|
end
|
2009-12-16 18:17:34 +01:00
|
|
|
if options_.steadystate_flag
|
2011-06-22 11:31:35 +02:00
|
|
|
resids = r1;
|
2009-12-16 18:17:34 +01:00
|
|
|
else
|
2011-06-22 11:31:35 +02:00
|
|
|
resids = [f(i_mult); r1];
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
|
|
|
rJ = [];
|