Merge branch 'loglinear'
commit
2e1ad9c51b
|
@ -3611,7 +3611,11 @@ The convergence criterion used in the logarithmic reduction algorithm. Its defau
|
|||
The maximum number of iterations used in the logarithmic reduction algorithm. Its default value is 100.
|
||||
|
||||
@item loglinear
|
||||
@xref{loglinear}.
|
||||
@xref{loglinear}. Note that ALL variables are log-transformed by using the Jacobian transformation,
|
||||
not only selected ones. Thus, you have to make sure that your variables have strictly positive
|
||||
steady states. @code{stoch_simul} will display the moments, decision rules,
|
||||
and impulse responses for the log-linearized variables. The decision rules saved
|
||||
in @code{oo_.dr} and the simulated variables will also be the ones for the log-linear variables.
|
||||
|
||||
@end table
|
||||
|
||||
|
|
|
@ -65,23 +65,6 @@ gy_obs = dA*y/y(-1);
|
|||
gp_obs = (P/P(-1))*m(-1)/dA;
|
||||
end;
|
||||
|
||||
initval;
|
||||
k = 6;
|
||||
m = mst;
|
||||
P = 2.25;
|
||||
c = 0.45;
|
||||
e = 1;
|
||||
W = 4;
|
||||
R = 1.02;
|
||||
d = 0.85;
|
||||
n = 0.19;
|
||||
l = 0.86;
|
||||
y = 0.6;
|
||||
gy_obs = exp(gam);
|
||||
gp_obs = exp(-gam);
|
||||
dA = exp(gam);
|
||||
end;
|
||||
|
||||
shocks;
|
||||
var e_a; stderr 0.014;
|
||||
var e_m; stderr 0.005;
|
||||
|
|
|
@ -74,7 +74,7 @@ bayestopt_.mf = bayestopt_.smoother_mf;
|
|||
if options_.noconstant
|
||||
constant = zeros(nobs,1);
|
||||
else
|
||||
if options_.loglinear == 1
|
||||
if options_.loglinear
|
||||
constant = log(SteadyState(bayestopt_.mfys));
|
||||
else
|
||||
constant = SteadyState(bayestopt_.mfys);
|
||||
|
|
|
@ -170,19 +170,19 @@ for b=1:B
|
|||
horizon+maxlag,1);
|
||||
end
|
||||
yf(:,IdObs) = yf(:,IdObs)+(gend+[1-maxlag:horizon]')*trend_coeff';
|
||||
if options_.loglinear == 1
|
||||
if options_.loglinear
|
||||
yf = yf+repmat(log(SteadyState'),horizon+maxlag,1);
|
||||
else
|
||||
yf = yf+repmat(SteadyState',horizon+maxlag,1);
|
||||
end
|
||||
yf1 = forcst2(yyyy,horizon,dr,1);
|
||||
if options_.prefilter == 1
|
||||
if options_.prefilter
|
||||
yf1(:,IdObs,:) = yf1(:,IdObs,:)+ ...
|
||||
repmat(bayestopt_.mean_varobs',[horizon+maxlag,1,1]);
|
||||
end
|
||||
yf1(:,IdObs,:) = yf1(:,IdObs,:)+repmat((gend+[1-maxlag:horizon]')* ...
|
||||
trend_coeff',[1,1,1]);
|
||||
if options_.loglinear == 1
|
||||
if options_.loglinear
|
||||
yf1 = yf1 + repmat(log(SteadyState'),[horizon+maxlag,1,1]);
|
||||
else
|
||||
yf1 = yf1 + repmat(SteadyState',[horizon+maxlag,1,1]);
|
||||
|
|
|
@ -628,7 +628,7 @@ for i = 1:Size;
|
|||
|
||||
|
||||
|
||||
if options_.loglinear == 1
|
||||
if options_.loglinear
|
||||
error('log linear option is for the moment not supported in first order approximation for a block decomposed mode');
|
||||
% k = find(dr.kstate(:,2) <= M_.maximum_endo_lag+1);
|
||||
% klag = dr.kstate(k,[1 2]);
|
||||
|
|
|
@ -63,7 +63,12 @@ if (isnumeric(options_.mode_compute) && options_.mode_compute && options_.analyt
|
|||
analytic_derivation0=options_.analytic_derivation;
|
||||
options_.analytic_derivation=1;
|
||||
end
|
||||
|
||||
|
||||
if options_.logged_steady_state
|
||||
oo_.dr.ys=exp(oo_.dr.ys);
|
||||
oo_.steady_state=exp(oo_.steady_state);
|
||||
end
|
||||
|
||||
|
||||
if nnobs > 1
|
||||
for i=1:nnobs
|
||||
|
|
|
@ -388,7 +388,7 @@ if options_gsa.glue,
|
|||
gend = options_.nobs;
|
||||
rawdata = read_variables(options_.datafile,options_.varobs,[],options_.xls_sheet,options_.xls_range);
|
||||
rawdata = rawdata(options_.first_obs:options_.first_obs+gend-1,:);
|
||||
if options_.loglinear == 1
|
||||
if options_.loglinear
|
||||
rawdata = log(rawdata);
|
||||
end
|
||||
if options_.prefilter == 1
|
||||
|
|
|
@ -374,6 +374,7 @@ options_.lik_init = 1;
|
|||
options_.load_mh_file = 0;
|
||||
options_.logdata = 0;
|
||||
options_.loglinear = 0;
|
||||
options_.logged_steady_state = 0;
|
||||
options_.mh_conf_sig = 0.90;
|
||||
options_.prior_interval = 0.90;
|
||||
options_.mh_drop = 0.5;
|
||||
|
|
|
@ -97,11 +97,10 @@ else
|
|||
dr.ghx = dr.g_1(:,1:nspred);
|
||||
dr.ghu = dr.g_1(:,nspred+1:end);
|
||||
|
||||
if options.loglinear == 1
|
||||
if options.loglinear
|
||||
k = find(dr.kstate(:,2) <= M.maximum_endo_lag+1);
|
||||
klag = dr.kstate(k,[1 2]);
|
||||
k1 = dr.order_var;
|
||||
|
||||
dr.ghx = repmat(1./dr.ys(k1),1,size(dr.ghx,2)).*dr.ghx.* ...
|
||||
repmat(dr.ys(k1(klag(:,1)))',size(dr.ghx,1),1);
|
||||
dr.ghu = repmat(1./dr.ys(k1),1,size(dr.ghu,2)).*dr.ghu;
|
||||
|
|
|
@ -195,12 +195,12 @@ for b=fpar:B
|
|||
if horizon
|
||||
yyyy = alphahat(iendo,i_last_obs);
|
||||
yf = forcst2a(yyyy,dr,zeros(horizon,exo_nbr));
|
||||
if options_.prefilter == 1
|
||||
if options_.prefilter
|
||||
yf(:,IdObs) = yf(:,IdObs)+repmat(bayestopt_.mean_varobs', ...
|
||||
horizon+maxlag,1);
|
||||
end
|
||||
yf(:,IdObs) = yf(:,IdObs)+(gend+[1-maxlag:horizon]')*trend_coeff';
|
||||
if options_.loglinear == 1
|
||||
if options_.loglinear
|
||||
yf = yf+repmat(log(SteadyState'),horizon+maxlag,1);
|
||||
else
|
||||
yf = yf+repmat(SteadyState',horizon+maxlag,1);
|
||||
|
@ -212,7 +212,7 @@ for b=fpar:B
|
|||
end
|
||||
yf1(:,IdObs,:) = yf1(:,IdObs,:)+repmat((gend+[1-maxlag:horizon]')* ...
|
||||
trend_coeff',[1,1,1]);
|
||||
if options_.loglinear == 1
|
||||
if options_.loglinear
|
||||
yf1 = yf1 + repmat(log(SteadyState'),[horizon+maxlag,1,1]);
|
||||
else
|
||||
yf1 = yf1 + repmat(SteadyState',[horizon+maxlag,1,1]);
|
||||
|
|
|
@ -107,6 +107,30 @@ if info(1)
|
|||
return
|
||||
end
|
||||
|
||||
if options.loglinear
|
||||
% Find variables with non positive steady state.
|
||||
idx = find(dr.ys<1e-9);
|
||||
if length(idx)
|
||||
variables_with_non_positive_steady_state = M.endo_names(idx,:);
|
||||
skipline()
|
||||
fprintf('You are attempting to simulate/estimate a loglinear approximation of a model, but\n')
|
||||
fprintf('the steady state level of the following variables is not strictly positive:\n')
|
||||
for i=1:length(idx)
|
||||
fprintf(' - %s (%s)\n',deblank(variables_with_non_positive_steady_state(idx,:)), num2str(dr.ys(idx)))
|
||||
end
|
||||
if isestimation()
|
||||
fprintf('You should check that the priors and/or bounds over the deep parameters are such')
|
||||
frpintf('the steady state levels of all the variables are strictly positive, or consider')
|
||||
fprintf('a linearization of the model instead of a log linearization.')
|
||||
else
|
||||
fprintf('You should check that the calibration of the deep parameters is such that the')
|
||||
fprintf('steady state levels of all the variables are strictly positive, or consider')
|
||||
fprintf('a linearization of the model instead of a log linearization.')
|
||||
end
|
||||
error('stoch_simul::resol: The loglinearization of the model cannot be performed because the steady state is not strictly positive!')
|
||||
end
|
||||
end
|
||||
|
||||
if options.block
|
||||
[dr,info,M,options,oo] = dr_block(dr,check_flag,M,options,oo);
|
||||
else
|
||||
|
|
|
@ -77,9 +77,18 @@ elseif options_.discretionary_policy
|
|||
end
|
||||
[oo_.dr,ys,info] = discretionary_policy_1(oo_,options_.instruments);
|
||||
else
|
||||
if options_.logged_steady_state %if steady state was previously logged, undo this
|
||||
oo_.dr.ys=exp(oo_.dr.ys);
|
||||
oo_.steady_state=exp(oo_.steady_state);
|
||||
end
|
||||
[oo_.dr,info,M_,options_,oo_] = resol(0,M_,options_,oo_);
|
||||
end
|
||||
|
||||
if options_.loglinear %log steady state for correct display of decision rules and simulations
|
||||
oo_.dr.ys=log(oo_.dr.ys);
|
||||
oo_.steady_state=log(oo_.steady_state);
|
||||
options_old.logged_steady_state = 1;
|
||||
end
|
||||
if info(1)
|
||||
options_ = options_old;
|
||||
print_info(info, options_.noprint, options_);
|
||||
|
|
|
@ -297,22 +297,20 @@ if M_.exo_det_nbr > 0
|
|||
kron(hudi,Eud)+dr.ghxud{i-1}(kf,:)* ...
|
||||
kron(hudj,Eud)+dr.ghxx(kf,:)*kron(hudj,hudi))-M1*R2;
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if options_.loglinear == 1
|
||||
if options_.loglinear
|
||||
% this needs to be extended for order=2,3
|
||||
k = find(dr.kstate(:,2) <= M_.maximum_endo_lag+1);
|
||||
klag = dr.kstate(k,[1 2]);
|
||||
k1 = dr.order_var;
|
||||
|
||||
dr.ghx = repmat(1./dr.ys(k1),1,size(dr.ghx,2)).*dr.ghx.* ...
|
||||
repmat(dr.ys(k1(klag(:,1)))',size(dr.ghx,1),1);
|
||||
dr.ghu = repmat(1./dr.ys(k1),1,size(dr.ghu,2)).*dr.ghu;
|
||||
if options_.order>1
|
||||
error('Loglinear options currently only works at order 1')
|
||||
error('Loglinear options currently only works at order 1')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
function a = isestimation()
|
||||
|
||||
% Returns 1 if we are currently estimating a model, 0 otherwise.
|
||||
|
||||
% Copyright (C) 2014 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/>.
|
||||
|
||||
a = 0;
|
||||
|
||||
tmp = struct2cell(dbstack);
|
||||
list_of_previously_called_routines = transpose(tmp(2,:));
|
||||
|
||||
if ~isempty(strmatch('dsge_likelihood', list_of_previously_called_routines, 'exact')) || ...
|
||||
~isempty(strmatch('dsge_var_likelihood', list_of_previously_called_routines, 'exact')) || ...
|
||||
~isempty(strmatch('non_linear_dsge_likelihood', list_of_previously_called_routines, 'exact')) || ...
|
||||
~isempty(strmatch('simulated_moments_estimation', list_of_previously_called_routines, 'exact'))
|
||||
a = 1;
|
||||
end
|
|
@ -167,7 +167,8 @@ MODFILES = \
|
|||
gradient/fs2000_numgrad_3.mod \
|
||||
gradient/fs2000_numgrad_5.mod \
|
||||
filter_step_ahead/fs2000_filter_step_ahead_bayesian.mod \
|
||||
filter_step_ahead/fs2000_filter_step_ahead_ML.mod
|
||||
filter_step_ahead/fs2000_filter_step_ahead_ML.mod \
|
||||
loglinear/example4_loglinear.mod
|
||||
|
||||
XFAIL_MODFILES = ramst_xfail.mod \
|
||||
estim_param_in_shock_value.mod
|
||||
|
@ -327,7 +328,8 @@ EXTRA_DIST = \
|
|||
estimation/fs2000_MCMC_jumping_covariance_steadystate.m \
|
||||
estimation/fs2000_initialize_from_calib_steadystate.m \
|
||||
filter_step_ahead/fs2000_filter_step_ahead_bayesian_steadystate.m \
|
||||
filter_step_ahead/fs2000_filter_step_ahead_ML_steadystate.m
|
||||
filter_step_ahead/fs2000_filter_step_ahead_ML_steadystate.m \
|
||||
loglinear/results_exp.mat
|
||||
|
||||
TARGETS =
|
||||
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Example 1 from F. Collard (2001): "Stochastic simulations with DYNARE:
|
||||
* A practical guide" (see "guide.pdf" in the documentation directory).
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2001-2010 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 y, c, k, a, h, b;
|
||||
varexo e, u;
|
||||
|
||||
parameters beta, rho, alpha, delta, theta, psi, tau;
|
||||
|
||||
alpha = 0.36;
|
||||
rho = 0.95;
|
||||
tau = 0.025;
|
||||
beta = 0.99;
|
||||
delta = 0.025;
|
||||
psi = 0;
|
||||
theta = 2.95;
|
||||
|
||||
phi = 0.1;
|
||||
|
||||
model;
|
||||
exp(c)*theta*exp(h)^(1+psi)=(1-alpha)*exp(y);
|
||||
exp(k) = beta*(((exp(b)*exp(c))/(exp(b(+1))*exp(c(+1))))
|
||||
*(exp(b(+1))*alpha*exp(y(+1))+(1-delta)*exp(k)));
|
||||
exp(y) = exp(a)*(exp(k(-1))^alpha)*(exp(h)^(1-alpha));
|
||||
exp(k) = exp(b)*(exp(y)-exp(c))+(1-delta)*exp(k(-1));
|
||||
a = rho*a(-1)+tau*b(-1) + e;
|
||||
b = tau*a(-1)+rho*b(-1) + u;
|
||||
end;
|
||||
|
||||
initval;
|
||||
y = log(1.08068253095672);
|
||||
c = log(0.80359242014163);
|
||||
h = log(0.29175631001732);
|
||||
k = log(11.08360443260358);
|
||||
a = 0;
|
||||
b = 0;
|
||||
end;
|
||||
resid(1);
|
||||
shocks;
|
||||
var e; stderr 0.009;
|
||||
var u; stderr 0.009;
|
||||
var e, u = phi*0.009*0.009;
|
||||
end;
|
||||
|
||||
stoch_simul(order=1);
|
||||
oo_exp=oo_;
|
||||
save results_exp oo_exp
|
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
* Example 1 from F. Collard (2001): "Stochastic simulations with DYNARE:
|
||||
* A practical guide" (see "guide.pdf" in the documentation directory).
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2001-2010 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 y, c, k, a, h, b;
|
||||
varexo e, u;
|
||||
|
||||
parameters beta, rho, alpha, delta, theta, psi, tau;
|
||||
|
||||
alpha = 0.36;
|
||||
rho = 0.95;
|
||||
tau = 0.025;
|
||||
beta = 0.99;
|
||||
delta = 0.025;
|
||||
psi = 0;
|
||||
theta = 2.95;
|
||||
|
||||
phi = 0.1;
|
||||
|
||||
model;
|
||||
c*theta*h^(1+psi)=(1-alpha)*y;
|
||||
k = beta*(((b*c)/(b(+1)*c(+1)))
|
||||
*(b(+1)*alpha*y(+1)+(1-delta)*k));
|
||||
y = a*(k(-1)^alpha)*(h^(1-alpha));
|
||||
k = b*(y-c)+(1-delta)*k(-1);
|
||||
log(a) = rho*log(a(-1))+tau*log(b(-1)) + e;
|
||||
log(b) = tau*log(a(-1))+rho*log(b(-1)) + u;
|
||||
end;
|
||||
|
||||
initval;
|
||||
y = 1.08068253095672;
|
||||
c = 0.80359242014163;
|
||||
h = 0.29175631001732;
|
||||
k = 11.08360443260358;
|
||||
a = 1;
|
||||
b = 1;
|
||||
end;
|
||||
resid(1);
|
||||
shocks;
|
||||
var e; stderr 0.009;
|
||||
var u; stderr 0.009;
|
||||
var e, u = phi*0.009*0.009;
|
||||
end;
|
||||
|
||||
stoch_simul(loglinear,order=1);
|
||||
|
||||
load results_exp;
|
||||
if max(max(abs(oo_.dr.ghx-oo_exp.dr.ghx)))>1e-10
|
||||
error('Option loglinear wrong, ghx not equal')
|
||||
end
|
||||
if max(max(abs(oo_.dr.ghu-oo_exp.dr.ghu)))>1e-10
|
||||
error('Option loglinear wrong, ghu not equal')
|
||||
end
|
||||
if max(max(abs(oo_.irfs.y_e-oo_exp.irfs.y_e)))>1e-10
|
||||
error('Option loglinear wrong, IRFs not equal')
|
||||
end
|
||||
if max(max(abs(oo_.irfs.y_u-oo_exp.irfs.y_u)))>1e-10
|
||||
error('Option loglinear wrong, ghu not equal')
|
||||
end
|
||||
if max(max(abs(oo_.mean-oo_exp.mean)))>1e-10
|
||||
error('Option loglinear wrong, mean not equal')
|
||||
end
|
||||
if max(max(abs(oo_.dr.ys-oo_exp.dr.ys)))>1e-10
|
||||
error('Option loglinear wrong, ys not equal')
|
||||
end
|
||||
if max(max(abs(oo_.steady_state-oo_exp.steady_state)))>1e-10
|
||||
error('Option loglinear wrong, steady_state not equal')
|
||||
end
|
||||
|
||||
for ii=1:length(oo_.gamma_y)
|
||||
if max(max(abs(oo_.gamma_y{ii,1}-oo_exp.gamma_y{ii,1})))>1e-10
|
||||
error('Option loglinear wrong, moments not equal')
|
||||
end
|
||||
end
|
||||
|
||||
for ii=1:length(oo_.autocorr)
|
||||
if max(max(abs(oo_.autocorr{1,ii}-oo_exp.autocorr{1,ii})))>1e-10
|
||||
error('Option loglinear wrong, moments not equal')
|
||||
end
|
||||
end
|
||||
stoch_simul(loglinear,order=1,periods=100000);
|
||||
if abs(mean(y)-0.0776)>0.02
|
||||
error('Simulations are wrong')
|
||||
end
|
Binary file not shown.
Loading…
Reference in New Issue