1) check for restricted or extened var list
2) allow proper working will all GSA type of sample: prior, MC, posteriortime-shift
parent
8655df67a9
commit
55b6d0eb93
|
@ -42,8 +42,7 @@ endo_prior_restrictions.irf= DynareOptions.endogenous_prior_restrictions.irf;
|
|||
endo_prior_restrictions.moment= DynareOptions.endogenous_prior_restrictions.moment;
|
||||
|
||||
if ~isempty(endo_prior_restrictions.irf),
|
||||
data_irf=cell(size(endo_prior_restrictions.irf,1),1);
|
||||
|
||||
data_irf=cell(size(endo_prior_restrictions.irf,1),1);
|
||||
if DynareOptions.order>1,
|
||||
error('The algorithm for prior (sign) restrictions on irf''s is currently restricted to first-order decision rules')
|
||||
return
|
||||
|
@ -53,7 +52,18 @@ if ~isempty(endo_prior_restrictions.irf),
|
|||
[T,R,SteadyState,infox,Model,DynareOptions,DynareResults] = dynare_resolve(Model,DynareOptions,DynareResults);
|
||||
else % check if T and R are given in the restricted form!!!
|
||||
if size(T,1)<size(varlist,1),
|
||||
varlist=varlist(DynareResults.dr.restrict_var_list,:);
|
||||
varlist=varlist(DynareResults.dr.restrict_var_list,:);
|
||||
end
|
||||
% check if endo_prior_restrictions.irf{:,1} variables are in varlist
|
||||
varlistok=1;
|
||||
for j=1:size(endo_prior_restrictions.irf,1)
|
||||
if isempty(strmatch(endo_prior_restrictions.irf{j,1},varlist,'exact'))
|
||||
varlistok=0;
|
||||
end
|
||||
end
|
||||
if ~varlistok
|
||||
varlist=Model.endo_names(DynareResults.dr.order_var,:);
|
||||
[T,R,SteadyState,infox,Model,DynareOptions,DynareResults] = dynare_resolve(Model,DynareOptions,DynareResults);
|
||||
end
|
||||
end
|
||||
NT=1;
|
||||
|
|
|
@ -26,16 +26,29 @@ indx_moment = [];
|
|||
skipline()
|
||||
disp('Sensitivity analysis for calibration criteria')
|
||||
|
||||
filetoload=[OutputDirectoryName '/' fname_ '_prior'];
|
||||
load(filetoload,'lpmat','lpmat0','istable','iunstable','iindeterm','iwrong' ,'infox')
|
||||
if ~isempty(lpmat0),
|
||||
lpmatx=lpmat0(istable,:);
|
||||
if DynareOptions.opt_gsa.ppost,
|
||||
filetoload=dir([Model.dname filesep 'metropolis' filesep fname_ '_param_irf*.mat']);
|
||||
lpmat=[];
|
||||
for j=1:length(filetoload),
|
||||
load([Model.dname filesep 'metropolis' filesep fname_ '_param_irf',int2str(j),'.mat'])
|
||||
lpmat = [lpmat; stock];
|
||||
clear stock
|
||||
end
|
||||
type = 'post';
|
||||
else
|
||||
lpmatx=[];
|
||||
if DynareOptions.opt_gsa.pprior
|
||||
filetoload=[OutputDirectoryName '/' fname_ '_prior'];
|
||||
load(filetoload,'lpmat','lpmat0','istable','iunstable','iindeterm','iwrong' ,'infox')
|
||||
lpmat = [lpmat0 lpmat];
|
||||
type = 'prior';
|
||||
else
|
||||
filetoload=[OutputDirectoryName '/' fname_ '_mc'];
|
||||
load(filetoload,'lpmat','lpmat0','istable','iunstable','iindeterm','iwrong' ,'infox')
|
||||
lpmat = [lpmat0 lpmat];
|
||||
type = 'mc';
|
||||
end
|
||||
end
|
||||
[Nsam, np] = size(lpmat);
|
||||
nshock = size(lpmat0,2);
|
||||
npT = np+nshock;
|
||||
|
||||
nbr_irf_restrictions = size(DynareOptions.endogenous_prior_restrictions.irf,1);
|
||||
mat_irf=cell(nbr_irf_restrictions,1);
|
||||
|
@ -51,7 +64,7 @@ end
|
|||
|
||||
irestrictions = [1:Nsam];
|
||||
for j=1:Nsam,
|
||||
Model = set_all_parameters([lpmat0(j,:) lpmat(j,:)]',EstimatedParameters,Model);
|
||||
Model = set_all_parameters(lpmat(j,:)',EstimatedParameters,Model);
|
||||
[Tt,Rr,SteadyState,info] = dynare_resolve(Model,DynareOptions,DynareResults,'restrict');
|
||||
if info(1)==0,
|
||||
[info, info_irf, info_moment, data_irf, data_moment]=endogenous_prior_restrictions(Tt,Rr,Model,DynareOptions,DynareResults);
|
||||
|
@ -72,12 +85,13 @@ for j=1:Nsam,
|
|||
end
|
||||
end
|
||||
irestrictions=irestrictions(find(irestrictions));
|
||||
xmat=[lpmat0(irestrictions,:) lpmat(irestrictions,:)];
|
||||
xmat=lpmat(irestrictions,:);
|
||||
skipline()
|
||||
save([OutputDirectoryName,filesep,fname_,'_',type,'_restrictions'],'xmat','mat_irf','mat_moment','irestrictions','indx_irf','indx_moment');
|
||||
|
||||
if ~isempty(indx_irf),
|
||||
indx_irf = indx_irf(irestrictions,:);
|
||||
h1=dyn_figure(DynareOptions,'name','Evaluation of irf restrictions');
|
||||
h1=dyn_figure(DynareOptions,'name',[type ' evaluation of irf restrictions']);
|
||||
nrow=ceil(sqrt(nbr_irf_restrictions));
|
||||
ncol=nrow;
|
||||
if nrow*(nrow-1)>nbr_irf_restrictions,
|
||||
|
@ -108,21 +122,21 @@ if ~isempty(indx_irf),
|
|||
indx2 = find(indx_irf(:,ij)~=0);
|
||||
atitle=[DynareOptions.endogenous_prior_restrictions.irf{ij,1},' vs ',DynareOptions.endogenous_prior_restrictions.irf{ij,2}, '(', leg,')'];
|
||||
fprintf(['%4.1f%% of the prior support matches IRF ',atitle,' inside [%4.1f, %4.1f]\n'],length(indx1)/length(irestrictions)*100,DynareOptions.endogenous_prior_restrictions.irf{ij,4})
|
||||
aname=['irf_calib_',int2str(ij)];
|
||||
atitle=['IRF Calib: Parameter(s) driving ',DynareOptions.endogenous_prior_restrictions.irf{ij,1},' vs ',DynareOptions.endogenous_prior_restrictions.irf{ij,2}, '(', leg,')'];
|
||||
aname=[type '_irf_calib_',int2str(ij)];
|
||||
atitle=[type ' IRF Calib: Parameter(s) driving ',DynareOptions.endogenous_prior_restrictions.irf{ij,1},' vs ',DynareOptions.endogenous_prior_restrictions.irf{ij,2}, '(', leg,')'];
|
||||
[proba, dproba] = stab_map_1(xmat, indx1, indx2, aname, 0);
|
||||
indplot=find(proba<pvalue_ks);
|
||||
if ~isempty(indplot)
|
||||
stab_map_1(xmat, indx1, indx2, aname, 1, indplot, OutputDirectoryName,[],atitle);
|
||||
end
|
||||
end
|
||||
dyn_saveas(h1,[OutputDirectoryName,filesep,fname_,'_irf_restrictions'],DynareOptions);
|
||||
dyn_saveas(h1,[OutputDirectoryName,filesep,fname_,'_',type,'_irf_restrictions'],DynareOptions);
|
||||
skipline()
|
||||
end
|
||||
|
||||
if ~isempty(indx_moment)
|
||||
indx_moment = indx_moment(irestrictions,:);
|
||||
h2=dyn_figure(DynareOptions,'name','Evaluation of moment restrictions');
|
||||
h2=dyn_figure(DynareOptions,'name',[type ' evaluation of moment restrictions']);
|
||||
nrow=ceil(sqrt(nbr_moment_restrictions));
|
||||
ncol=nrow;
|
||||
if nrow*(nrow-1)>nbr_moment_restrictions,
|
||||
|
@ -153,15 +167,15 @@ if ~isempty(indx_moment)
|
|||
indx2 = find(indx_moment(:,ij)~=0);
|
||||
atitle=[DynareOptions.endogenous_prior_restrictions.moment{ij,1},' vs ',DynareOptions.endogenous_prior_restrictions.moment{ij,2}, '(', leg,')'];
|
||||
fprintf(['%4.1f%% of the prior support matches MOMENT ',atitle,' inside [%4.1f, %4.1f]\n'],length(indx1)/length(irestrictions)*100,DynareOptions.endogenous_prior_restrictions.moment{ij,4})
|
||||
aname=['moment_calib_',int2str(ij)];
|
||||
atitle=['MOMENT Calib: Parameter(s) driving ',DynareOptions.endogenous_prior_restrictions.moment{ij,1},' vs ',DynareOptions.endogenous_prior_restrictions.moment{ij,2}, '(', leg,')'];
|
||||
aname=[type '_moment_calib_',int2str(ij)];
|
||||
atitle=[type ' MOMENT Calib: Parameter(s) driving ',DynareOptions.endogenous_prior_restrictions.moment{ij,1},' vs ',DynareOptions.endogenous_prior_restrictions.moment{ij,2}, '(', leg,')'];
|
||||
[proba, dproba] = stab_map_1(xmat, indx1, indx2, aname, 0);
|
||||
indplot=find(proba<pvalue_ks);
|
||||
if ~isempty(indplot)
|
||||
stab_map_1(xmat, indx1, indx2, aname, 1, indplot, OutputDirectoryName,[],atitle);
|
||||
end
|
||||
end
|
||||
dyn_saveas(h2,[OutputDirectoryName,filesep,fname_,'_moment_restrictions'],DynareOptions);
|
||||
dyn_saveas(h2,[OutputDirectoryName,filesep,fname_,'_',type,'_moment_restrictions'],DynareOptions);
|
||||
skipline()
|
||||
end
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue