Skip to content
Snippets Groups Projects
Verified Commit 2a24d159 authored by Stéphane Adjemian's avatar Stéphane Adjemian
Browse files

Add an option to decide if PAC equation target must be cherrypicked

The auxiliary equation for the composite target of the PAC equation is
cherrypicked unless the value of the (new) last argument is true.
parent 3bc4823c
Branches
No related tags found
No related merge requests found
function json = cherrypick(infile, outfold, eqtags, noresids, json, substitutetarget) function json = cherrypick(infile, outfold, eqtags, noresids, json, substitutetarget, donotpicktarget)
% Extract some equations in infile (mod file used for estimation) % Extract some equations in infile (mod file used for estimation)
% and write them in outfile (mod file used for simulation). % and write them in outfile (mod file used for simulation).
...@@ -10,6 +10,7 @@ function json = cherrypick(infile, outfold, eqtags, noresids, json, substituteta ...@@ -10,6 +10,7 @@ function json = cherrypick(infile, outfold, eqtags, noresids, json, substituteta
% - noresids [logical] Removes estimation residuals (not to be used in simulation) if true. % - noresids [logical] Removes estimation residuals (not to be used in simulation) if true.
% - json [char] Content of a JSON file. % - json [char] Content of a JSON file.
% - substitutetarget [logical] Substitute expression of a composite target in the error correction term of PAC equation if true. Default is false. % - substitutetarget [logical] Substitute expression of a composite target in the error correction term of PAC equation if true. Default is false.
% - donotpicktarget [logical] Do not cherrypick auxiliary equation associated to the composite target. Default is false (equation is automagically cherrypicked).
% %
% OUTPUTS % OUTPUTS
% - json [char] Content of a JSON file. % - json [char] Content of a JSON file.
...@@ -67,11 +68,16 @@ if nargin<5 || isempty(json) ...@@ -67,11 +68,16 @@ if nargin<5 || isempty(json)
json = loadjson_(sprintf('%s/model/json/modfile-original.json', M_.dname)); json = loadjson_(sprintf('%s/model/json/modfile-original.json', M_.dname));
end end
if nargin<6 if nargin<6 || isempty(substitutetarget)
substitutetarget = false; substitutetarget = false;
% Otherwise substitute target expression (in case of composite target) in the error correction term % Otherwise substitute target expression (in case of composite target) in the error correction term
end end
if nargin<7 || isempty(donotpicktarget)
donotpicktarget = false;
% By default the auxiliary equation for the target in PAC equation is cherrypicked
end
% Create a new file. % Create a new file.
fid = fopen(sprintf('%s/model.inc', outfold), 'w'); fid = fopen(sprintf('%s/model.inc', outfold), 'w');
...@@ -248,10 +254,14 @@ try ...@@ -248,10 +254,14 @@ try
if substitutetarget if substitutetarget
RHS = strrep(RHS, sprintf('pac_target_nonstationary(model_name = %s)', ispac.name), targetexpr()); RHS = strrep(RHS, sprintf('pac_target_nonstationary(model_name = %s)', ispac.name), targetexpr());
else else
if ~donotpicktarget
auxlhs{end+1} = M_.endo_names{M_.pac.(ispac.name).ec.vars(M_.pac.(ispac.name).ec.istarget)}; auxlhs{end+1} = M_.endo_names{M_.pac.(ispac.name).ec.vars(M_.pac.(ispac.name).ec.istarget)};
rhs{end+1} = M_.aux_vars(strmatch(auxlhs{end}, M_.endo_names, 'exact')==[M_.aux_vars(:).endo_index]).orig_expr; rhs{end+1} = M_.aux_vars(strmatch(auxlhs{end}, M_.endo_names, 'exact')==[M_.aux_vars(:).endo_index]).orig_expr;
rhs{end} = remove_aux_variables_from_expression(rhs{end}, M_); rhs{end} = remove_aux_variables_from_expression(rhs{end}, M_);
RHS = strrep(RHS, sprintf('pac_target_nonstationary(model_name = %s)', ispac.name), sprintf('%s(-1)', auxlhs{end})); RHS = strrep(RHS, sprintf('pac_target_nonstationary(model_name = %s)', ispac.name), sprintf('%s(-1)', auxlhs{end}));
else
RHS = strrep(RHS, sprintf('pac_target_nonstationary(model_name = %s)', ispac.name), sprintf('%s(-1)', M_.endo_names{M_.pac.(ispac.name).ec.vars(M_.pac.(ispac.name).ec.istarget)}));
end
end end
end end
% Print equation for unrolled PAC/VAR-expectation and update % Print equation for unrolled PAC/VAR-expectation and update
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment