preprocessor: add data command

issue#70
Houtan Bastani 2011-12-06 15:42:57 +01:00
parent b89eb4931c
commit 1c733dd55f
7 changed files with 109 additions and 2 deletions

View File

@ -325,6 +325,30 @@ EstimationStatement::checkPass(ModFileStructure &mod_file_struct)
cerr << "ERROR: An estimation statement cannot take more than one dsge_var option." << endl;
exit(EXIT_FAILURE);
}
if (options_list.string_options.find("datafile") == options_list.string_options.end() &&
!mod_file_struct.estimation_data_statement_present)
{
cerr << "ERROR: The estimation statement requires a data file to be supplied "
<< "either from the data statement or from the deprecated option datafile." << endl;
exit(EXIT_FAILURE);
}
if (options_list.string_options.find("datafile") != options_list.string_options.end())
cerr << "WARNING: The datafile option of estimation has been deprecated. "
<< "Use the data command instead." << endl;
if (options_list.string_options.find("xls_sheet") != options_list.string_options.end())
cerr << "WARNING: The xls_sheet option of estimation has been deprecated. "
<< "Use the data command instead." << endl;
if (options_list.string_options.find("xls_range") != options_list.string_options.end())
cerr << "WARNING: The xls_range option of estimation has been deprecated. "
<< "Use the data command instead." << endl;
if (options_list.num_options.find("first_obs") != options_list.num_options.end())
cerr << "WARNING: The first_obs option of estimation has been deprecated. "
<< "Use the data command instead." << endl;
}
void
@ -1442,3 +1466,36 @@ SetTimeStatement::writeOutput(ostream &output, const string &basename) const
{
options_list.writeOutput(output);
}
EstimationDataStatement::EstimationDataStatement(const OptionsList &options_list_arg) :
options_list(options_list_arg)
{
}
void
EstimationDataStatement::checkPass(ModFileStructure &mod_file_struct)
{
mod_file_struct.estimation_data_statement_present = true;
OptionsList::num_options_t::const_iterator it = options_list.num_options.find("nobs");
if (it != options_list.num_options.end())
if (atoi(it->second.c_str()) <= 0)
{
cerr << "ERROR: The nobs option of the data statement only accepts positive integers." << endl;
exit(EXIT_FAILURE);
}
if (options_list.string_options.find("file") == options_list.string_options.end())
{
cerr << "ERROR: The file option must be passed to the data statement." << endl;
exit(EXIT_FAILURE);
}
}
void
EstimationDataStatement::writeOutput(ostream &output, const string &basename) const
{
options_list.writeOutput(output, "options_.dataset");
if (options_list.date_options.find("first_obs") == options_list.date_options.end())
output << "options_.dataset.firstobs = options_.initial_period;" << endl;
}

View File

@ -565,5 +565,15 @@ public:
virtual void writeOutput(ostream &output, const string &basename) const;
};
class EstimationDataStatement : public Statement
{
private:
const OptionsList options_list;
public:
EstimationDataStatement(const OptionsList &options_list_arg);
virtual void checkPass(ModFileStructure &mod_file_struct);
virtual void writeOutput(ostream &output, const string &basename) const;
};
#endif

View File

