Commit 540f0454 authored by Johannes Pfeifer 's avatar Johannes Pfeifer

Code Review of GMM routines

- fix prefilter option
- Implement iterative GMM
parent a40807ca
......@@ -61,6 +61,7 @@ p = {'/distributions/' ; ...
'/cli/' ; ...
'/lmmcp/' ; ...
'/optimization/' ; ...
'/method_of_moments/' ; ...
'/discretionary_policy/' ; ...
'/accessors/' ; ...
'/modules/dseries/src/' ; ...
......
This diff is collapsed.
This diff is collapsed.
function [dataMoments, m_data] = method_of_moments_datamoments(data, DynareResults, MatchedMoments, OptionsMoM)
% [dataMoments, m_data] = method_of_moments_datamoments(data, DynareResults, MatchedMoments, OptionsMoM)
function [dataMoments, m_data] = method_of_moments_data_moments(data, oo_, matched_moments_, options_mom_)
% [dataMoments, m_data] = method_of_moments_data_moments(data, oo_, matched_moments_, options_mom_)
% This function computes the user-selected empirical moments from data
% =========================================================================
% INPUTS
% o data [T x varobs_nbr] data set
% o DynareResults: [structure] storage for results (oo_)
% o MatchedMoments: [structure] information about selected moments to match in estimation (matched_moments_)
% o OptionsMoM: [structure] information about all settings (specified by the user, preprocessor, and taken from global options_)
% o oo_: [structure] storage for results
% o matched_moments_: [structure] information about selected moments to match in estimation
% o options_mom_: [structure] information about all settings (specified by the user, preprocessor, and taken from global options_)
% -------------------------------------------------------------------------
% OUTPUTS
% o dataMoments [numMom x 1] mean of selected empirical moments
......@@ -40,28 +40,26 @@ function [dataMoments, m_data] = method_of_moments_datamoments(data, DynareResul
% Initialization
T = size(data,1); % Number of observations (T) and number of observables (ny)
mom_nbr = OptionsMoM.mom_nbr;
dataMoments = nan(mom_nbr,1);
m_data = nan(T,mom_nbr);
% Product moment for each time period, i.e. each row t contains yt1(l1)^p1*yt2(l2)^p2*...
dataMoments = NaN(options_mom_.mom_nbr,1);
m_data = NaN(T,options_mom_.mom_nbr);
% Product moment for each time period, i.e. each row t contains y_t1(l1)^p1*y_t2(l2)^p2*...
% note that here we already are able to treat leads and lags and any power product moments
for jm = 1:mom_nbr
vars = DynareResults.dr.inv_order_var(MatchedMoments{jm,1})';
leadlags = MatchedMoments{jm,2}; % note that lags are negative numbers and leads are positive numbers
powers = MatchedMoments{jm,3};
for jm = 1:options_mom_.mom_nbr
vars = oo_.dr.inv_order_var(matched_moments_{jm,1})';
leadlags = matched_moments_{jm,2}; % lags are negative numbers and leads are positive numbers
powers = matched_moments_{jm,3};
for jv = 1:length(vars)
jvar = DynareResults.dr.obs_var == vars(jv);
y = nan(T,1);
y( (1-min(leadlags(jv),0)) : (T-max(leadlags(jv),0)) , 1) = data( (1+max(leadlags(jv),0)) : (T+min(leadlags(jv),0)) , jvar).^powers(jv);
jvar = (oo_.dr.obs_var == vars(jv));
y = NaN(T,1); %Take care of T_eff instead of T for lags and NaN via nanmean below
y( (1-min(leadlags(jv),0)) : (T-max(leadlags(jv),0)), 1) = data( (1+max(leadlags(jv),0)) : (T+min(leadlags(jv),0)), jvar).^powers(jv);
if jv==1
m_data_tmp = y;
else
m_data_tmp = m_data_tmp.*y;
end
end
dataMoments(jm,1) = sum(m_data_tmp,'omitnan')/(T-sum(abs(leadlags)));
% We replace nan (due to leads and lags) with the corresponding mean
% @wmutschl: this should also work for missing values, right?
% We replace NaN (due to leads and lags and missing values) with the corresponding mean
dataMoments(jm,1) = mean(m_data_tmp,'omitnan');
m_data_tmp(isnan(m_data_tmp)) = dataMoments(jm,1);
m_data(:,jm) = m_data_tmp;
end
......
function method_of_moments_mode_check(fun,xparam,SE_vec,options_,M_,estim_params_,Bounds,bayestopt_,varargin)
% Checks the estimated ML mode or Posterior mode.
% Copyright (C) 2020 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/>.
TeX = options_.TeX;
if ~isempty(SE_vec)
[ s_min, k ] = min(SE_vec);
end
fval = feval(fun,xparam,varargin{:});
if ~isempty(SE_vec)
skipline()
disp('MODE CHECK')
skipline()
fprintf('Fval obtained by the minimization routine: %f', fval);
skipline()
if s_min<eps
fprintf('Most negative variance %f for parameter %d (%s = %f)', s_min, k , bayestopt_.name{k}, xparam(k))
end
end
[nbplt,nr,nc,lr,lc,nstar] = pltorg(length(xparam));
if ~exist([M_.fname filesep 'graphs'],'dir')
mkdir(M_.fname,'graphs');
end
if TeX && any(strcmp('eps',cellstr(options_.graph_format)))
fidTeX = fopen([M_.fname, '/graphs/', M_.fname '_MoMCheckPlots.tex'],'w');
fprintf(fidTeX,'%% TeX eps-loader file generated by method_of_moments_mode_check.m (Dynare).\n');
fprintf(fidTeX,['%% ' datestr(now,0) '\n']);
fprintf(fidTeX,' \n');
end
ll = options_.mode_check.neighbourhood_size;
if isinf(ll)
options_.mode_check.symmetric_plots = false;
end
mcheck = struct('cross',struct(),'emode',struct());
for plt = 1:nbplt
if TeX
NAMES = [];
TeXNAMES = [];
end
hh = dyn_figure(options_.nodisplay,'Name','Mode check plots');
for k=1:min(nstar,length(xparam)-(plt-1)*nstar)
subplot(nr,nc,k)
kk = (plt-1)*nstar+k;
[name,texname] = get_the_name(kk,TeX,M_,estim_params_,options_);
xx = xparam;
if xparam(kk)~=0 || ~isinf(Bounds.lb(kk)) || ~isinf(Bounds.lb(kk))
l1 = max(Bounds.lb(kk),(1-sign(xparam(kk))*ll)*xparam(kk)); m1 = 0; %lower bound
l2 = min(Bounds.ub(kk),(1+sign(xparam(kk))*ll)*xparam(kk)); %upper bound
else
%size info for 0 parameter is missing, use prior standard
%deviation
upper_bound=Bounds.lb(kk);
if isinf(upper_bound)
upper_bound=-1e-6*options_.huge_number;
end
lower_bound=Bounds.ub(kk);
if isinf(lower_bound)
lower_bound=-1e-6*options_.huge_number;
end
l1 = max(lower_bound,-bayestopt_.p2(kk)); m1 = 0; %lower bound
l2 = min(upper_bound,bayestopt_.p2(kk)); %upper bound
end
binding_lower_bound=0;
binding_upper_bound=0;
if isequal(xparam(kk),Bounds.lb(kk))
binding_lower_bound=1;
bound_value=Bounds.lb(kk);
elseif isequal(xparam(kk),Bounds.ub(kk))
binding_upper_bound=1;
bound_value=Bounds.ub(kk);
end
if options_.mode_check.symmetric_plots && ~binding_lower_bound && ~binding_upper_bound
if l2<(1+ll)*xparam(kk) %test whether upper bound is too small due to prior binding
l1 = xparam(kk) - (l2-xparam(kk)); %adjust lower bound to become closer
m1 = 1;
end
if ~m1 && (l1>(1-ll)*xparam(kk)) && (xparam(kk)+(xparam(kk)-l1)<Bounds.ub(kk)) % if lower bound was truncated and using difference from lower bound does not violate upper bound
l2 = xparam(kk) + (xparam(kk)-l1); %set upper bound to same distance as lower bound
end
end
z1 = l1:((xparam(kk)-l1)/(options_.mode_check.number_of_points/2)):xparam(kk);
z2 = xparam(kk):((l2-xparam(kk))/(options_.mode_check.number_of_points/2)):l2;
z = union(z1,z2);
if options_.mom.penalized_estimator
y = zeros(length(z),2);
dy=(xx-bayestopt_.p1)'/diag(bayestopt_.p2.^2)*(xx-bayestopt_.p1);
else
y = zeros(length(z),1);
end
for i=1:length(z)
xx(kk) = z(i);
[fval, info, exit_flag] = feval(fun,xx,varargin{:});
if exit_flag
y(i,1) = fval;
else
y(i,1) = NaN;
if options_.debug
fprintf('mode_check:: could not solve model for parameter %s at value %4.3f, error code: %u\n',name,z(i),info(1))
end
end
if options_.mom.penalized_estimator
prior=(xx-bayestopt_.p1)'/diag(bayestopt_.p2.^2)*(xx-bayestopt_.p1);
y(i,2) = (y(i,1)+prior-dy);
end
end
mcheck.cross = setfield(mcheck.cross, name, [transpose(z), -y]);
mcheck.emode = setfield(mcheck.emode, name, xparam(kk));
fighandle=plot(z,-y);
hold on
yl=get(gca,'ylim');
plot( [xparam(kk) xparam(kk)], yl, 'c', 'LineWidth', 1)
NaN_index = find(isnan(y(:,1)));
zNaN = z(NaN_index);
yNaN = yl(1)*ones(size(NaN_index));
plot(zNaN,yNaN,'o','MarkerEdgeColor','r','MarkerFaceColor','r','MarkerSize',6);
if TeX
title(texname,'interpreter','latex')
else
title(name,'interpreter','none')
end
axis tight
if binding_lower_bound || binding_upper_bound
xl=get(gca,'xlim');
plot( [bound_value bound_value], yl, 'r--', 'LineWidth', 1)
xlim([xl(1)-0.5*binding_lower_bound*(xl(2)-xl(1)) xl(2)+0.5*binding_upper_bound*(xl(2)-xl(1))])
end
hold off
drawnow
end
if options_.mom.penalized_estimator
if isoctave
axes('outerposition',[0.3 0.93 0.42 0.07],'box','on'),
else
axes('position',[0.3 0.01 0.42 0.05],'box','on'),
end
line_color=get(fighandle,'color');
plot([0.48 0.68],[0.5 0.5],'color',line_color{2})
hold on, plot([0.04 0.24],[0.5 0.5],'color',line_color{1})
set(gca,'xlim',[0 1],'ylim',[0 1],'xtick',[],'ytick',[])
text(0.25,0.5,'log-post')
text(0.69,0.5,'log-lik kernel')
end
dyn_saveas(hh,[M_.fname, '/graphs/', M_.fname '_MoMCheckPlots' int2str(plt) ],options_.nodisplay,options_.graph_format);
if TeX && any(strcmp('eps',cellstr(options_.graph_format)))
% TeX eps loader file
fprintf(fidTeX,'\\begin{figure}[H]\n');
fprintf(fidTeX,'\\centering \n');
fprintf(fidTeX,'\\includegraphics[width=%2.2f\\textwidth]{%_MoMCheckPlots%s}\n',options_.figures.textwidth*min(k/nc,1),[M_.fname, '/graphs/',M_.fname],int2str(plt));
fprintf(fidTeX,'\\caption{Method of Moments check plots.}');
fprintf(fidTeX,'\\label{Fig:MoMCheckPlots:%s}\n',int2str(plt));
fprintf(fidTeX,'\\end{figure}\n');
fprintf(fidTeX,' \n');
end
end
if TeX && any(strcmp('eps',cellstr(options_.graph_format)))
fclose(fidTeX);
end
OutputDirectoryName = CheckPath('modecheck',M_.dname);
save([OutputDirectoryName '/MoM_check_plot_data.mat'],'mcheck');
function Wopt = method_of_moments_optimal_weighting_matrix(m_data, moments, qLag)
% Wopt = method_of_moments_optimal_weighting_matrix(m_data, moments, qLag)
function [W_opt, normalization_factor]= method_of_moments_optimal_weighting_matrix(m_data, moments, q_lag)
% W_opt = method_of_moments_optimal_weighting_matrix(m_data, moments, q_lag)
% -------------------------------------------------------------------------
% This function computes the optimal weigthing matrix by a Bartlett kernel with maximum lag qlag
% This function computes the optimal weigthing matrix by a Bartlett kernel with maximum lag q_lag
% Adapted from replication codes of
% o Andreasen, Fernández-Villaverde, 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.
% o Andreasen, Fernndez-Villaverde, Rubio-Ramrez (2018): "The Pruned State-Space System for Non-Linear DSGE Models: Theory and Empirical Applications", Review of Economic Studies, 85(1):1-49.
% =========================================================================
% INPUTS
% o m_data [T x numMom] selected empirical or theoretical moments at each point in time
% o moments [numMom x 1] mean of selected empirical or theoretical moments
% o qlag [integer] Bartlett kernel maximum lag order
% o q_lag [integer] Bartlett kernel maximum lag order
% -------------------------------------------------------------------------
% OUTPUTS
% o Wopt [numMom x numMom] optimal weighting matrix
% o W_opt [numMom x numMom] optimal weighting matrix
% -------------------------------------------------------------------------
% This function is called by
% o method_of_moments.m
......@@ -42,45 +42,45 @@ function Wopt = method_of_moments_optimal_weighting_matrix(m_data, moments, qLag
% =========================================================================
% Initialize
[T,numMom] = size(m_data); %note that in m_data nan values (due to leads or lags in matchedmoments) are removed so T is the effective sample size
[T,num_Mom] = size(m_data); %note that in m_data NaN values (due to leads or lags in matched_moments and missing data) were replaced by the mean
% center around moments (could be either datamoments or modelmoments)
hFunc = m_data - repmat(moments',T,1);
% center around moments (could be either data_moments or model_moments)
h_Func = m_data - repmat(moments',T,1);
% The required correlation matrices
GAMA_array = zeros(numMom,numMom,qLag);
GAMA0 = CorrMatrix(hFunc,T,numMom,0);
if qLag > 0
for ii=1:qLag
GAMA_array(:,:,ii) = CorrMatrix(hFunc,T,numMom,ii);
GAMA_array = zeros(num_Mom,num_Mom,q_lag);
GAMA0 = Corr_Matrix(h_Func,T,num_Mom,0);
if q_lag > 0
for ii=1:q_lag
GAMA_array(:,:,ii) = Corr_Matrix(h_Func,T,num_Mom,ii);
end
end
% The estimate of S
S = GAMA0;
if qLag > 0
for ii=1:qLag
S = S + (1-ii/(qLag+1))*(GAMA_array(:,:,ii) + GAMA_array(:,:,ii)');
if q_lag > 0
for ii=1:q_lag
S = S + (1-ii/(q_lag+1))*(GAMA_array(:,:,ii) + GAMA_array(:,:,ii)');
end
end
% The estimate of W
Wopt = S\eye(size(S,1));
W_opt = S\eye(size(S,1));
% Check positive definite W
try
chol(Wopt);
chol(W_opt);
catch err
error('method_of_moments: The optimal weighting matrix is not positive definite. Check whether your model implies stochastic singularity\n')
error('method_of_moments: The optimal weighting matrix is not positive definite. Check whether your model implies stochastic singularity.\n')
end
end
% The correlation matrix
function GAMAcorr = CorrMatrix(hFunc,T,numMom,v)
GAMAcorr = zeros(numMom,numMom);
function GAMA_corr = Corr_Matrix(h_Func,T,num_Mom,v)
GAMA_corr = zeros(num_Mom,num_Mom);
for t = 1+v:T
GAMAcorr = GAMAcorr + hFunc(t-v,:)'*hFunc(t,:);
GAMA_corr = GAMA_corr + h_Func(t-v,:)'*h_Func(t,:);
end
GAMAcorr = GAMAcorr/T;
GAMA_corr = GAMA_corr/T;
end
\ No newline at end of file
function [SEvalues, AVar] = method_of_moments_standard_errors(xparam, objective_function, Bounds, DynareResults, EstimatedParameters, MatchedMoments, Model, OptionsMoM, Wopt_flag)
% [SEvalues, AVar] = method_of_moments_standard_errors(xparam, objective_function, Bounds, DynareResults, EstimatedParameters, MatchedMoments, Model, OptionsMoM, Wopt_flag)
function [SE_values, Asympt_Var] = method_of_moments_standard_errors(xparam, objective_function, Bounds, oo_, estim_params_, matched_moments_, M_, options_mom_, Wopt_flag)
% [SE_values, Asympt_Var] = method_of_moments_standard_errors(xparam, objective_function, Bounds, oo_, estim_params_, matched_moments_, M_, options_mom_, Wopt_flag)
% -------------------------------------------------------------------------
% This function computes standard errors to the method of moments estimates
% Adapted from replication codes of
% o Andreasen, Fernández-Villaverde, 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.
% o Andreasen, Fernndez-Villaverde, Rubio-Ramrez (2018): "The Pruned State-Space System for Non-Linear DSGE Models: Theory and Empirical Applications", Review of Economic Studies, 85(1):1-49.
% =========================================================================
% INPUTS
% o xparam: value of estimated parameters as returned by set_prior()
% o objective_function string of objective function, either method_of_moments_GMM.m or method_of_moments_SMM.m
% o Bounds: structure containing parameter bounds
% o DynareResults: structure for results (oo_)
% o EstimatedParameters: structure describing the estimated_parameters (estim_params_)
% o MatchedMoments: structure containing information about selected moments to match in estimation (matched_moments_)
% o Model structure describing the Model
% o OptionsMoM: structure information about all settings (specified by the user, preprocessor, and taken from global options_)
% o oo_: structure for results
% o estim_params_: structure describing the estimated_parameters
% o matched_moments_: structure containing information about selected moments to match in estimation
% o M_ structure describing the model
% o options_mom_: structure information about all settings (specified by the user, preprocessor, and taken from global options_)
% o Wopt_flag: indicator whether the optimal weighting is actually used
% -------------------------------------------------------------------------
% OUTPUTS
% o SEvalues [nparam x 1] vector of standard errors
% o AVar [nparam x nparam] asymptotic covariance matrix
% o SE_values [nparam x 1] vector of standard errors
% o Asympt_Var [nparam x nparam] asymptotic covariance matrix
% -------------------------------------------------------------------------
% This function is called by
% o method_of_moments.m
......@@ -26,8 +26,8 @@ function [SEvalues, AVar] = method_of_moments_standard_errors(xparam, objective_
% This function calls:
% o get_the_name
% o get_error_message
% o method_of_moments_GMM.m (objective function)
% o method_of_moments_SMM.m (objective function)
% o GMM_objective_function
% o SMM_objective_function.m
% o method_of_moments_optimal_weighting_matrix
% =========================================================================
% Copyright (C) 2020 Dynare Team
......@@ -53,53 +53,53 @@ function [SEvalues, AVar] = method_of_moments_standard_errors(xparam, objective_
% =========================================================================
% Some dimensions
numMom = size(DynareResults.mom.modelMoments,1);
dimParams = size(xparam,1);
D = zeros(numMom,dimParams);
epsValue = OptionsMoM.dynatol.x;
num_mom = size(oo_.mom.model_moments,1);
dim_params = size(xparam,1);
D = zeros(num_mom,dim_params);
eps_value = options_mom_.mom.se_tolx;
for i=1:dimParams
for i=1:dim_params
%Positive step
xparam_eps_p = xparam;
xparam_eps_p(i,1) = xparam_eps_p(i) + epsValue;
[~, info_p, exit_flag_p, DynareResults_p, ~, ~] = feval(objective_function, xparam_eps_p, Bounds, DynareResults, EstimatedParameters, MatchedMoments, Model, OptionsMoM);
xparam_eps_p(i,1) = xparam_eps_p(i) + eps_value;
[~, info_p, ~, ~,~, oo__p] = feval(objective_function, xparam_eps_p, Bounds, oo_, estim_params_, matched_moments_, M_, options_mom_);
% Negative step
xparam_eps_m = xparam;
xparam_eps_m(i,1) = xparam_eps_m(i) - epsValue;
[~, info_m, exit_flag_m, DynareResults_m, ~, ~] = feval(objective_function, xparam_eps_m, Bounds, DynareResults, EstimatedParameters, MatchedMoments, Model, OptionsMoM);
xparam_eps_m(i,1) = xparam_eps_m(i) - eps_value;
[~, info_m, ~, ~,~, oo__m] = feval(objective_function, xparam_eps_m, Bounds, oo_, estim_params_, matched_moments_, M_, options_mom_);
% The Jacobian:
if nnz(info_p)==0 && nnz(info_m)==0
D(:,i) = (DynareResults_p.mom.modelMoments - DynareResults_m.mom.modelMoments)/(2*epsValue);
D(:,i) = (oo__p.mom.model_moments - oo__m.mom.model_moments)/(2*eps_value);
else
problpar = get_the_name(i,OptionsMoM.TeX, Model, EstimatedParameters, OptionsMoM);
message_p = get_error_message(info_p, OptionsMoM);
message_m = get_error_message(info_m, OptionsMoM);
problpar = get_the_name(i,options_mom_.TeX, M_, estim_params_, options_mom_);
message_p = get_error_message(info_p, options_mom_);
message_m = get_error_message(info_m, options_mom_);
warning('method_of_moments:info','Cannot compute the Jacobian for parameter %s - no standard errors available\n %s %s\nCheck your bounds and/or priors, or use a different optimizer.\n',problpar, message_p, message_m)
AVar = NaN(length(xparam),length(xparam));
SEvalues = NaN(length(xparam),1);
Asympt_Var = NaN(length(xparam),length(xparam));
SE_values = NaN(length(xparam),1);
return
end
end
T = OptionsMoM.nobs; %Number of observations
if isfield(OptionsMoM,'variance_correction_factor')
T = T*OptionsMoM.variance_correction_factor;
T = options_mom_.nobs; %Number of observations
if isfield(options_mom_,'variance_correction_factor')
T = T*options_mom_.variance_correction_factor;
end
if Wopt_flag
% We have the optimal weighting matrix
WW = DynareResults.mom.Sw'*DynareResults.mom.Sw;
AVar = 1/T*((D'*WW*D)\eye(dimParams));
WW = oo_.mom.Sw'*oo_.mom.Sw;
Asympt_Var = 1/T*((D'*WW*D)\eye(dim_params));
else
% We do not have the optimal weighting matrix yet
WWused = DynareResults.mom.Sw'*DynareResults.mom.Sw;
WWopt = method_of_moments_optimal_weighting_matrix(DynareResults.mom.m_data, DynareResults.mom.modelMoments, OptionsMoM.bartlett_kernel_lag);
WWused = oo_.mom.Sw'*oo_.mom.Sw;
WWopt = method_of_moments_optimal_weighting_matrix(oo_.mom.m_data, oo_.mom.model_moments, options_mom_.mom.bartlett_kernel_lag);
S = WWopt\eye(size(WWopt,1));
AA = (D'*WWused*D)\eye(dimParams);
AVar = 1/T*AA*D'*WWused*S*WWused*D*AA;
AA = (D'*WWused*D)\eye(dim_params);
Asympt_Var = 1/T*AA*D'*WWused*S*WWused*D*AA;
end
SEvalues = sqrt(diag(AVar));
\ No newline at end of file
SE_values = sqrt(diag(Asympt_Var));
\ No newline at end of file
This diff is collapsed.
......@@ -25,6 +25,8 @@ MODFILES = \
measurement_errors/fs2000_corr_me_ml_mcmc/fs2000_corr_ME.mod \
TeX/fs2000_corr_ME.mod \
estimation/MH_recover/fs2000_recover_tarb.mod \
estimation/method_of_moments/RBC_MoM.mod \
estimation/method_of_moments/RBC_MoM_SMM_ME.mod \
estimation/fs2000.mod \
gsa/ls2003a.mod \
optimizers/fs2000_8.mod \
......@@ -961,6 +963,8 @@ EXTRA_DIST = \
lmmcp/sw-common-header.inc \
lmmcp/sw-common-footer.inc \
estimation/tune_mh_jscale/fs2000.inc \
estimation/method_of_moments/RBC_MoM_common.inc \
estimation/method_of_moments/RBC_MoM_steady_helper.m \
histval_initval_file_unit_tests.m \
histval_initval_file/my_assert.m \
histval_initval_file/ramst_data.xls \
......
......@@ -25,7 +25,7 @@
@#define estimParams = 1
% Note that we set the numerical optimization tolerance levels very large to speed up the testsuite
@#define optimizer = 1
@#define optimizer = 4
var c p R g y z INFL INT YGR;
varexo e_r e_g e_z;
......@@ -190,12 +190,12 @@ matched_moments_ = {
% Options for both GMM and SMM
% , bartlett_kernel_lag = 20 % bandwith in optimal weighting matrix
, order = @{orderApp} % order of Taylor approximation in perturbation
, order = @{orderApp} % order of Taylor approximation in perturbation
% , penalized_estimator % use penalized optimization
, pruning % use pruned state space system at higher-order
, pruning % use pruned state space system at higher-order
% , verbose % display and store intermediate estimation results
, weighting_matrix = OPTIMAL % weighting matrix in moments distance objective function; possible values: OPTIMAL|IDENTITY_MATRIX|DIAGONAL|filename
, mom_steps = [2 2] % vector of numbers for the iterations in the 2-step feasible method of moments
, weighting_matrix = OPTIMAL % weighting matrix in moments distance objective function; possible values: OPTIMAL|IDENTITY_MATRIX|DIAGONAL|filename
, additional_optimizer_steps = [4] % vector of numbers for the iterations in the 2-step feasible method of moments
% , prefilter=0 % demean each data series by its empirical mean and use centered moments
%
% Options for SMM
......
% RBC model used in replication files of
% Andreasen, Fernández-Villaverde, 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.
% Adapted by Willi Mutschler (@wmutschl, willi@mutschler.eu)
% =========================================================================
% Tests SMM and GMM routines
%
% Copyright (C) 2020 Dynare Team
%
% This file is part of Dynare.
......@@ -21,92 +19,72 @@
% =========================================================================
% Define testscenario
@#define orderApp = 3
@#define orderApp = 1
@#define estimParams = 1
% Note that we will set the numerical optimization tolerance levels very large to speed up the testsuite
@#define optimizer = 13
var k c a iv y la n rk w;
predetermined_variables k;
varexo u_a;
varobs n c iv;
parameters DELTA BETTA B ETAl ETAc THETA ALFA RHOA STDA;
DELTA = 0.025;
BETTA = 0.984;
B = 0.5;
ETAl = 1;
ETAc = 2;
THETA = 3.48;
ALFA = 0.667;
RHOA = 0.979;
STDA = 0.0072;
model;
0 = -exp(la) +(exp(c)-B*exp(c(-1)))^(-ETAc) - BETTA*B*(exp(c(+1))-B*exp(c))^(-ETAc);
0 = -THETA*(1-exp(n))^-ETAl + exp(la)*exp(w);
0 = -exp(la) + BETTA*exp(la(+1))*(exp(rk(+1)) + (1-DELTA));
0 = -exp(a)*(1-ALFA)*exp(k)^(-ALFA)*exp(n)^(ALFA) + exp(rk);
0 = -exp(a)*ALFA*exp(k)^(1-ALFA)*exp(n)^(ALFA-1) + exp(w);
0 = -exp(c) - exp(iv) + exp(y);
0 = -exp(y) + exp(a)*exp(k)^(1-ALFA)*exp(n)^(ALFA);
0 = -exp(k(+1)) + (1-DELTA)*exp(k) + exp(iv);
0 = -log(exp(a)) + RHOA*log(exp(a(-1))) + STDA*u_a;
end;
@#include "RBC_MoM_common.inc"
shocks;
var u_a = 1;
end;
var u_a; stderr 0.0072;
end;
varobs n c iv;
@#if estimParams == 0
estimated_params;
DELTA, 0.02;
BETTA, 0.9;
B, 0.4;
DELTA, 0.025;
BETTA, 0.98;
B, 0.45;
%ETAl, 1;
ETAc, 1.5;
ALFA, 0.6;
RHOA, 0.9;
STDA, 0.01;
ETAc, 1.8;
ALFA, 0.65;
RHOA, 0.95;
stderr u_a, 0.01;