Commit f7cdc39f authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

Refuse that estimated parameters appear in the expressions defining the...

Refuse that estimated parameters appear in the expressions defining the variance/covariance matrix of shocks

Closes #469
parent 45c117fb
......@@ -517,6 +517,12 @@ EstimatedParamsStatement::checkPass(ModFileStructure &mod_file_struct, WarningCo
}
}
}
// Fill in mod_file_struct.estimated_parameters (related to #469)
for (vector<EstimationParams>::const_iterator it = estim_params_list.begin();
it != estim_params_list.end(); it++)
if (it->type == 2)
mod_file_struct.estimated_parameters.insert(symbol_table.getID(it->name));
}
void
......
......@@ -264,6 +264,28 @@ ModFile::checkPass()
|| dynamic_model.isBinaryOpUsed(oEqualEqual)
|| dynamic_model.isBinaryOpUsed(oDifferent)))
warnings << "WARNING: you are using a function (max, min, abs, sign) or an operator (<, >, <=, >=, ==, !=) which is unsuitable for a stochastic context; see the reference manual, section about \"Expressions\", for more details." << endl;
// Test if some estimated parameters are used within the values of shocks
// statements (see issue #469)
set<int> parameters_intersect;
set_intersection(mod_file_struct.parameters_within_shocks_values.begin(),
mod_file_struct.parameters_within_shocks_values.end(),
mod_file_struct.estimated_parameters.begin(),
mod_file_struct.estimated_parameters.end(),
inserter(parameters_intersect, parameters_intersect.begin()));
if (parameters_intersect.size() > 0)
{
cerr << "ERROR: some estimated parameters (";
for (set<int>::const_iterator it = parameters_intersect.begin();
it != parameters_intersect.end(); )
{
cerr << symbol_table.getName(*it);
if (++it != parameters_intersect.end())
cerr << ", ";
}
cerr << ") also appear in the expressions defining the variance/covariance matrix of shocks; this is not allowed." << endl;
exit(EXIT_FAILURE);
}
}
void
......
......@@ -284,6 +284,25 @@ ShocksStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidati
|| symbol_table.isObservedVariable(it->first.second))
mod_file_struct.calibrated_measurement_errors = true;
}
// Fill in mod_file_struct.parameters_with_shocks_values (related to #469)
set<pair<int, int> > params_lags;
for (var_and_std_shocks_t::const_iterator it = var_shocks.begin();
it != var_shocks.end(); ++it)
it->second->collectVariables(eParameter, params_lags);
for (var_and_std_shocks_t::const_iterator it = std_shocks.begin();
it != std_shocks.end(); ++it)
it->second->collectVariables(eParameter, params_lags);
for (covar_and_corr_shocks_t::const_iterator it = covar_shocks.begin();
it != covar_shocks.end(); ++it)
it->second->collectVariables(eParameter, params_lags);
for (covar_and_corr_shocks_t::const_iterator it = corr_shocks.begin();
it != corr_shocks.end(); ++it)
it->second->collectVariables(eParameter, params_lags);
for (set<pair<int, int> >::const_iterator it = params_lags.begin();
it != params_lags.end(); ++it)
mod_file_struct.parameters_within_shocks_values.insert(it->first);
}
MShocksStatement::MShocksStatement(const det_shocks_t &det_shocks_arg,
......
......@@ -23,6 +23,7 @@
#include <ostream>
#include <string>
#include <map>
#include <set>
#include "SymbolList.hh"
#include "WarningConsolidation.hh"
......@@ -97,6 +98,11 @@ public:
int last_markov_switching_chain;
//! Whether a calib_smoother statement is present
bool calib_smoother_present;
//! Set of parameters used within shocks blocks, inside the expressions
//! defining the values of covariances (stored as symbol ids)
set<int> parameters_within_shocks_values;
//! Set of estimated parameters (stored as symbol ids)
set<int> estimated_parameters;
};
class Statement
......
......@@ -166,7 +166,8 @@ MODFILES = \
gradient/fs2000_numgrad_3.mod \
gradient/fs2000_numgrad_5.mod
XFAIL_MODFILES = ramst_xfail.mod
XFAIL_MODFILES = ramst_xfail.mod \
estim_param_in_shock_value.mod
# Dependencies
example1_use_dll.m.trs: example1.m.trs
......
// Test for #469, should fail in the preprocessor
var m P c e W R k d n l gy_obs gp_obs y dA;
varexo e_a e_m;
parameters alp bet gam mst rho psi del sig_e_a;
alp = 0.33;
bet = 0.99;
gam = 0.003;
mst = 1.011;
rho = 0.7;
psi = 0.787;
del = 0.02;
sig_e_a=0.014;
model;
dA = exp(gam+e_a);
log(m) = (1-rho)*log(mst) + rho*log(m(-1))+e_m;
-P/(c(+1)*P(+1)*m)+bet*P(+1)*(alp*exp(-alp*(gam+log(e(+1))))*k^(alp-1)*n(+1)^(1-alp)+(1-del)*exp(-(gam+log(e(+1)))))/(c(+2)*P(+2)*m(+1))=0;
W = l/n;
-(psi/(1-psi))*(c*P/(1-n))+l/n = 0;
R = P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(-alp)/W;
1/(c*P)-bet*P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)/(m*l*c(+1)*P(+1)) = 0;
c+k = exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)+(1-del)*exp(-(gam+e_a))*k(-1);
P*c = m;
m-1+d = l;
e = exp(e_a);
y = k(-1)^alp*n^(1-alp)*exp(-alp*(gam+e_a));
gy_obs = dA*y/y(-1);
gp_obs = (P/P(-1))*m(-1)/dA;
end;
initval;
k = 6;
m = mst;
P = 2.25;
c = 0.45;
e = 1;
W = 4;
R = 1.02;
d = 0.85;
n = 0.19;
l = 0.86;
y = 0.6;
gy_obs = exp(gam);
gp_obs = exp(-gam);
dA = exp(gam);
end;
shocks;
var e_a; stderr sig_e_a;
var e_m; stderr 0.005;
end;
steady;
check;
estimated_params;
del, beta_pdf, 0.01, 0.005;
sig_e_a, inv_gamma_pdf, 0.035449, inf;
end;
varobs gp_obs gy_obs;
estimation(order=1,bayesian_irf,irf_shocks=(e_m),datafile=fsdat_simul,mode_check, nobs=192, loglinear, mh_replic=2000, mh_nblocks=2, mh_jscale=0.8);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment