Commit 94d2b92c authored by Marco Ratto's avatar Marco Ratto
Browse files

new algorithm for weighted SD with occbin, where weights for the regime effect...

new algorithm for weighted SD with occbin, where weights for the regime effect are common to all variables and set based on target variable, e.g. shadow rate in the case of ZLB.
parent c98c221e
......@@ -236,13 +236,46 @@ deco_p(:,M_.exo_nbr+2,:)=as_p;
%deco_p(:,M_.exo_nbr+3,:)=as_p-reg_p;
oo_.occbin.smoother.decomp=deco_p;
rr=abs(deco_p(:,1:end-1,:));
if ~isempty(options_.occbin.shock_decomp.variable_for_computing_weights)
i_target = strmatch(options_.occbin.shock_decomp.variable_for_computing_weights,M_.endo_names,'exact');
else
i_target=[];
end
if ~isempty(i_target) && ~isempty(options_.occbin.shock_decomp.variable_for_computing_weights_lower_bound)
rr=deco_p(:,1:end-1,:);
tmp=squeeze(rr(i_target,:,:));
if options_.occbin.shock_decomp.variable_for_computing_weights_lower_bound
% lower bound, only consider shocks that have negative impact on the target
% variables
tmp(tmp>0)=0;
else
% upper bound, only consider shocks that have positive impact on the target
% variables
tmp(tmp<0)=0;
end
rr=abs(deco_p(:,1:end-1,:));
rr(i_target,:,:)=abs(tmp);
% % only consider shocks whose effect has the same sign as the regime
% % effect
% tmp=squeeze(rr(i_target,:,:));
% tmp0=sign(tmp(i_reg,:)); % check when regime effect is active
% tmp=tmp(:,find(tmp0));
% tmp(sign(tmp)~=sign(tmp(i_reg,:)))=0; %eliminate shocks with different sign
% rr(i_target,:,find(tmp0))=tmp;
end
if isequal(use_shock_groups,'ALL') && ~isempty(i_reg)
rr(:,i_reg,:)=0;
end
if ~isempty(options_.occbin.shock_decomp.exclude_shock_from_weights)
i_tmp = strmatch(options_.occbin.shock_decomp.exclude_shock_from_weights,M_.exo_names,'exact');
rr(:,i_tmp,:)=0;
end
ww=zeros(size(rr));
for k=1:size(rr,3)
tmp=sum(rr(:,:,k),2);
tmp(tmp<1.e-10)=1;
tmp(abs(tmp)<1.e-10)=1;
for g=1:size(rr,2)
ww(:,g,k) = rr(:,g,k)./tmp;
end
......@@ -254,7 +287,11 @@ end
for k=1:size(rr,3)
if any(any(reg_p(:,k)))
for g=1:size(rr,2)
wdeco_p(:,g,k) = wdeco_p(:,g,k)+reg_p(:,k).*ww(:,g,k);
if isempty(i_target)
wdeco_p(:,g,k) = wdeco_p(:,g,k)+reg_p(:,k).*ww(:,g,k);
else
wdeco_p(:,g,k) = wdeco_p(:,g,k)+reg_p(:,k).*ww(i_target,g,k);
end
end
end
end
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment