Add example for system prior

(@stepan removed trailing spaces)
mr#1908
Johannes Pfeifer 2021-08-16 15:39:33 +02:00 committed by Stéphane Adjemian (Charybdis)
parent 8228a32d5c
commit cf6621187e
Signed by: stepan
GPG Key ID: 295C1FE89E17EB3C
9 changed files with 573 additions and 2 deletions

View File

@ -8,7 +8,8 @@ Bibliography
* Adjemian, Stéphane, Matthieu Darracq Parriès and Stéphane Moyen (2008): “Towards a monetary policy evaluation framework”, *European Central Bank Working Paper*, 942.
* Aguiar, Mark and Gopinath, Gita (2004): “Emerging Market Business Cycles: The Cycle is the Trend,” *NBER* Working Paper, 10734.
* Amisano, Gianni and Tristani, Oreste (2010): “Euro area inflation persistence in an estimated nonlinear DSGE model”, *Journal of Economic Dynamics and Control*, 34(10), 18371858.
* Andreasen, Martin M., Jesús Fernández-Villaverde, and Juan Rubio-Ramírez (2018): “The Pruned State-Space System for Non-Linear DSGE Models: Theory and Empirical Applications,” *Review of Economic Studies*, 85(1), pp. 1-49.
* Andreasen, Martin M., Jesús Fernández-Villaverde, and Juan Rubio-Ramírez (2018): “The Pruned State-Space System for Non-Linear DSGE Models: Theory and Empirical Applications,” *Review of Economic Studies*, 85(1), 1-49.
* Andrle, Michal and Miroslav Plašil (2018): “Econometrics with system priors,” *Economics Letters*, 172, 134-137.
* Andrews, Donald W.K (1991): “Heteroskedasticity and autocorrelation consistent covariance matrix estimation”, *Econometrica*, 59(3), 817858.
* Backus, David K., Patrick J. Kehoe, and Finn E. Kydland (1992): “International Real Business Cycles,” *Journal of Political Economy*, 100(4), 745775.
* Baxter, Marianne and Robert G. King (1999): “Measuring Business Cycles: Approximate Band-pass Filters for Economic Time Series,” *Review of Economics and Statistics*, 81(4), 575593.
@ -33,6 +34,7 @@ Bibliography
* Fernández-Villaverde, Jesús and Juan Rubio-Ramírez (2004): “Comparing Dynamic Equilibrium Economies to Data: A Bayesian Approach,” *Journal of Econometrics*, 123, 153187.
* Fernández-Villaverde, Jesús and Juan Rubio-Ramírez (2005): “Estimating Dynamic Equilibrium Economies: Linear versus Nonlinear Likelihood,” *Journal of Applied Econometrics*, 20, 891910.
* Ferris, Michael C. and Todd S. Munson (1999): “Interfaces to PATH 3.0: Design, Implementation and Usage”, *Computational Optimization and Applications*, 12(1), 207227.
* Galí, Jordi (2015): “Monetary Policy, Inflation, and the Business Cycle,” 2nd Edition, Princeton University Press, Princeton.
* Geweke, John (1992): “Evaluating the accuracy of sampling-based approaches to the calculation of posterior moments,” in J.O. Berger, J.M. Bernardo, A.P. Dawid, and A.F.M. Smith (eds.) Proceedings of the Fourth Valencia International Meeting on Bayesian Statistics, pp. 169194, Oxford University Press.
* Geweke, John (1999): “Using simulation methods for Bayesian econometric models: Inference, development and communication,” *Econometric Reviews*, 18(1), 173.
* Giovannini, Massimo, Philipp Pfeiffer, and Marco Ratto (2021), “Efficient and robust inference of models with occasionally binding constraints,” Working Papers 2021-03, Joint Research Centre, European Commission

View File

@ -51,6 +51,12 @@ description, please refer to the comments inside the files themselves.
Small open economy RBC model with shocks to the growth trend,
presented in *Aguiar and Gopinath (2004)*.
``Gali_2015.mod``
Basic New Keynesian model of *Galí (2015)*, Chapter 3 showing how to
i) use "system prior"-type prior restrictions as in *Andrle and Plašil (2018)*
and ii) run prior/posterior-functions.
``NK_baseline.mod``
Baseline New Keynesian Model estimated in *Fernández-Villaverde

184
examples/Gali_2015.mod Normal file
View File

@ -0,0 +1,184 @@
/*
* This file shows how to use "system prior"-type prior restrictions as in
* Michal Andrle/Miroslav Plašil (2018): "Econometrics with system priors",
* Economics Letters, 172, pp. 134-137 during estimation based on
* the baseline New Keynesian model of Jordi Galí (2015): Monetary Policy, Inflation,
* and the Business Cycle, Princeton University Press, Second Edition, Chapter 3
*
* THIS MOD-FILE REQUIRES DYNARE 4.5 OR HIGHER
*
* Notes:
* - The estimation will automatically take the Gali_2015_prior_restrictions.m into
* account, which has the required name and format
* - Estimation is based on simulated data
* - The file also shows how to use a prior/posterior-function
*
* This implementation was written by Johannes Pfeifer. In case you spot mistakes,
* email me at jpfeifer@gmx.de
*
* Please note that the following copyright notice only applies to this Dynare
*/
/*
* Copyright (C) 2021 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/>.
*/
var pi ${\pi}$ (long_name='inflation')
y_gap ${\tilde y}$ (long_name='output gap')
y_nat ${y^{nat}}$ (long_name='natural output') //(in contrast to the textbook defined in deviation from steady state)
y ${y}$ (long_name='output')
yhat ${\hat y}$ (long_name='output deviation from steady state')
r_nat ${r^{nat}}$ (long_name='natural interest rate')
i ${i}$ (long_name='nominal interrst rate')
n ${n}$ (long_name='hours worked')
nu ${\nu}$ (long_name='AR(1) monetary policy shock process')
a ${a}$ (long_name='AR(1) technology shock process')
z ${z}$ (long_name='AR(1) preference shock process')
p ${p}$ (long_name='price level')
w ${w}$ (long_name='nominal wage')
c ${c}$ (long_name='consumption')
;
varexo eps_a ${\varepsilon_a}$ (long_name='technology shock')
eps_nu ${\varepsilon_\nu}$ (long_name='monetary policy shock')
eps_z ${\varepsilon_z}$ (long_name='preference shock innovation')
;
parameters alppha ${\alpha}$ (long_name='capital share')
betta ${\beta}$ (long_name='discount factor')
rho_a ${\rho_a}$ (long_name='autocorrelation technology shock')
rho_nu ${\rho_{\nu}}$ (long_name='autocorrelation monetary policy shock')
rho_z ${\rho_{z}}$ (long_name='autocorrelation monetary demand shock')
siggma ${\sigma}$ (long_name='inverse EIS')
varphi ${\varphi}$ (long_name='inverse Frisch elasticity')
phi_pi ${\phi_{\pi}}$ (long_name='inflation feedback Taylor Rule')
phi_y ${\phi_{y}}$ (long_name='output feedback Taylor Rule')
eta ${\eta}$ (long_name='semi-elasticity of money demand')
epsilon ${\epsilon}$ (long_name='demand elasticity')
theta ${\theta}$ (long_name='Calvo parameter')
;
%----------------------------------------------------------------
% Parametrization, p. 67 and p. 113-115
%----------------------------------------------------------------
siggma = 1;
varphi = 5;
phi_pi = 1.5;
phi_y = 0.125;
theta = 3/4;
rho_nu =0.5;
rho_z = 0.5;
rho_a = 0.9;
betta = 0.99;
eta = 3.77; %footnote 11, p. 115
alppha = 1/4;
epsilon = 9;
%----------------------------------------------------------------
% First Order Conditions
%----------------------------------------------------------------
model(linear);
//Composite parameters
#Omega=(1-alppha)/(1-alppha+alppha*epsilon); %defined on page 60
#psi_n_ya=(1+varphi)/(siggma*(1-alppha)+varphi+alppha); %defined on page 62
#lambda=(1-theta)*(1-betta*theta)/theta*Omega; %defined on page 61
#kappa=lambda*(siggma+(varphi+alppha)/(1-alppha)); %defined on page 63
[name='New Keynesian Phillips Curve eq. (22)']
pi=betta*pi(+1)+kappa*y_gap;
[name='Dynamic IS Curve eq. (23)']
y_gap=-1/siggma*(i-pi(+1)-r_nat)+y_gap(+1);
[name='Interest Rate Rule eq. (26)']
i=phi_pi*pi+phi_y*yhat+nu;
[name='Definition natural rate of interest eq. (24)']
r_nat=-siggma*psi_n_ya*(1-rho_a)*a+(1-rho_z)*z;
[name='Definition natural output, eq. (20)']
y_nat=psi_n_ya*a;
[name='Definition output gap']
y_gap=y-y_nat;
[name='Monetary policy shock']
nu=rho_nu*nu(-1)+eps_nu;
[name='TFP shock']
a=rho_a*a(-1)+eps_a;
[name='Production function (eq. 14)']
y=a+(1-alppha)*n;
[name='Preference shock, p. 54']
z=rho_z*z(-1) - eps_z;
[name='Output deviation from steady state']
yhat=y-steady_state(y);
[name='Definition price level']
pi=p-p(-1);
[name='resource constraint, eq. (12)']
y=c;
[name='FOC labor, eq. (2)']
w-p=siggma*c+varphi*n;
end;
shocks;
var eps_nu = 0.0025^2; //1 standard deviation shock of 25 basis points, i.e. 1 percentage point annualized
end;
% simulate data
stoch_simul(periods=100,drop=0,irf=0) yhat;
% save data
datatomfile('sim_data',{'yhat'});
estimated_params;
theta,0.75,beta_pdf,0.5,0.1;
betta, beta_pdf, 0.993, 0.002;
alppha, beta_pdf, 0.25, 0.02;
end;
varobs yhat;
% Run prior function to get prior slope of the PC based on independent priors
hh=figure('Name','Slope of the Phillips Curve');
prior_function(function='Gali_2015_PC_slope');
PC_slope_vec=cell2mat(oo_.prior_function_results(:,1));
optimal_bandwidth = mh_optimal_bandwidth(PC_slope_vec,length(PC_slope_vec),0,'gaussian');
[density(:,1),density(:,2)] = kernel_density_estimate(PC_slope_vec,512,length(PC_slope_vec),optimal_bandwidth,'gaussian');
figure(hh)
subplot(3,1,1)
plot(density(:,1),density(:,2));
title('Prior')
% Run estimation with 1 observation to show effect of _prior_restriction .m
% on independent prior
estimation(datafile='sim_data',mode_compute=5,mh_replic=2001,mh_nblocks=1,diffuse_filter,nobs=1,mh_jscale=0.8);
posterior_function(function='Gali_2015_PC_slope');
PC_slope_vec=cell2mat(oo_.posterior_function_results(:,1));
optimal_bandwidth = mh_optimal_bandwidth(PC_slope_vec,length(PC_slope_vec),0,'gaussian');
[density(:,1),density(:,2)] = kernel_density_estimate(PC_slope_vec,512,length(PC_slope_vec),optimal_bandwidth,'gaussian');
figure(hh)
subplot(3,1,2)
plot(density(:,1),density(:,2));
title('Updated Prior')
% Run estimation with full observations
estimation(datafile='sim_data',mode_compute=5,mh_replic=2001,mh_nblocks=1,diffuse_filter,nobs=100,mh_jscale=0.8);
posterior_function(function='Gali_2015_PC_slope');
PC_slope_vec=cell2mat(oo_.posterior_function_results(:,1));
optimal_bandwidth = mh_optimal_bandwidth(PC_slope_vec,length(PC_slope_vec),0,'gaussian');
[density(:,1),density(:,2)] = kernel_density_estimate(PC_slope_vec,512,length(PC_slope_vec),optimal_bandwidth,'gaussian');
figure(hh)
subplot(3,1,3)
plot(density(:,1),density(:,2));
title('Posterior')

View File

@ -0,0 +1,56 @@
function output_cell =PC_slope(xparam1,M_,options_,oo_,estim_params_,bayestopt_,dataset_,dataset_info)
% output_cell =PC_slope(xparam1,M_,options_,oo_,estim_params_,bayestopt_,dataset_,dataset_info);
% This is an example file computing statistics on the prior/posterior draws. The
% function allows read-only access to all Dynare structures. However, those
% structures are local to this function. Changing them will not affect
% other Dynare functions and you cannot use them to pass results to other
% Dynare functions.
% The function takes one and only one output argument: an 1 by n cell.
% Using functions like cell2mat, the contents of the cell can be easily
% transformed back to matrices. See the fs2000_posterior_function.mod for
% an example
% INPUTS
% xparam1 Current parameter draw
% M_ [structure] Matlab's structure describing the Model (initialized by dynare, see @ref{M_}).
% options_ [structure] Matlab's structure describing the options (initialized by dynare, see @ref{options_}).
% oo_ [structure] Matlab's structure gathering the results (initialized by dynare, see @ref{oo_}).
% estim_params_[structure] Matlab's structure describing the estimated_parameters (initialized by dynare, see @ref{estim_params_}).
% bayestopt_ [structure] Matlab's structure describing the parameter options (initialized by dynare, see @ref{bayestopt_}).
% dataset_ [structure] Matlab's structure storing the dataset
% dataset_info [structure] Matlab's structure storing the information about the dataset
% Output
% output_cell [1 by n cell] 1 by n Matlab cell allowing to store any
% desired computation or result (strings, matrices, structures, etc.)
% Copyright (C) 2021 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/>.
%% store the slope based on the parameter draw
NumberOfParameters = M_.param_nbr;
for ii = 1:NumberOfParameters
paramname = deblank(M_.param_names{ii,:});
eval([ paramname ' = M_.params(' int2str(ii) ');']);
end
Omega=(1-alppha)/(1-alppha+alppha*epsilon);
lambda=(1-theta)*(1-betta*theta)/theta*Omega; %defined on page 61
output_cell{1,1}=lambda*(siggma+(varphi+alppha)/(1-alppha)); %defined on page 63
end

View File

@ -0,0 +1,40 @@
function log_prior_val=Gali_2015_prior_restrictions(M_, oo_, options_, dataset_, dataset_info);
% function prior_val=Gali_2015_prior_restrictions(M_, oo_, options_, dataset_, dataset_info);
% Example of a _prior_restrictions-file automatically called during
% estimation
% It imposes a prior of the slope of the New Keynesian Phillips Curve of
% 0.03. As the slope is a composite of other parameters with independent
% priors, a separate function is required to do this.
% Copyright (C) 2021 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 <https://www.gnu.org/licenses/>.
% read out parameters to access them with their name
NumberOfParameters = M_.param_nbr;
for ii = 1:NumberOfParameters
paramname = M_.param_names{ii};
eval([ paramname ' = M_.params(' int2str(ii) ');']);
end
Omega=(1-alppha)/(1-alppha+alppha*epsilon);
lambda=(1-theta)*(1-betta*theta)/theta*Omega; %defined on page 61
kappa=lambda*(siggma+(varphi+alppha)/(1-alppha)); %defined on page 63
prior_mean=0.03;
prior_std=0.02;
log_prior_val=log(normpdf(kappa,prior_mean,prior_std));

View File

@ -77,6 +77,7 @@ MODFILES = \
estimation/method_of_moments/AFVRR/AFVRR_M0.mod \
estimation/method_of_moments/AFVRR/AFVRR_MFB.mod \
estimation/method_of_moments/AFVRR/AFVRR_MFB_RRA.mod \
estimation/system_prior_restriction/Gali_2015.mod \
estimation/no_init_estimation_check_first_obs/fs2000_init_check.mod \
estimation/example_nls.mod \
moments/example1_var_decomp.mod \
@ -150,7 +151,7 @@ MODFILES = \
histval_initval_file/ramst_datafile.mod \
histval_initval_file/sim_exo_lead_lag.mod \
histval_initval_file/sim_exo_lead_lag_initvalf.mod \
ramst_normcdf_and_friends.mod \
ramst_normcdf_and_friends.mod \
ramst_vec.mod \
ramst_mshocks_vec.mod \
example1_varexo_det.mod \
@ -1243,6 +1244,8 @@ EXTRA_DIST = \
estimation/fsdat_simul.m \
estimation/heteroskedastic_shocks/fs2000_het_model.inc \
estimation/heteroskedastic_shocks/fs2000_het_check.inc \
estimation/system_prior_restriction/Gali_2015_PC_slope.m \
estimation/system_prior_restriction/Gali_2015_prior_restrictions.m \
ep/mean_preserving_spread.m \
ep/rbcii_steady_state.m \
decision_rules/example1_results_dyn_432.mat \

View File

@ -0,0 +1,184 @@
/*
* This file shows how to use "system prior"-type prior restrictions as in
* Michal Andrle/Miroslav Plašil (2018): "Econometrics with system priors",
* Economics Letters, 172, pp. 134-137 during estimation based on
* the baseline New Keynesian model of Jordi Galí (2015): Monetary Policy, Inflation,
* and the Business Cycle, Princeton University Press, Second Edition, Chapter 3
*
* THIS MOD-FILE REQUIRES DYNARE 4.5 OR HIGHER
*
* Notes:
* - The estimation will automatically take the Gali_2015_prior_restrictions.m into
* account, which has the required name and format
* - Estimation is based on simulated data
* - The file also shows how to use a prior/posterior-function
*
* This implementation was written by Johannes Pfeifer. In case you spot mistakes,
* email me at jpfeifer@gmx.de
*
* Please note that the following copyright notice only applies to this Dynare
*/
/*
* Copyright (C) 2021 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/>.
*/
var pi ${\pi}$ (long_name='inflation')
y_gap ${\tilde y}$ (long_name='output gap')
y_nat ${y^{nat}}$ (long_name='natural output') //(in contrast to the textbook defined in deviation from steady state)
y ${y}$ (long_name='output')
yhat ${\hat y}$ (long_name='output deviation from steady state')
r_nat ${r^{nat}}$ (long_name='natural interest rate')
i ${i}$ (long_name='nominal interrst rate')
n ${n}$ (long_name='hours worked')
nu ${\nu}$ (long_name='AR(1) monetary policy shock process')
a ${a}$ (long_name='AR(1) technology shock process')
z ${z}$ (long_name='AR(1) preference shock process')
p ${p}$ (long_name='price level')
w ${w}$ (long_name='nominal wage')
c ${c}$ (long_name='consumption')
;
varexo eps_a ${\varepsilon_a}$ (long_name='technology shock')
eps_nu ${\varepsilon_\nu}$ (long_name='monetary policy shock')
eps_z ${\varepsilon_z}$ (long_name='preference shock innovation')
;
parameters alppha ${\alpha}$ (long_name='capital share')
betta ${\beta}$ (long_name='discount factor')
rho_a ${\rho_a}$ (long_name='autocorrelation technology shock')
rho_nu ${\rho_{\nu}}$ (long_name='autocorrelation monetary policy shock')
rho_z ${\rho_{z}}$ (long_name='autocorrelation monetary demand shock')
siggma ${\sigma}$ (long_name='inverse EIS')
varphi ${\varphi}$ (long_name='inverse Frisch elasticity')
phi_pi ${\phi_{\pi}}$ (long_name='inflation feedback Taylor Rule')
phi_y ${\phi_{y}}$ (long_name='output feedback Taylor Rule')
eta ${\eta}$ (long_name='semi-elasticity of money demand')
epsilon ${\epsilon}$ (long_name='demand elasticity')
theta ${\theta}$ (long_name='Calvo parameter')
;
%----------------------------------------------------------------
% Parametrization, p. 67 and p. 113-115
%----------------------------------------------------------------
siggma = 1;
varphi = 5;
phi_pi = 1.5;
phi_y = 0.125;
theta = 3/4;
rho_nu =0.5;
rho_z = 0.5;
rho_a = 0.9;
betta = 0.99;
eta = 3.77; %footnote 11, p. 115
alppha = 1/4;
epsilon = 9;
%----------------------------------------------------------------
% First Order Conditions
%----------------------------------------------------------------
model(linear);
//Composite parameters
#Omega=(1-alppha)/(1-alppha+alppha*epsilon); %defined on page 60
#psi_n_ya=(1+varphi)/(siggma*(1-alppha)+varphi+alppha); %defined on page 62
#lambda=(1-theta)*(1-betta*theta)/theta*Omega; %defined on page 61
#kappa=lambda*(siggma+(varphi+alppha)/(1-alppha)); %defined on page 63
[name='New Keynesian Phillips Curve eq. (22)']
pi=betta*pi(+1)+kappa*y_gap;
[name='Dynamic IS Curve eq. (23)']
y_gap=-1/siggma*(i-pi(+1)-r_nat)+y_gap(+1);
[name='Interest Rate Rule eq. (26)']
i=phi_pi*pi+phi_y*yhat+nu;
[name='Definition natural rate of interest eq. (24)']
r_nat=-siggma*psi_n_ya*(1-rho_a)*a+(1-rho_z)*z;
[name='Definition natural output, eq. (20)']
y_nat=psi_n_ya*a;
[name='Definition output gap']
y_gap=y-y_nat;
[name='Monetary policy shock']
nu=rho_nu*nu(-1)+eps_nu;
[name='TFP shock']
a=rho_a*a(-1)+eps_a;
[name='Production function (eq. 14)']
y=a+(1-alppha)*n;
[name='Preference shock, p. 54']
z=rho_z*z(-1) - eps_z;
[name='Output deviation from steady state']
yhat=y-steady_state(y);
[name='Definition price level']
pi=p-p(-1);
[name='resource constraint, eq. (12)']
y=c;
[name='FOC labor, eq. (2)']
w-p=siggma*c+varphi*n;
end;
shocks;
var eps_nu = 0.0025^2; //1 standard deviation shock of 25 basis points, i.e. 1 percentage point annualized
end;
% simulate data
stoch_simul(periods=100,drop=0,irf=0) yhat;
% save data
datatomfile('sim_data',{'yhat'});
estimated_params;
theta,0.75,beta_pdf,0.5,0.1;
betta, beta_pdf, 0.993, 0.002;
alppha, beta_pdf, 0.25, 0.02;
end;
varobs yhat;
% Run prior function to get prior slope of the PC based on independent priors
hh=figure('Name','Slope of the Phillips Curve');
prior_function(function='Gali_2015_PC_slope');
PC_slope_vec=cell2mat(oo_.prior_function_results(:,1));
optimal_bandwidth = mh_optimal_bandwidth(PC_slope_vec,length(PC_slope_vec),0,'gaussian');
[density(:,1),density(:,2)] = kernel_density_estimate(PC_slope_vec,512,length(PC_slope_vec),optimal_bandwidth,'gaussian');
figure(hh)
subplot(3,1,1)
plot(density(:,1),density(:,2));
title('Prior')
% Run estimation with 1 observation to show effect of _prior_restriction .m
% on independent prior
estimation(datafile='sim_data',mode_compute=5,mh_replic=2001,mh_nblocks=1,diffuse_filter,nobs=1,mh_jscale=0.8);
posterior_function(function='Gali_2015_PC_slope');
PC_slope_vec=cell2mat(oo_.posterior_function_results(:,1));
optimal_bandwidth = mh_optimal_bandwidth(PC_slope_vec,length(PC_slope_vec),0,'gaussian');
[density(:,1),density(:,2)] = kernel_density_estimate(PC_slope_vec,512,length(PC_slope_vec),optimal_bandwidth,'gaussian');
figure(hh)
subplot(3,1,2)
plot(density(:,1),density(:,2));
title('Updated Prior')
% Run estimation with full observations
estimation(datafile='sim_data',mode_compute=5,mh_replic=2001,mh_nblocks=1,diffuse_filter,nobs=100,mh_jscale=0.8);
posterior_function(function='Gali_2015_PC_slope');
PC_slope_vec=cell2mat(oo_.posterior_function_results(:,1));
optimal_bandwidth = mh_optimal_bandwidth(PC_slope_vec,length(PC_slope_vec),0,'gaussian');
[density(:,1),density(:,2)] = kernel_density_estimate(PC_slope_vec,512,length(PC_slope_vec),optimal_bandwidth,'gaussian');
figure(hh)
subplot(3,1,3)
plot(density(:,1),density(:,2));
title('Posterior')

View File

@ -0,0 +1,56 @@
function output_cell =PC_slope(xparam1,M_,options_,oo_,estim_params_,bayestopt_,dataset_,dataset_info)
% output_cell =PC_slope(xparam1,M_,options_,oo_,estim_params_,bayestopt_,dataset_,dataset_info);
% This is an example file computing statistics on the prior/posterior draws. The
% function allows read-only access to all Dynare structures. However, those
% structures are local to this function. Changing them will not affect
% other Dynare functions and you cannot use them to pass results to other
% Dynare functions.
% The function takes one and only one output argument: an 1 by n cell.
% Using functions like cell2mat, the contents of the cell can be easily
% transformed back to matrices. See the fs2000_posterior_function.mod for
% an example
% INPUTS
% xparam1 Current parameter draw
% M_ [structure] Matlab's structure describing the Model (initialized by dynare, see @ref{M_}).
% options_ [structure] Matlab's structure describing the options (initialized by dynare, see @ref{options_}).
% oo_ [structure] Matlab's structure gathering the results (initialized by dynare, see @ref{oo_}).
% estim_params_[structure] Matlab's structure describing the estimated_parameters (initialized by dynare, see @ref{estim_params_}).
% bayestopt_ [structure] Matlab's structure describing the parameter options (initialized by dynare, see @ref{bayestopt_}).
% dataset_ [structure] Matlab's structure storing the dataset
% dataset_info [structure] Matlab's structure storing the information about the dataset
% Output
% output_cell [1 by n cell] 1 by n Matlab cell allowing to store any
% desired computation or result (strings, matrices, structures, etc.)
% Copyright (C) 2021 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/>.
%% store the slope based on the parameter draw
NumberOfParameters = M_.param_nbr;
for ii = 1:NumberOfParameters
paramname = deblank(M_.param_names{ii,:});
eval([ paramname ' = M_.params(' int2str(ii) ');']);
end
Omega=(1-alppha)/(1-alppha+alppha*epsilon);
lambda=(1-theta)*(1-betta*theta)/theta*Omega; %defined on page 61
output_cell{1,1}=lambda*(siggma+(varphi+alppha)/(1-alppha)); %defined on page 63
end

View File

@ -0,0 +1,40 @@
function log_prior_val=Gali_2015_prior_restrictions(M_, oo_, options_, dataset_, dataset_info);
% function prior_val=Gali_2015_prior_restrictions(M_, oo_, options_, dataset_, dataset_info);
% Example of a _prior_restrictions-file automatically called during
% estimation
% It imposes a prior of the slope of the New Keynesian Phillips Curve of
% 0.03. As the slope is a composite of other parameters with independent
% priors, a separate function is required to do this.
% Copyright (C) 2021 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 <https://www.gnu.org/licenses/>.
% read out parameters to access them with their name
NumberOfParameters = M_.param_nbr;
for ii = 1:NumberOfParameters
paramname = M_.param_names{ii};
eval([ paramname ' = M_.params(' int2str(ii) ');']);
end
Omega=(1-alppha)/(1-alppha+alppha*epsilon);
lambda=(1-theta)*(1-betta*theta)/theta*Omega; %defined on page 61
kappa=lambda*(siggma+(varphi+alppha)/(1-alppha)); %defined on page 63
prior_mean=0.03;
prior_std=0.02;
log_prior_val=log(normpdf(kappa,prior_mean,prior_std));