Allow arbitrary nonzero mean exogenous variables in PAC equations.
Previously any nonzero mean exogenous variable had to be centered on the growth rate (first difference) of the (PAC's LHS) endogenous variable.var-model-with-constant
parent
d9298ca03a
commit
2b4572affd
|
@ -1,6 +1,17 @@
|
|||
function dummy = set(pacmodel, paceq, parameter, isnonzeromean)
|
||||
function dummy = set(pacmodel, paceq, variable, nonzeromean)
|
||||
|
||||
% Copyright (C) 2019 Dynare Team
|
||||
% Provide information about long run levels of exogenous variables in PAC equation.
|
||||
%
|
||||
% INPUTS
|
||||
% - pacmodel [char] 1×n array, name of the PAC model
|
||||
% - paceq [char] 1×m array, name of the PAC equation
|
||||
% - variable [char] 1×p array, name of the variable (exogenous variable in the PAC equation)
|
||||
% - nonzeromean [double] scalar, mean of the exogenous variable
|
||||
%
|
||||
% OUPUTS
|
||||
% - dummy [double] empty array.
|
||||
|
||||
% Copyright © 2019-2021 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
|
@ -22,39 +33,39 @@ global M_
|
|||
eqtag = M_.pac.(pacmodel).tag_map{strcmp(paceq, M_.pac.(pacmodel).tag_map(:,1)),2};
|
||||
|
||||
dummy = [];
|
||||
idp = find(strcmp(parameter, M_.param_names));
|
||||
if ~isempty(idp)
|
||||
ide = find(strcmp(variable, M_.endo_names));
|
||||
if ~isempty(ide)
|
||||
if isfield(M_.pac.(pacmodel).equations.(eqtag), 'additive') && length(M_.pac.(pacmodel).equations.(eqtag).additive.vars)>1
|
||||
if ~isfield(M_.pac.(pacmodel).equations.(eqtag).additive, 'bgp')
|
||||
M_.pac.(pacmodel).equations.(eqtag).additive.bgp = false(1, length(M_.pac.(pacmodel).equations.(eqtag).additive.params));
|
||||
M_.pac.(pacmodel).equations.(eqtag).additive.bgp = zeros(1, length(M_.pac.(pacmodel).equations.(eqtag).additive.params));
|
||||
end
|
||||
[isparam, ip] = ismember(idp, M_.pac.(pacmodel).equations.(eqtag).additive.params);
|
||||
if isparam
|
||||
M_.pac.(pacmodel).equations.(eqtag).additive.bgp(ip) = isnonzeromean;
|
||||
[isvar, ie] = ismember(ide, M_.pac.(pacmodel).equations.(eqtag).additive.vars);
|
||||
if isvar
|
||||
M_.pac.(pacmodel).equations.(eqtag).additive.bgp(ie) = nonzeromean;
|
||||
return
|
||||
end
|
||||
end
|
||||
if isfield(M_.pac.(pacmodel).equations.(eqtag), 'optim_additive')
|
||||
if ~isfield(M_.pac.(pacmodel).equations.(eqtag).optim_additive, 'bgp')
|
||||
M_.pac.(pacmodel).equations.(eqtag).optim_additive.bgp = false(1, length(M_.pac.(pacmodel).equations.(eqtag).optim_additive.params));
|
||||
M_.pac.(pacmodel).equations.(eqtag).optim_additive.bgp = zeros(1, length(M_.pac.(pacmodel).equations.(eqtag).optim_additive.params));
|
||||
end
|
||||
[isparam, ip] = ismember(idp, M_.pac.(pacmodel).equations.(eqtag).optim_additive.params);
|
||||
if isparam
|
||||
M_.pac.(pacmodel).equations.(eqtag).optim_additive.bgp(ip) = isnonzeromean;
|
||||
[isvar, ie] = ismember(ide, M_.pac.(pacmodel).equations.(eqtag).optim_additive.vars);
|
||||
if isvar
|
||||
M_.pac.(pacmodel).equations.(eqtag).optim_additive.bgp(ie) = nonzeromean;
|
||||
return
|
||||
end
|
||||
end
|
||||
if isfield(M_.pac.(pacmodel).equations.(eqtag), 'non_optimizing_behaviour')
|
||||
if ~isfield(M_.pac.(pacmodel).equations.(eqtag).non_optimizing_behaviour, 'bgp')
|
||||
M_.pac.(pacmodel).equations.(eqtag).non_optimizing_behaviour.bgp = false(1, length(M_.pac.(pacmodel).equations.(eqtag).non_optimizing_behaviour.params));
|
||||
M_.pac.(pacmodel).equations.(eqtag).non_optimizing_behaviour.bgp = zeros(1, length(M_.pac.(pacmodel).equations.(eqtag).non_optimizing_behaviour.params));
|
||||
end
|
||||
[isparam, ip] = ismember(idp, M_.pac.(pacmodel).equations.(eqtag).non_optimizing_behaviour.params);
|
||||
if isparam
|
||||
M_.pac.(pacmodel).equations.(eqtag).non_optimizing_behaviour.bgp(ip) = isnonzeromean;
|
||||
[isvar, ie] = ismember(ide, M_.pac.(pacmodel).equations.(eqtag).non_optimizing_behaviour.vars);
|
||||
if isvar
|
||||
M_.pac.(pacmodel).equations.(eqtag).non_optimizing_behaviour.bgp(ie) = nonzeromean;
|
||||
return
|
||||
end
|
||||
end
|
||||
warning('Parameter %s is not associated to an exogenous variable in equation %s.', parameter, paceq)
|
||||
warning('%s is not an exogenous variable in equation %s.', variable, paceq)
|
||||
else
|
||||
error('Parameter %s is unknown.', parameter)
|
||||
error('Endogenous variable %s is unknown.', variable)
|
||||
end
|
|
@ -167,9 +167,9 @@ for e=1:number_of_pac_eq
|
|||
tmp = 0;
|
||||
for i=1:length(equations.(eqtag).optim_additive.params)
|
||||
if isnan(equations.(eqtag).optim_additive.params(i)) && equations.(eqtag).optim_additive.bgp(i)
|
||||
tmp = tmp + equations.(eqtag).optim_additive.scaling_factor(i);
|
||||
tmp = tmp + equations.(eqtag).optim_additive.scaling_factor(i)*equations.(eqtag).optim_additive.bgp(i);
|
||||
elseif ~isnan(equations.(eqtag).optim_additive.params(i)) && equations.(eqtag).optim_additive.bgp(i)
|
||||
tmp = tmp + DynareModel.params(equations.(eqtag).optim_additive.params(i))*equations.(eqtag).optim_additive.scaling_factor(i);
|
||||
tmp = tmp + DynareModel.params(equations.(eqtag).optim_additive.params(i))*equations.(eqtag).optim_additive.scaling_factor(i)*equations.(eqtag).optim_additive.bgp(i);
|
||||
end
|
||||
end
|
||||
cc = cc - gamma*tmp;
|
||||
|
@ -180,9 +180,9 @@ for e=1:number_of_pac_eq
|
|||
tmp = 0;
|
||||
for i=1:length(equations.(eqtag).non_optimizing_behaviour.params)
|
||||
if isnan(equations.(eqtag).non_optimizing_behaviour.params(i)) && equations.(eqtag).non_optimizing_behaviour.bgp(i)
|
||||
tmp = tmp + equations.(eqtag).non_optimizing_behaviour.scaling_factor(i);
|
||||
tmp = tmp + equations.(eqtag).non_optimizing_behaviour.scaling_factor(i)*equations.(eqtag).non_optimizing_behaviour.bgp(i);
|
||||
elseif ~isnan(equations.(eqtag).non_optimizing_behaviour.params(i)) && equations.(eqtag).non_optimizing_behaviour.bgp(i)
|
||||
tmp = tmp + DynareModel.params(equations.(eqtag).non_optimizing_behaviour.params(i))*equations.(eqtag).non_optimizing_behaviour.scaling_factor(i);
|
||||
tmp = tmp + DynareModel.params(equations.(eqtag).non_optimizing_behaviour.params(i))*equations.(eqtag).non_optimizing_behaviour.scaling_factor(i)*equations.(eqtag).non_optimizing_behaviour.bgp(i);
|
||||
end
|
||||
end
|
||||
cc = cc - (1.0-gamma)*tmp;
|
||||
|
@ -193,9 +193,9 @@ for e=1:number_of_pac_eq
|
|||
tmp = 0;
|
||||
for i=1:length(equations.(eqtag).additive.params)
|
||||
if isnan(equations.(eqtag).additive.params(i)) && equations.(eqtag).additive.bgp(i)
|
||||
tmp = tmp + equations.(eqtag).additive.scaling_factor(i);
|
||||
tmp = tmp + equations.(eqtag).additive.scaling_factor(i)*equations.(eqtag).additive.bgp(i);
|
||||
elseif ~isnan(equations.(eqtag).additive.params(i)) && equations.(eqtag).additive.bgp(i)
|
||||
tmp = tmp + DynareModel.params(equations.(eqtag).additive.params(i))*equations.(eqtag).additive.scaling_factor(i);
|
||||
tmp = tmp + DynareModel.params(equations.(eqtag).additive.params(i))*equations.(eqtag).additive.scaling_factor(i)*equations.(eqtag).additive.bgp(i);
|
||||
end
|
||||
end
|
||||
cc = cc - tmp;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// --+ options: json=compute, stochastic +--
|
||||
|
||||
var x1 x2 x1bar x2bar z y x u v s;
|
||||
var x1 x2 x1bar x2bar z y x u v s dx2 dv;
|
||||
|
||||
varexo ex1 ex2 ex1bar ex2bar ez ey ex eu ev es;
|
||||
|
||||
|
@ -45,7 +45,7 @@ lambda = 0.5; // Share of optimizing agents.
|
|||
|
||||
trend_component_model(model_name=toto, eqtags=['eq:x1', 'eq:x2', 'eq:x1bar', 'eq:x2bar'], targets=['eq:x1bar', 'eq:x2bar']);
|
||||
|
||||
pac_model(auxiliary_model_name=toto, discount=beta, model_name=pacman);
|
||||
pac_model(auxiliary_model_name=toto, discount=beta, model_name=pacman, growth=.25*diff(x1(-1))+.25*diff(x1(-2))+.25*diff(x1(-3))+.25*diff(x1(-4)));
|
||||
|
||||
model;
|
||||
|
||||
|
@ -77,8 +77,11 @@ x1bar = x1bar(-1) + ex1bar;
|
|||
x2bar = x2bar(-1) + ex2bar;
|
||||
|
||||
[name='zpac']
|
||||
diff(z) = lambda*(e_c_m*(x1(-1)-z(-1)) + c_z_1*diff(z(-1)) + c_z_2*diff(z(-2)) + pac_expectation(pacman) + c_z_s*s + c_z_dv*diff(v) ) + (1-lambda)*( cy*y + cx*x) + c_z_u*u + c_z_dx2*diff(x2) + ez;
|
||||
diff(z) = lambda*(e_c_m*(x1(-1)-z(-1)) + c_z_1*diff(z(-1)) + c_z_2*diff(z(-2)) + pac_expectation(pacman) + c_z_s*s + c_z_dv*dv ) + (1-lambda)*( cy*y + cx*x) + c_z_u*u + c_z_dx2*dx2 + ez;
|
||||
|
||||
dx2 = diff(x2);
|
||||
|
||||
dv = diff(v);
|
||||
end;
|
||||
|
||||
shocks;
|
||||
|
@ -97,46 +100,46 @@ end;
|
|||
// Initialize the PAC model (build the Companion VAR representation for the auxiliary model).
|
||||
pac.initialize('pacman');
|
||||
|
||||
// Update the parameters of the PAC expectation model (h0 and h1 vectors).
|
||||
// Exogenous variables with non zero mean:
|
||||
pac.bgp.set('pacman', 'zpac', 's', .2);
|
||||
pac.bgp.set('pacman', 'zpac', 'x', .2);
|
||||
pac.bgp.set('pacman', 'zpac', 'dx2', .2);
|
||||
|
||||
// Update the parameters of the PAC expectation model (h0 and h1 vectors, growth neutrality correction).
|
||||
pac.update.expectation('pacman');
|
||||
|
||||
// Exogenous variables with non zero mean:
|
||||
pac.bgp.set('pacman', 'zpac', 'c_z_s', true);
|
||||
pac.bgp.set('pacman', 'zpac', 'cx', true);
|
||||
pac.bgp.set('pacman', 'zpac', 'c_z_dx2', true);
|
||||
|
||||
id = find(strcmp('c_z_s', M_.param_names));
|
||||
id = find(id==M_.pac.pacman.equations.eq0.additive.params);
|
||||
id = find(strcmp('s', M_.endo_names));
|
||||
id = find(id==M_.pac.pacman.equations.eq0.additive.vars);
|
||||
if ~pac.bgp.get('pacman', 'zpac', 'additive', id)
|
||||
error('bgp field in additive is wrong.')
|
||||
end
|
||||
|
||||
id = find(strcmp('c_z_dv', M_.param_names));
|
||||
id = find(id==M_.pac.pacman.equations.eq0.additive.params);
|
||||
id = find(strcmp('dv', M_.endo_names));
|
||||
id = find(id==M_.pac.pacman.equations.eq0.additive.vars);
|
||||
if pac.bgp.get('pacman', 'zpac', 'additive', id)
|
||||
error('bgp field in additive is wrong.')
|
||||
end
|
||||
|
||||
id = find(strcmp('cx', M_.param_names));
|
||||
id = find(id==M_.pac.pacman.equations.eq0.non_optimizing_behaviour.params);
|
||||
id = find(strcmp('x', M_.endo_names));
|
||||
id = find(id==M_.pac.pacman.equations.eq0.non_optimizing_behaviour.vars);
|
||||
if ~pac.bgp.get('pacman', 'zpac', 'non_optimizing_behaviour', id)
|
||||
error('bgp field in non_optimizing_behaviour is wrong.')
|
||||
end
|
||||
|
||||
id = find(strcmp('cy', M_.param_names));
|
||||
id = find(id==M_.pac.pacman.equations.eq0.non_optimizing_behaviour.params);
|
||||
id = find(strcmp('y', M_.endo_names));
|
||||
id = find(id==M_.pac.pacman.equations.eq0.non_optimizing_behaviour.vars);
|
||||
if pac.bgp.get('pacman', 'zpac', 'non_optimizing_behaviour', id)
|
||||
error('bgp field in non_optimizing_behaviour is wrong.')
|
||||
end
|
||||
|
||||
id = find(strcmp('c_z_dx2', M_.param_names));
|
||||
id = find(id==M_.pac.pacman.equations.eq0.optim_additive.params);
|
||||
id = find(strcmp('dx2', M_.endo_names));
|
||||
id = find(id==M_.pac.pacman.equations.eq0.optim_additive.vars);
|
||||
if ~pac.bgp.get('pacman', 'zpac', 'optim_additive', id)
|
||||
error('bgp field in optim_additive is wrong.')
|
||||
end
|
||||
|
||||
id = find(strcmp('c_z_u', M_.param_names));
|
||||
id = find(id==M_.pac.pacman.equations.eq0.additive.params);
|
||||
id = find(strcmp('u', M_.endo_names));
|
||||
id = find(id==M_.pac.pacman.equations.eq0.additive.vars);
|
||||
if pac.bgp.get('pacman', 'zpac', 'optim_additive', id)
|
||||
error('bgp field in optim_additive is wrong.')
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue