From b58bbb8e84a8e27fa1780760406c21eb0e2d6e91 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Thu, 12 Dec 2019 16:03:59 +0100
Subject: [PATCH] Ramsey: do not warn if instruments are not defined in
 steady_state_model block

Closes: dynare#1677
---
 src/ComputingTasks.cc     | 15 +++++++++++++++
 src/ModelEquationBlock.cc | 14 ++++++++++----
 src/Statement.hh          |  2 ++
 3 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/src/ComputingTasks.cc b/src/ComputingTasks.cc
index bc0cebf6..28464a2c 100644
--- a/src/ComputingTasks.cc
+++ b/src/ComputingTasks.cc
@@ -786,6 +786,11 @@ RamseyModelStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsol
       (it != options_list.num_options.end() && it->second == "true")
       || mod_file_struct.order_option >= 3)
     mod_file_struct.k_order_solver = true;
+
+  // Fill list of instruments
+  if (auto it = options_list.symbol_list_options.find("instruments");
+      it != options_list.symbol_list_options.end())
+    mod_file_struct.instruments = it->second;
 }
 
 void
@@ -944,6 +949,11 @@ RamseyPolicyStatement::checkPass(ModFileStructure &mod_file_struct, WarningConso
       (it != options_list.num_options.end() && it->second == "true")
       || mod_file_struct.order_option >= 3)
     mod_file_struct.k_order_solver = true;
+
+  // Fill list of instruments
+  if (auto it = options_list.symbol_list_options.find("instruments");
+      it != options_list.symbol_list_options.end())
+    mod_file_struct.instruments = it->second;
 }
 
 void
@@ -1067,6 +1077,11 @@ DiscretionaryPolicyStatement::checkPass(ModFileStructure &mod_file_struct, Warni
       (it != options_list.num_options.end() && it->second == "true")
       || mod_file_struct.order_option >= 3)
     mod_file_struct.k_order_solver = true;
+
+  // Fill list of instruments
+  if (auto it = options_list.symbol_list_options.find("instruments");
+      it != options_list.symbol_list_options.end())
+    mod_file_struct.instruments = it->second;
 }
 
 void
diff --git a/src/ModelEquationBlock.cc b/src/ModelEquationBlock.cc
index 32867240..3f88da46 100644
--- a/src/ModelEquationBlock.cc
+++ b/src/ModelEquationBlock.cc
@@ -120,12 +120,18 @@ SteadyStateModel::checkPass(ModFileStructure &mod_file_struct, WarningConsolidat
       copy(symb_ids.begin(), symb_ids.end(), back_inserter(so_far_defined));
     }
 
-  set<int> orig_endogs = symbol_table.getOrigEndogenous();
-  for (int orig_endog : orig_endogs)
+  /* Check that all original endogous are defined (except the instruments of a
+     Ramsey model, since the steady_state_block should give the steady state
+     *conditional* to those instruments) */
+  set<int> should_be_defined = symbol_table.getOrigEndogenous();
+  if (mod_file_struct.ramsey_policy_present || mod_file_struct.ramsey_model_present)
+    for (const auto &s : mod_file_struct.instruments.getSymbols())
+      should_be_defined.erase(symbol_table.getID(s));
+  for (int v : should_be_defined)
     {
-      if (find(so_far_defined.begin(), so_far_defined.end(), orig_endog)
+      if (find(so_far_defined.begin(), so_far_defined.end(), v)
           == so_far_defined.end())
-        warnings << "WARNING: in the 'steady_state_model' block, variable '" << symbol_table.getName(orig_endog) << "' is not assigned a value" << endl;
+        warnings << "WARNING: in the 'steady_state_model' block, variable '" << symbol_table.getName(v) << "' is not assigned a value" << endl;
     }
 }
 
diff --git a/src/Statement.hh b/src/Statement.hh
index 3ea99130..b6d6eab3 100644
--- a/src/Statement.hh
+++ b/src/Statement.hh
@@ -129,6 +129,8 @@ public:
   bool write_latex_steady_state_model_present{false};
   //! Pac growth and discount
   set<int> pac_params;
+  //! Instruments if ramsey_model, ramsey_policy or discretionary_policy is present
+  SymbolList instruments;
 };
 
 class Statement
-- 
GitLab