From 3aaccc59e3589ded4b036dbc71a7c850205ca095 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?= Date: Thu, 24 Jun 2010 12:53:10 +0200 Subject: [PATCH] Changes related to the new interface for the dsge-var models. --- matlab/DsgeVarLikelihood.m | 6 ++---- matlab/check_list_of_variables.m | 2 +- matlab/dynare_estimation.m | 2 +- matlab/dynare_estimation_1.m | 34 +++++++++++++++--------------- matlab/dynare_estimation_init.m | 2 +- matlab/initial_estimation_checks.m | 2 +- matlab/mode_check.m | 4 ++-- matlab/print_info.m | 2 ++ 8 files changed, 27 insertions(+), 27 deletions(-) diff --git a/matlab/DsgeVarLikelihood.m b/matlab/DsgeVarLikelihood.m index d32fb0233..0a25e445b 100644 --- a/matlab/DsgeVarLikelihood.m +++ b/matlab/DsgeVarLikelihood.m @@ -1,5 +1,4 @@ function [fval,cost_flag,info,PHI,SIGMAu,iXX,prior] = DsgeVarLikelihood(xparam1,gend) -% function [fval,cost_flag,info,PHI,SIGMAu,iXX] = DsgeVarLikelihood(xparam1,gend) % Evaluates the posterior kernel of the bvar-dsge model. % % INPUTS @@ -46,7 +45,7 @@ nx = nvx+nvn+ncx+ncn+np; ns = nvx+nvn+ncx+ncn; NumberOfObservedVariables = size(options_.varobs,1); -NumberOfLags = options_.varlag; +NumberOfLags = options_.dsge_varlag; NumberOfParameters = NumberOfObservedVariables*NumberOfLags ; if ~options_.noconstant NumberOfParameters = NumberOfParameters + 1; @@ -83,7 +82,7 @@ for i=1:estim_params_.nvx end offset = estim_params_.nvx; if estim_params_.nvn - disp('DsgeVarLikelihood :: Measurement errors are implemented!') + disp('DsgeVarLikelihood :: Measurement errors are not implemented!') return end if estim_params_.ncx @@ -104,7 +103,6 @@ if dsge_prior_weight<(NumberOfParameters+NumberOfObservedVariables)/gend; return; end - %------------------------------------------------------------------------------ % 2. call model setup & reduction program %------------------------------------------------------------------------------ diff --git a/matlab/check_list_of_variables.m b/matlab/check_list_of_variables.m index 00ead8f42..2e7810468 100644 --- a/matlab/check_list_of_variables.m +++ b/matlab/check_list_of_variables.m @@ -32,7 +32,7 @@ function varlist = check_list_of_variables(options_, M_, varlist) % along with Dynare. If not, see . msg = 0; -if options_.bvar_dsge && options_.bayesian_irf +if options_.dsge_var && options_.bayesian_irf if ~isempty(varlist) for i=1:size(varlist,1) idx = strmatch(deblank(varlist(i,:)),options_.varobs,'exact'); diff --git a/matlab/dynare_estimation.m b/matlab/dynare_estimation.m index a4bff9e3e..5cccc34e2 100644 --- a/matlab/dynare_estimation.m +++ b/matlab/dynare_estimation.m @@ -32,7 +32,7 @@ global options_ oo_ M_ oo_recursive_ %% Decide if a DSGE or DSGE-VAR has to be estimated. if ~isempty(strmatch('dsge_prior_weight',M_.param_names)) - options_.bvar_dsge = 1; + options_.dsge_var = 1; end var_list = check_list_of_variables(options_, M_, var_list); diff --git a/matlab/dynare_estimation_1.m b/matlab/dynare_estimation_1.m index 1ff2b46ce..31d2da49a 100644 --- a/matlab/dynare_estimation_1.m +++ b/matlab/dynare_estimation_1.m @@ -331,7 +331,7 @@ end %% compute sample moments if needed (bvar-dsge) -if options_.bvar_dsge +if options_.dsge_var if options_.missing_data error('I cannot estimate a DSGE-VAR model with missing observations!') end @@ -339,12 +339,12 @@ if options_.bvar_dsge evalin('base',... ['[mYY,mXY,mYX,mXX,Ydata,Xdata] = ' ... 'var_sample_moments(options_.first_obs,' ... - 'options_.first_obs+options_.nobs-1,options_.varlag,-1,' ... + 'options_.first_obs+options_.nobs-1,options_.dsge_varlag,-1,' ... 'options_.datafile, options_.varobs,options_.xls_sheet,options_.xls_range);']) else% The steady state is non zero ==> a constant in the VAR is needed! evalin('base',['[mYY,mXY,mYX,mXX,Ydata,Xdata] = ' ... 'var_sample_moments(options_.first_obs,' ... - 'options_.first_obs+options_.nobs-1,options_.varlag,0,' ... + 'options_.first_obs+options_.nobs-1,options_.dsge_varlag,0,' ... 'options_.datafile, options_.varobs,options_.xls_sheet,options_.xls_range);']) end end @@ -391,7 +391,7 @@ end %% Estimation of the posterior mode or likelihood mode if options_.mode_compute > 0 & options_.posterior_mode_estimation - if ~options_.bvar_dsge + if ~options_.dsge_var fh=str2func('DsgeLikelihood'); else fh=str2func('DsgeVarLikelihood'); @@ -403,7 +403,7 @@ if options_.mode_compute > 0 & options_.posterior_mode_estimation if isfield(options_,'optim_opt') eval(['optim_options = optimset(optim_options,' options_.optim_opt ');']); end - if ~options_.bvar_dsge + if ~options_.dsge_var [xparam1,fval,exitflag,output,lamdba,grad,hessian_fmincon] = ... fmincon(fh,xparam1,[],[],[],[],lb,ub,[],optim_options,gend,data,data_index,number_of_observations,no_more_missing_observations); else @@ -417,7 +417,7 @@ if options_.mode_compute > 0 & options_.posterior_mode_estimation if isfield(options_,'optim_opt') eval(['optim_options = optimset(optim_options,' options_.optim_opt ');']); end - if ~options_.bvar_dsge + if ~options_.dsge_var [xparam1,fval,exitflag] = fminunc(fh,xparam1,optim_options,gend,data,data_index,number_of_observations,no_more_missing_observations); else [xparam1,fval,exitflag] = fminunc(fh,xparam1,optim_options,gend); @@ -427,7 +427,7 @@ if options_.mode_compute > 0 & options_.posterior_mode_estimation crit = 1e-7; nit = 1000; verbose = 2; - if ~options_.bvar_dsge + if ~options_.dsge_var [fval,xparam1,grad,hessian_csminwel,itct,fcount,retcodehat] = ... csminwel('DsgeLikelihood',xparam1,H0,[],crit,nit,options_.gradient_method,options_.gradient_epsilon,gend,data,data_index,number_of_observations,no_more_missing_observations); disp(sprintf('Objective function at mode: %f',fval)) @@ -459,7 +459,7 @@ if options_.mode_compute > 0 & options_.posterior_mode_estimation else nit=1000; end - if ~options_.bvar_dsge + if ~options_.dsge_var [xparam1,hh,gg,fval,invhess] = newrat('DsgeLikelihood',xparam1,hh,gg,igg,crit,nit,flag,gend,data,data_index,number_of_observations,no_more_missing_observations); else [xparam1,hh,gg,fval,invhess] = newrat('DsgeVarLikelihood',xparam1,hh,gg,igg,crit,nit,flag,gend); @@ -467,7 +467,7 @@ if options_.mode_compute > 0 & options_.posterior_mode_estimation parameter_names = bayestopt_.name; save([M_.fname '_mode.mat'],'xparam1','hh','gg','fval','invhess','parameter_names'); case 6 - if ~options_.bvar_dsge + if ~options_.dsge_var fval = DsgeLikelihood(xparam1,gend,data,data_index,number_of_observations,no_more_missing_observations); else fval = DsgeVarLikelihood(xparam1,gend); @@ -504,7 +504,7 @@ if options_.mode_compute > 0 & options_.posterior_mode_estimation else flag = 'LastCall'; end - if ~options_.bvar_dsge + if ~options_.dsge_var [xparam1,PostVar,Scale,PostMean] = ... gmhmaxlik('DsgeLikelihood',xparam1,bounds,options_.Opt6Numb,Scale,flag,MeanPar,CovJump,gend,data,... data_index,number_of_observations,no_more_missing_observations); @@ -526,7 +526,7 @@ if options_.mode_compute > 0 & options_.posterior_mode_estimation else flag = 'LastCall'; end - if ~options_.bvar_dsge + if ~options_.dsge_var [xparam1,PostVar,Scale,PostMean] = ... gmhmaxlik('DsgeLikelihood',xparam1,bounds,... options_.Opt6Numb,Scale,flag,PostMean,PostVar,gend,data,data_index,number_of_observations,no_more_missing_observations); @@ -553,7 +553,7 @@ if options_.mode_compute > 0 & options_.posterior_mode_estimation if isfield(options_,'optim_opt') eval(['optim_options = optimset(optim_options,' options_.optim_opt ');']); end - if ~options_.bvar_dsge + if ~options_.dsge_var [xparam1,fval,exitflag] = fminsearch(fh,xparam1,optim_options,gend,data,data_index,number_of_observations,no_more_missing_observations); else [xparam1,fval,exitflag] = fminsearch(fh,xparam1,optim_options,gend); @@ -602,7 +602,7 @@ if options_.mode_compute > 0 & options_.posterior_mode_estimation disp(['c vector ' num2str(c')]); % keyboard - if ~options_.bvar_dsge + if ~options_.dsge_var [xparam1, fval, nacc, nfcnev, nobds, ier, t, vm] = sa(fh,xparam1,maxy,rt_,eps,ns,nt ... ,neps,maxevl,LB,UB,c,idisp ,t,vm,gend,data,data_index,number_of_observations,no_more_missing_observations); else @@ -611,7 +611,7 @@ if options_.mode_compute > 0 & options_.posterior_mode_estimation end otherwise if ischar(options_.mode_compute) - if options_.bvar_dsge + if options_.dsge_var [xparam1, fval, retcode ] = feval(options_.mode_compute,fh,xparam1,gend,data); else [xparam1, fval, retcode ] = feval(options_.mode_compute, ... @@ -625,7 +625,7 @@ if options_.mode_compute > 0 & options_.posterior_mode_estimation % if options_.mode_compute ~= 5 if options_.mode_compute ~= 6 if options_.cova_compute == 1 - if ~options_.bvar_dsge + if ~options_.dsge_var hh = reshape(hessian('DsgeLikelihood',xparam1, ... options_.gstep,gend,data,data_index,number_of_observations,... no_more_missing_observations),nx,nx); @@ -777,7 +777,7 @@ if any(bayestopt_.pshape > 0) & options_.posterior_mode_estimation estim_params_nbr = size(xparam1,1); scale_factor = -sum(log10(diag(invhess))); log_det_invhess = -estim_params_nbr*log(scale_factor)+log(det(scale_factor*invhess)); - if ~options_.bvar_dsge + if ~options_.dsge_var md_Laplace = .5*estim_params_nbr*log(2*pi) + .5*log_det_invhess ... - DsgeLikelihood(xparam1,gend,data,data_index,number_of_observations,no_more_missing_observations); else @@ -1073,7 +1073,7 @@ if (any(bayestopt_.pshape >0 ) & options_.mh_replic) | ... if options_.load_mh_file & options_.use_mh_covariance_matrix invhess = compute_mh_covariance_matrix; end - if options_.bvar_dsge + if options_.dsge_var feval(options_.posterior_sampling_method,'DsgeVarLikelihood',options_.proposal_distribution,xparam1,invhess,bounds,gend); else feval(options_.posterior_sampling_method,'DsgeLikelihood',options_.proposal_distribution,xparam1,invhess,bounds,gend,data,... diff --git a/matlab/dynare_estimation_init.m b/matlab/dynare_estimation_init.m index 60f51fa7e..e1ea40ccb 100644 --- a/matlab/dynare_estimation_init.m +++ b/matlab/dynare_estimation_init.m @@ -48,7 +48,7 @@ for i = 1:size(M_.endo_names,1) end if ~isempty(strmatch('dsge_prior_weight',M_.param_names)) - options_.bvar_dsge = 1; + options_.dsge_var = 1; end if options_.order > 1 diff --git a/matlab/initial_estimation_checks.m b/matlab/initial_estimation_checks.m index 351952557..9a6468f62 100644 --- a/matlab/initial_estimation_checks.m +++ b/matlab/initial_estimation_checks.m @@ -54,7 +54,7 @@ if (number_of_observations==gend*nv)% No missing observations... end end -if ~isempty(strmatch('dsge_prior_weight',M_.param_names)) +if options_.dsge_var [fval,cost_flag,info] = DsgeVarLikelihood(xparam1,gend); else [fval,cost_flag,ys,trend_coeff,info] = DsgeLikelihood(xparam1,gend,data,data_index,number_of_observations,no_more_missing_observations); diff --git a/matlab/mode_check.m b/matlab/mode_check.m index f2936ef68..d7204c6ba 100644 --- a/matlab/mode_check.m +++ b/matlab/mode_check.m @@ -39,7 +39,7 @@ global bayestopt_ M_ options_ TeX = options_.TeX; [ s_min, k ] = min(diag(hessian)) ; -if options_.bvar_dsge +if options_.dsge_var fval = DsgeVarLikelihood(x,gend); else fval = DsgeLikelihood(x,gend,data,data_index,number_of_observations,no_more_missing_observations); @@ -87,7 +87,7 @@ for plt = 1:nbplt, end for i=1:length(z) xx(kk) = z(i); - if options_.bvar_dsge + if options_.dsge_var [fval,cost_flag] = DsgeVarLikelihood(xx,gend); if cost_flag y(i,1) = fval; diff --git a/matlab/print_info.m b/matlab/print_info.m index c997d97d5..9a20d5429 100644 --- a/matlab/print_info.m +++ b/matlab/print_info.m @@ -56,6 +56,8 @@ if ~noprint error('The steady state is complex.') case 30 error('Variance can''t be computed') + case 51 + error('You are estimating a DSGE-VAR model, but the value of the dsge prior weight is too low!') otherwise error('This case shouldn''t happen. Contact the authors of Dynare') end