@ -94,9 +94,9 @@ class ParsingDriver;
%token BVAR_PRIOR_MU BVAR_PRIOR_OMEGA BVAR_PRIOR_TAU BVAR_PRIOR_TRAIN
%token BVAR_REPLIC BYTECODE
%token CHANGE_TYPE CHECK CONDITIONAL_FORECAST CONDITIONAL_FORECAST_PATHS CONF_SIG CONSTANT CONTROLLED_VAREXO CORR COVAR CUTOFF
%token DATAFILE DR_ALGO DROP DSAMPLE DYNASAVE DYNATYPE CALIBRATION
%token DATAFILE FILE DR_ALGO DROP DSAMPLE DYNASAVE DYNATYPE CALIBRATION
%token END ENDVAL EQUAL ESTIMATION ESTIMATED_PARAMS ESTIMATED_PARAMS_BOUNDS ESTIMATED_PARAMS_INIT
%token FILENAME FILTER_STEP_AHEAD FILTERED_VARS FIRST_OBS SET_TIME
%token FILENAME FILTER_STEP_AHEAD FILTERED_VARS FIRST_OBS LAST_OBS SET_TIME
%token <string_val> FLOAT_NUMBER
%token FORECAST K_ORDER_SOLVER INSTRUMENTS
%token GAMMA_PDF GRAPH CONDITIONAL_VARIANCE_DECOMPOSITION NOCHECK
@ -215,6 +215,7 @@ statement : parameters
| estimated_params_bounds
| estimated_params_init
| set_time
| data
| varobs
| observation_trends
| unit_root_vars
@ -1163,6 +1164,22 @@ set_time : SET_TIME '(' date_number ')' ';'
{ driver.set_time($3); }
;
data : DATA '(' data_options_list ')'';'
{ driver.estimation_data(); }
;
data_options_list : data_options_list COMMA data_options
| data_options
;
data_options : o_file
| o_new_estimation_data_first_obs
| o_last_obs
| o_new_estimation_data_nobs
| o_xls_sheet
| o_xls_range
;
estimation : ESTIMATION ';'
{ driver.run_estimation(); }
| ESTIMATION '(' estimation_options_list ')' ';'
@ -1862,6 +1879,7 @@ o_mfs : MFS EQUAL INT_NUMBER { driver.mfs($3); };
o_simul : SIMUL; // Do nothing, only here for backward compatibility
o_simul_seed : SIMUL_SEED EQUAL INT_NUMBER { driver.error("'simul_seed' option is no longer supported; use 'set_dynare_seed' command instead"); } ;
o_qz_criterium : QZ_CRITERIUM EQUAL non_negative_number { driver.option_num("qz_criterium", $3); };
o_file : FILE EQUAL filename { driver.option_str("file", $3); };
o_datafile : DATAFILE EQUAL filename { driver.option_str("datafile", $3); };
o_nobs : NOBS EQUAL vec_int
{ driver.option_vec_int("nobs", $3); }
@ -1874,6 +1892,14 @@ o_conditional_variance_decomposition : CONDITIONAL_VARIANCE_DECOMPOSITION EQUAL
{ driver.option_vec_int("conditional_variance_decomposition", $3); }
;
o_first_obs : FIRST_OBS EQUAL INT_NUMBER { driver.option_num("first_obs", $3); };
o_new_estimation_data_first_obs : FIRST_OBS EQUAL date_number
{ driver.option_date("first_obs", $3); }
;
o_last_obs : LAST_OBS EQUAL date_number
{ driver.option_date("last_obs", $3); }
;
o_new_estimation_data_nobs : NOBS EQUAL INT_NUMBER { driver.option_num("nobs", $3); };
o_prefilter : PREFILTER EQUAL INT_NUMBER { driver.option_num("prefilter", $3); };
o_presample : PRESAMPLE EQUAL INT_NUMBER { driver.option_num("presample", $3); };
o_lik_algo : LIK_ALGO EQUAL INT_NUMBER { driver.option_num("lik_algo", $3); };

View File

@ -109,6 +109,7 @@ string eofbuff;
<INITIAL>model_info {BEGIN DYNARE_STATEMENT; return token::MODEL_INFO;}
<INITIAL>estimation {BEGIN DYNARE_STATEMENT; return token::ESTIMATION;}
<INITIAL>set_time {BEGIN DYNARE_STATEMENT; return token::SET_TIME;}
<INITIAL>data {BEGIN DYNARE_STATEMENT; return token::DATA;}
<INITIAL>varobs {BEGIN DYNARE_STATEMENT; return token::VAROBS;}
<INITIAL>unit_root_vars {BEGIN DYNARE_STATEMENT; return token::UNIT_ROOT_VARS;}
<INITIAL>rplot {BEGIN DYNARE_STATEMENT; return token::RPLOT;}
@ -189,8 +190,10 @@ string eofbuff;
<DYNARE_BLOCK>end {BEGIN INITIAL; return token::END;}
/* Inside of a Dynare statement */
<DYNARE_STATEMENT>file {return token::FILE;}
<DYNARE_STATEMENT>datafile {return token::DATAFILE;}
<DYNARE_STATEMENT>nobs {return token::NOBS;}
<DYNARE_STATEMENT>last_obs {return token::LAST_OBS;}
<DYNARE_STATEMENT>first_obs {return token::FIRST_OBS;}
<DYNARE_STATEMENT>prefilter {return token::PREFILTER;}
<DYNARE_STATEMENT>presample {return token::PRESAMPLE;}

View File

@ -1212,6 +1212,13 @@ ParsingDriver::set_time(string *arg)
options_list.clear();
}
void
ParsingDriver::estimation_data()
{
mod_file->addStatement(new EstimationDataStatement(options_list));
options_list.clear();
}
void
ParsingDriver::run_estimation()
{

View File

@ -357,6 +357,8 @@ public:
void add_estimated_params_element();
//! Sets the frequency of the data
void set_time(string *arg);
//! Estimation Data
void estimation_data();
//! Runs estimation process
void run_estimation();
//! Runs dynare_sensitivy()

View File

@ -86,6 +86,8 @@ public:
bool dsge_var_estimated;
//! Whether there is a bayesian_irf option passed to the estimation statement
bool bayesian_irf_present;
//! Whether there is a data statement present
bool estimation_data_statement_present;
};
class Statement