From 2a24d1593d68c82bdd6dbaa0e94f68ac298b334c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Ry=C3=BBk=29?= <stepan@adjemian.eu> Date: Thu, 6 Jun 2024 15:44:54 +0200 Subject: [PATCH] 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. --- matlab/cherrypick.m | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/matlab/cherrypick.m b/matlab/cherrypick.m index ee10a86e0a..1aac16614c 100644 --- a/matlab/cherrypick.m +++ b/matlab/cherrypick.m @@ -1,4 +1,4 @@ -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) % and write them in outfile (mod file used for simulation). @@ -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. % - 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. +% - donotpicktarget [logical] Do not cherrypick auxiliary equation associated to the composite target. Default is false (equation is automagically cherrypicked). % % OUTPUTS % - json [char] Content of a JSON file. @@ -67,11 +68,16 @@ if nargin<5 || isempty(json) json = loadjson_(sprintf('%s/model/json/modfile-original.json', M_.dname)); end -if nargin<6 +if nargin<6 || isempty(substitutetarget) substitutetarget = false; % Otherwise substitute target expression (in case of composite target) in the error correction term 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. fid = fopen(sprintf('%s/model.inc', outfold), 'w'); @@ -248,10 +254,14 @@ try if substitutetarget RHS = strrep(RHS, sprintf('pac_target_nonstationary(model_name = %s)', ispac.name), targetexpr()); else - 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} = 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})); + if ~donotpicktarget + 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} = 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})); + 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 % Print equation for unrolled PAC/VAR-expectation and update @@ -342,8 +352,8 @@ try % Update lists of parameters, endogenous variables and exogenous variables. plist = union(plist, pnames); elist = union(elist, enames); - xlist = union(xlist, xnames); - end + xlist = union(xlist, xnames); + end catch e fclose(fid); fprintf(2, '%s\n', e.message) -- GitLab