diff --git a/DynareBison.yy b/DynareBison.yy index 2967d612dd38be70c713f9d479f558d993206c75..342a59e1d18f5594d3202879e79ab035c36eae1e 100644 --- a/DynareBison.yy +++ b/DynareBison.yy @@ -929,7 +929,6 @@ estimated_elem1 : STDERR symbol } | DSGE_PRIOR_WEIGHT { - driver.declare_dsge_prior_weight(); driver.estim_params.type = 2; driver.estim_params.name = "dsge_prior_weight"; } diff --git a/ModFile.cc b/ModFile.cc index 249c0b07b013a5e0238c3479af669b0c03651d6b..8044fa1b193bfcad27a6da02b0e9a24ec9c6cdcc 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -153,13 +153,51 @@ ModFile::checkPass() exit(EXIT_FAILURE); } + if (symbol_table.exists("dsge_prior_weight")) + { + if (symbol_table.getType("dsge_prior_weight") != eParameter) + { + cerr << "ERROR: dsge_prior_weight may only be used as a parameter." << endl; + exit(EXIT_FAILURE); + } + else + cout << "WARNING: When estimating a DSGE-Var, declaring dsge_prior_weight as a parameter is deprecated. " + << "The preferred method is to do this via the dsge_var option in the estimation statement." << endl; + + if (mod_file_struct.dsge_var_estimated || !mod_file_struct.dsge_var_calibrated.empty()) + { + cerr << "ERROR: dsge_prior_weight can either be declared as a parameter (deprecated) or via the dsge_var option " + << "to the estimation statement (preferred), but not both." << endl; + exit(EXIT_FAILURE); + } + + if (!mod_file_struct.dsge_prior_weight_initialized && !mod_file_struct.dsge_prior_weight_in_estimated_params) + { + cerr << "ERROR: If dsge_prior_weight is declared as a parameter, it must either be initialized or placed in the " + << "estimated_params block." << endl; + exit(EXIT_FAILURE); + } + + if (mod_file_struct.dsge_prior_weight_initialized && mod_file_struct.dsge_prior_weight_in_estimated_params) + { + cerr << "ERROR: dsge_prior_weight cannot be both initalized and estimated." << endl; + exit(EXIT_FAILURE); + } + } + if (mod_file_struct.dsge_prior_weight_in_estimated_params) - if (!mod_file_struct.dsge_var_estimated) + if (!mod_file_struct.dsge_var_estimated && !mod_file_struct.dsge_var_calibrated.empty()) { - cerr << "ERROR: If dsge_prior_weight is in the estimated_params_block, the prior weight cannot be calibrated " + cerr << "ERROR: If dsge_prior_weight is in the estimated_params block, the prior weight cannot be calibrated " << "via the dsge_var option in the estimation statement." << endl; exit(EXIT_FAILURE); } + else if (!mod_file_struct.dsge_var_estimated && !symbol_table.exists("dsge_prior_weight")) + { + cerr << "ERROR: If dsge_prior_weight is in the estimated_params block, it must either be declared as a parameter " + << "(deprecated) or the dsge_var option must be passed to the estimation statement (preferred)." << endl; + exit(EXIT_FAILURE); + } } void @@ -183,12 +221,14 @@ ModFile::transformPass() dynamic_model.substituteExoLag(); } - if (!mod_file_struct.dsge_var_calibrated.empty()) + if (mod_file_struct.dsge_var_estimated || !mod_file_struct.dsge_var_calibrated.empty()) try { - addStatement(new InitParamStatement(symbol_table.addSymbol("dsge_prior_weight", eParameter), - expressions_tree.AddNumConstant(mod_file_struct.dsge_var_calibrated), - symbol_table)); + int sid = symbol_table.addSymbol("dsge_prior_weight", eParameter); + if (!mod_file_struct.dsge_var_calibrated.empty()) + addStatement(new InitParamStatement(sid, + expressions_tree.AddNumConstant(mod_file_struct.dsge_var_calibrated), + symbol_table)); } catch (SymbolTable::AlreadyDeclaredException &e) { @@ -215,21 +255,21 @@ ModFile::transformPass() cout << "Found " << dynamic_model.equation_number() << " equation(s)." << endl; - if (!mod_file_struct.dsge_var_calibrated.empty() || mod_file_struct.dsge_var_estimated) + if (symbol_table.exists("dsge_prior_weight")) if (mod_file_struct.bayesian_irf_present) { if (symbol_table.exo_nbr() != symbol_table.observedVariablesNbr()) { - cerr << "ERROR: If bayesian_irf and dsge_var are passed to the estimation statement, " - << "the number of shocks must equal the number of observed variables." << endl; + cerr << "ERROR: When estimating a DSGE-Var and the bayesian_irf option is passed to the estimation " + << "statement, the number of shocks must equal the number of observed variables." << endl; exit(EXIT_FAILURE); } } else if (symbol_table.exo_nbr() < symbol_table.observedVariablesNbr()) { - cerr << "ERROR: If dsge_var is passed to the estimation statement, the number of shocks " - << "must be greater than or equal to the number of observed variables." << endl; + cerr << "ERROR: When estimating a DSGE-Var, the number of shocks must be " + << "greater than or equal to the number of observed variables." << endl; exit(EXIT_FAILURE); } } diff --git a/NumericalInitialization.cc b/NumericalInitialization.cc index 357469ead5783306eec1f17e07855ba7267c57dc..fdf1a052e34e76b12ed3b9104fff0696ed1602f3 100644 --- a/NumericalInitialization.cc +++ b/NumericalInitialization.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2009 Dynare Team + * Copyright (C) 2003-2010 Dynare Team * * This file is part of Dynare. * @@ -32,6 +32,13 @@ InitParamStatement::InitParamStatement(int symb_id_arg, { } +void +InitParamStatement::checkPass(ModFileStructure &mod_file_struct) +{ + if (symbol_table.getName(symb_id) == "dsge_prior_weight") + mod_file_struct.dsge_prior_weight_initialized = true; +} + void InitParamStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/NumericalInitialization.hh b/NumericalInitialization.hh index f01e6436ab0a8918d5ca4d922385eadfa5428b03..e4d343e911cdb77a20974b2e57c34f47c90cebbb 100644 --- a/NumericalInitialization.hh +++ b/NumericalInitialization.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2009 Dynare Team + * Copyright (C) 2003-2010 Dynare Team * * This file is part of Dynare. * @@ -39,6 +39,7 @@ private: public: InitParamStatement(int symb_id_arg, const NodeID param_value_arg, const SymbolTable &symbol_table_arg); + virtual void checkPass(ModFileStructure &mod_file_struct); virtual void writeOutput(ostream &output, const string &basename) const; //! Fill eval context with parameter value void fillEvalContext(eval_context_type &eval_context) const; diff --git a/ParsingDriver.cc b/ParsingDriver.cc index 96549c33eb409a73b7c751df0d90f18a2d228114..17b875179605db546f260e46304018a6b293e74c 100644 --- a/ParsingDriver.cc +++ b/ParsingDriver.cc @@ -164,16 +164,6 @@ ParsingDriver::declare_parameter(string *name, string *tex_name) delete tex_name; } -void -ParsingDriver::declare_dsge_prior_weight() -{ - if (mod_file->symbol_table.exists("dsge_prior_weight")) - error("If dsge_prior_weight appears in the estimated_params block, it cannot have been previosly declared."); - - string *dsge_prior_weight = new string("dsge_prior_weight"); - declare_parameter(dsge_prior_weight); -} - void ParsingDriver::add_predetermined_variable(string *name) { @@ -893,10 +883,12 @@ ParsingDriver::check() void ParsingDriver::add_estimated_params_element() { - check_symbol_existence(estim_params.name); - if (estim_params.name2.size() > 0) - check_symbol_existence(estim_params.name2); - + if (estim_params.name != "dsge_prior_weight") + { + check_symbol_existence(estim_params.name); + if (estim_params.name2.size() > 0) + check_symbol_existence(estim_params.name2); + } estim_params_list.push_back(estim_params); estim_params.init(*data_tree); } diff --git a/ParsingDriver.hh b/ParsingDriver.hh index 91ef47433313320258ec691270a19c0d75962f1c..3acb8460c7c275ee0dab37df26c3b258a7437b69 100644 --- a/ParsingDriver.hh +++ b/ParsingDriver.hh @@ -212,8 +212,6 @@ public: void declare_exogenous_det(string *name, string *tex_name = NULL); //! Declares a parameter void declare_parameter(string *name, string *tex_name = NULL); - //! Declares dsge_prior_weight - void declare_dsge_prior_weight(); //! Adds a predetermined_variable void add_predetermined_variable(string *name); //! Declares and initializes a local parameter diff --git a/Statement.hh b/Statement.hh index 3e17a5de70f585923dcbc0c4f7130a0b4be46e82..e2b5e3efa503f055ce5741e16f165a4f053dec76 100644 --- a/Statement.hh +++ b/Statement.hh @@ -65,6 +65,8 @@ public: bool k_order_solver; //! Whether there is a calibrated measurement error bool calibrated_measurement_errors; + //! Whether dsge_prior_weight was initialized as a parameter + bool dsge_prior_weight_initialized; //! Whether dsge_prior_weight is in the estimated_params block bool dsge_prior_weight_in_estimated_params; //! Whether there is a dsge_var, with calibrated prior weight diff --git a/SymbolTable.cc b/SymbolTable.cc index b3e4ad12f65da9965fe76b095409fe44b0d4359b..91e1b6f4cf30c22bf31fb582f96274a61f31d076 100644 --- a/SymbolTable.cc +++ b/SymbolTable.cc @@ -201,6 +201,9 @@ SymbolTable::writeOutput(ostream &output) const throw (NotYetFrozenException) { output << "M_.param_names = strvcat(M_.param_names, '" << getName(param_ids[id]) << "');" << endl << "M_.param_names_tex = strvcat(M_.param_names_tex, '" << getTeXName(param_ids[id]) << "');" << endl; + + if (getName(param_ids[id]) == "dsge_prior_weight") + output << "options_.dsge_var = 1;" << endl; } }