diff --git a/matlab/dsge_likelihood.m b/matlab/dsge_likelihood.m index 40a7203c43bccbadad3245141b5f648dd480bd08..7ba2347852bd4b6c0c5471f03786aefa4e37f990 100644 --- a/matlab/dsge_likelihood.m +++ b/matlab/dsge_likelihood.m @@ -861,7 +861,7 @@ if DynareOptions.endogenous_prior==1 if DynareOptions.lik_init==2 || DynareOptions.lik_init==3 error('Endogenous prior not supported with non-stationary models') else - [lnpriormom] = endogenous_prior(Y,Pstar,BayesInfo,H); + [lnpriormom] = endogenous_prior(Y,DatasetInfo,Pstar,BayesInfo,H); fval = (likelihood-lnprior-lnpriormom); end else diff --git a/matlab/dynare_estimation_init.m b/matlab/dynare_estimation_init.m index c893be9c63ded305bbcf704a5a657a659ff91d21..bc8454ee2e04031e994734a651cda7d9d9c54bb4 100644 --- a/matlab/dynare_estimation_init.m +++ b/matlab/dynare_estimation_init.m @@ -555,6 +555,18 @@ end %set options for old interface from the ones for new interface if ~isempty(dataset_) options_.nobs = dataset_.nobs; + if options_.endogenous_prior + if dataset_info.missing.no_more_missing_observations<dataset_.nobs-10 + fprintf('\ndynare_estimation_init: There are missing observations in the data.\n') + fprintf('dynare_estimation_init: I am computing the moments for the endogenous prior only\n') + fprintf('dynare_estimation_init: on the observations after the last missing one, i.e. %u.\n',dataset_info.missing.no_more_missing_observations) + else + fprintf('\ndynare_estimation_init: There are too many missing observations in the data.\n') + fprintf('dynare_estimation_init: The endogenous_prior-option needs a consistent sample of \n') + fprintf('dynare_estimation_init: at least 10 full observations at the end.\n') + error('The endogenous_prior-option does not support your missing data.') + end + end end % setting steadystate_check_flag option diff --git a/matlab/endogenous_prior.m b/matlab/endogenous_prior.m index 26ea7ce5f5b9028f0ab68f28a0ca546e67f84278..5a192ad190eee360da4ed61061b6d50af8f5ffb9 100644 --- a/matlab/endogenous_prior.m +++ b/matlab/endogenous_prior.m @@ -1,8 +1,9 @@ -function [lnpriormom] = endogenous_prior(data,Pstar,BayesInfo,H) +function [lnpriormom] = endogenous_prior(data,dataset_info, Pstar,BayesInfo,H) % Computes the endogenous log prior addition to the initial prior % % INPUTS % data [double] n*T vector of data observations +% dataset_info [structure] various information about the dataset % Pstar [double] k*k matrix of % BayesInfo [structure] % @@ -11,7 +12,7 @@ function [lnpriormom] = endogenous_prior(data,Pstar,BayesInfo,H) % Code to implement notes on endogenous priors by Lawrence Christiano, % specified in the appendix of: -% Â’Introducing Financial Frictions and Unemployment into a Small Open Economy ModelÂ’ +% Introducing Financial Frictions and Unemployment into a Small Open Economy Model % by Lawrence J. Christiano, Mathias Trabandt and Karl Walentin (2011), Journal of Economic Dynamics and Control % this is the 'mother' of the priors on the model parameters. % the priors include a metric across some choosen moments of the (supposedly @@ -41,7 +42,8 @@ function [lnpriormom] = endogenous_prior(data,Pstar,BayesInfo,H) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. -Y=data'; +Y=data(:,dataset_info.missing.no_more_missing_observations:end)'; + [Tsamp,n]=size(Y); % sample length and number of matched moments (here set equal to nr of observables) hmat=zeros(n,Tsamp); @@ -85,4 +87,4 @@ Z=II(mf,:); Ftheta=diag(Z*Pstar(:,mf)+H); % below commented out line is for Del Negro Schorfheide style priors: % lnpriormom=-.5*n*TT*log(2*pi)-.5*TT*log(det(sigma))-.5*TT*trace(inv(sigma)*(gamyy-2*phi'*gamxy+phi'*gamxx*phi)); -lnpriormom=.5*n*log(Tsamp/(2*pi))-.5*log(det(Shat))-.5*Tsamp*(Fhat-Ftheta)'/Shat*(Fhat-Ftheta); +lnpriormom=.5*n*log(Tsamp/(2*pi))-.5*log(det(Shat))-.5*Tsamp*(Fhat-Ftheta)'/Shat*(Fhat-Ftheta); \ No newline at end of file