From f66e6a7f353de7f0c18c3c5f10d4dd32bff6bffa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Wed, 25 Sep 2019 12:00:40 +0200 Subject: [PATCH] Fix check for unused endos in the presence of PAC model-consistent expectations Since commit 64f55e4a5e5bd1dbc24f806f1b9c4b518f24eb8c, in the presence of PAC model-consistent expectations, some endogenous variables are added to the symbol table at the beginning of ModFile::transformPass(), while their defining equations are added at a later point. But commit 7c3f981eacdf7657aab0104cff6a028c93eb9549 has introduced a check that verifies that all endogenous are used in equations. That check happens after the above mentioned endogenous are created, but after their defining equations are added. Hence it fails. The fix consists in creating those endogenous after the check. Incidently, they are no longer part of the saved original model, but this is a good thing. --- src/ModFile.cc | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/ModFile.cc b/src/ModFile.cc index 1feca9ef..1eed44bb 100644 --- a/src/ModFile.cc +++ b/src/ModFile.cc @@ -397,21 +397,11 @@ ModFile::transformPass(bool nostrict, bool stochastic, bool compute_xrefs, const DataTree:AddDiff() */ dynamic_model.simplifyEquations(); - for (auto & statement : statements) - { - auto pms = dynamic_cast(statement.get()); - if (pms != nullptr) - { - if (pms->growth != nullptr) - pac_growth.push_back(pms->growth); - if (pms->aux_model_name == "") - dynamic_model.declarePacModelConsistentExpectationEndogs(pms->name); - } - } dynamic_model.substituteAdl(); dynamic_model.setLeadsLagsOrig(); original_model = dynamic_model; + // Check that all declared endogenous are used in equations set unusedEndogs = dynamic_model.findUnusedEndogenous(); bool unusedEndogsIsErr = !nostrict && !mod_file_struct.bvar_present && unusedEndogs.size(); for (int unusedEndog : unusedEndogs) @@ -427,6 +417,19 @@ ModFile::transformPass(bool nostrict, bool stochastic, bool compute_xrefs, const if (unusedEndogsIsErr) exit(EXIT_FAILURE); + // Declare endogenous used for PAC model-consistent expectations + for (auto & statement : statements) + { + auto pms = dynamic_cast(statement.get()); + if (pms != nullptr) + { + if (pms->growth != nullptr) + pac_growth.push_back(pms->growth); + if (pms->aux_model_name == "") + dynamic_model.declarePacModelConsistentExpectationEndogs(pms->name); + } + } + // Get all equation tags associated with VARs and Trend Component Models set eqtags; for (auto const & it : trend_component_model_table.getEqTags())