From 6e0a09f5faddaf7640ebf7f2fda7aeffdb799102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Ry=C3=BBk=29?= Date: Thu, 16 Mar 2023 13:46:33 +0100 Subject: [PATCH] Add interface to flip endogenous and exogenous variables. Calls to change_type can be done in a file named model-inversion-setup.inc in the current folder. The file is included, between the declaration of the exogenous variables and the model block, in the aggregate mod file if and only if the macrovariable InvertModel exists and is equal to True. To invert a model, the user just has to run the aggregated mod file with -DInvertModel=True on the command line. --- matlab/aggregate.m | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/matlab/aggregate.m b/matlab/aggregate.m index d77b3c986..ae3fc71e2 100644 --- a/matlab/aggregate.m +++ b/matlab/aggregate.m @@ -2,7 +2,7 @@ function aggregate(ofile, dynopt, rootfolder, varargin) % Agregates cherry-picked models. -% Copyright © 2019-2021 Dynare Team +% Copyright © 2019-2023 Dynare Team % % This file is part of Dynare. % @@ -263,6 +263,7 @@ end if ~isempty(firstline) fprintf(fid, '%s\n\n', firstline); end +% Print list of endogenous variables. fprintf(fid, 'var\n'); for i=1:rows(elist) if size(elist,2)==1 || isempty(elist{i,2}) @@ -272,15 +273,18 @@ for i=1:rows(elist) end end if ~isempty(plist) + % Print list of parameters. fprintf(fid, ';\n\n'); fprintf(fid, 'parameters\n'); for i=1:length(plist) fprintf(fid, '\t%s\n', plist{i}); end fprintf(fid, ';\n\n'); + % Print calibration. fprintf(fid, calibration); end if ~isempty(xlist) + % Print list of exogenous variables. fprintf(fid, '\n\n'); fprintf(fid, 'varexo\n'); for i=1:rows(xlist) @@ -291,7 +295,17 @@ if ~isempty(xlist) end end end -fprintf(fid, ';\n\n'); +fprintf(fid, ';\n'); +skipline(1, fid) +% Provide an interface to flip endogenous and exogenous variables. Active if only macrovariable +% InvertModel is set to True. The calls to the change_type command must be provided in the file +% model-inversion-setup.inc (in the current folder). +fprintf(fid, '@#ifdef InvertModel\n'); +fprintf(fid, ' @#if InvertModel\n'); +fprintf(fid, ' @#include "model-inversion-setup.inc"\n'); +fprintf(fid, ' @#endif\n'); +fprintf(fid, '@#endif\n'); +skipline(1, fid) fprintf(fid, 'model;\n\n'); for i=1:rows(eqlist) if isempty(eqlist{i,4})