more fixes for loglinear with lead/lagged exogenous variables
parent
7e13fe5ef7
commit
3c7c2f46a4
|
@ -334,15 +334,21 @@ end
|
||||||
|
|
||||||
if options_.loglinear
|
if options_.loglinear
|
||||||
% this needs to be extended for order=2,3
|
% this needs to be extended for order=2,3
|
||||||
k = get_all_variables_but_lagged_leaded_exogenous(M_);
|
[il,il1,ik,k1] = indices_lagged_leaded_exogenous_variables(dr.order_var,M_);
|
||||||
[ik,k1] = rm_lagged_leaded_exogenous_variables(dr.order_var,M_);
|
[illag,illag1,iklag,klag1] = indices_lagged_leaded_exogenous_variables(dr.order_var(M_.nstatic+(1:M_.nspred)),M_);
|
||||||
[iklag,klag1] = rm_lagged_leaded_exogenous_variables(dr.order_var(M_.nstatic+(1:M_.nspred)),M_);
|
|
||||||
if ~isempty(ik)
|
if ~isempty(ik)
|
||||||
if M_.maximum_endo_lag > 0
|
if M_.nspred > 0
|
||||||
dr.ghx(ik,iklag) = repmat(1./dr.ys(k1),1,length(klag1)).*dr.ghx(ik,iklag).* ...
|
dr.ghx(ik,iklag) = repmat(1./dr.ys(k1),1,length(klag1)).*dr.ghx(ik,iklag).* ...
|
||||||
repmat(dr.ys(klag1)',length(ik),1);
|
repmat(dr.ys(klag1)',length(ik),1);
|
||||||
|
dr.ghx(ik,illag) = repmat(1./dr.ys(k1),1,length(illag)).*dr.ghx(ik,illag)
|
||||||
end
|
end
|
||||||
dr.ghu(ik,:) = repmat(1./dr.ys(k1),1,M_.exo_nbr).*dr.ghu(ik,:);
|
if M_.exo_nbr > 0
|
||||||
|
dr.ghu(ik,:) = repmat(1./dr.ys(k1),1,M_.exo_nbr).*dr.ghu(ik,:);
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if ~isempty(il) && M_.nspred > 0
|
||||||
|
dr.ghx(il,iklag) = dr.ghx(il,iklag).*repmat(dr.ys(klag1)', ...
|
||||||
|
length(il),1);
|
||||||
end
|
end
|
||||||
if options_.order>1
|
if options_.order>1
|
||||||
error('Loglinear options currently only works at order 1')
|
error('Loglinear options currently only works at order 1')
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
function [il,l1,ik,k1] = indices_lagged_leaded_exogenous(k,M)
|
||||||
|
% returns indices of all endogenous variables split between auxiliary
|
||||||
|
% variables for lagged or leaded exogenous variables and all other ones
|
||||||
|
%
|
||||||
|
% INPUT
|
||||||
|
% k: vector of endogenous variables ID
|
||||||
|
% M: model structure
|
||||||
|
%
|
||||||
|
% OUTPUT
|
||||||
|
% il: indices of lagged or leaded variable in vector k
|
||||||
|
% l1: value of lagged or leaded variable in vector k
|
||||||
|
% ik: indices of non lagged or leaded variable in vector k
|
||||||
|
% k1: value of non lagged or leaded variable in vector k
|
||||||
|
|
||||||
|
% Copyright (C) 2011-2016 Dynare Team
|
||||||
|
%
|
||||||
|
% 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/>.
|
||||||
|
|
||||||
|
il = [];
|
||||||
|
l1 = [];
|
||||||
|
if isempty(M.aux_vars)
|
||||||
|
ik = 1:length(k);
|
||||||
|
k1 = k;
|
||||||
|
else
|
||||||
|
ik = [];
|
||||||
|
k1 = [];
|
||||||
|
orig_endo_nbr = M.orig_endo_nbr;
|
||||||
|
type = [M.aux_vars.type];
|
||||||
|
for j=1:length(k)
|
||||||
|
if (k(j) > orig_endo_nbr)
|
||||||
|
ty = type(k(j) - orig_endo_nbr);
|
||||||
|
if (ty ~= 2 & ty ~= 3)
|
||||||
|
ik = [ik; j];
|
||||||
|
k1 = [k1; k(j)];
|
||||||
|
else
|
||||||
|
il = [il; j];
|
||||||
|
l1 = [l1; k(j)];
|
||||||
|
end
|
||||||
|
else
|
||||||
|
ik = [ik; j];
|
||||||
|
k1 = [k1; k(j)]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,53 @@
|
||||||
|
function y = log_variable(ivar,x,M)
|
||||||
|
% returns the log of an endogenous variables except if
|
||||||
|
% it is a lagged/leaded exogenous variable
|
||||||
|
%
|
||||||
|
% INPUT
|
||||||
|
% ivar: vector of variable indices (in declaration order)
|
||||||
|
% x: vector of variables value
|
||||||
|
% M: model structure
|
||||||
|
%
|
||||||
|
% OUTPUT
|
||||||
|
% y: log of the selected variables if there are not auxiliary variables
|
||||||
|
% for lagged/leaded exogenous variables
|
||||||
|
%
|
||||||
|
|
||||||
|
% Copyright (C) 2011-2016 Dynare Team
|
||||||
|
%
|
||||||
|
% 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/>.
|
||||||
|
|
||||||
|
orig_endo_nbr = M.orig_endo_nbr;
|
||||||
|
aux_vars = M.aux_vars;
|
||||||
|
|
||||||
|
y = zeros(length(ivar),1);
|
||||||
|
for i = ivar(:)'
|
||||||
|
% Does ivar(i) refer to a lag/lead exogenous variable?
|
||||||
|
if ivar(i) > orig_endo_nbr
|
||||||
|
av = aux_vars(ivar(i) - orig_endo_nbr);
|
||||||
|
if av.type == 2 || av.type == 3
|
||||||
|
if av.endo_index ~= ivar(i)
|
||||||
|
error(['This case shouldn''t happen. Please, contact Dynare ' ...
|
||||||
|
'developers'])
|
||||||
|
else
|
||||||
|
y(i) = x(ivar(i));
|
||||||
|
end
|
||||||
|
else
|
||||||
|
y(i) = log(x(ivar(i)));
|
||||||
|
end
|
||||||
|
else
|
||||||
|
y(i) = log(x(ivar(i)));
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue