From 54ef4e28386972ac715a424b7f2d2d66f2afe3f6 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 20 Jul 2016 17:09:46 -0400 Subject: [PATCH 01/47] preprocessor: always write M_.state_var #637 --- preprocessor/DynamicModel.cc | 39 ++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/preprocessor/DynamicModel.cc b/preprocessor/DynamicModel.cc index 6d68eb425..71247755f 100644 --- a/preprocessor/DynamicModel.cc +++ b/preprocessor/DynamicModel.cc @@ -2603,23 +2603,24 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de (julia ? "false" : "0")) << ";" << endl; + vector state_var; + for (int endoID = 0; endoID < symbol_table.endo_nbr(); endoID++) + // Loop on periods + for (int lag = -max_endo_lag; lag < 0; lag++) + try + { + getDerivID(symbol_table.getID(eEndogenous, variable_reordered[endoID]), lag); + if (lag < 0 && find(state_var.begin(), state_var.end(), variable_reordered[endoID]+1) == state_var.end()) + state_var.push_back(variable_reordered[endoID]+1); + } + catch (UnknownDerivIDException &e) + { + } + //In case of sparse model, writes the block_decomposition structure of the model if (block_decomposition) { - vector state_var, state_equ; - for (int endoID = 0; endoID < symbol_table.endo_nbr(); endoID++) - // Loop on periods - for (int lag = -max_endo_lag; lag < 0; lag++) - try - { - getDerivID(symbol_table.getID(eEndogenous, variable_reordered[endoID]), lag); - if (lag < 0 && find(state_var.begin(), state_var.end(), variable_reordered[endoID]+1) == state_var.end()) - state_var.push_back(variable_reordered[endoID]+1); - } - catch (UnknownDerivIDException &e) - { - } - + vector state_equ; int count_lead_lag_incidence = 0; int max_lead, max_lag, max_lag_endo, max_lead_endo, max_lag_exo, max_lead_exo, max_lag_exo_det, max_lead_exo_det; unsigned int nb_blocks = getNbBlocks(); @@ -3039,13 +3040,13 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de KF_index_file.write(reinterpret_cast(&(*it)), sizeof(index_KF)); KF_index_file.close(); } - output << modstruct << "state_var = ["; - - for (vector::const_iterator it=state_var.begin(); it != state_var.end(); it++) - output << *it << " "; - output << "];" << endl; } + output << modstruct << "state_var = ["; + for (vector::const_iterator it=state_var.begin(); it != state_var.end(); it++) + output << *it << " "; + output << "];" << endl; + // Writing initialization for some other variables if (!julia) output << modstruct << "exo_names_orig_ord = [1:" << symbol_table.exo_nbr() << "];" << endl; From ce5316a1eccfa31a0bb95c34279bdea3f5801740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?= Date: Thu, 27 Jul 2017 14:08:57 +0200 Subject: [PATCH 02/47] Fixed typo. (cherry picked from commit b866bd828cfde830c227dbe935624e640197c409) --- matlab/backward/simul_backward_linear_model.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/backward/simul_backward_linear_model.m b/matlab/backward/simul_backward_linear_model.m index 44555449f..7e630d0f4 100644 --- a/matlab/backward/simul_backward_linear_model.m +++ b/matlab/backward/simul_backward_linear_model.m @@ -79,7 +79,7 @@ Y = DynareOutput.endo_simul; [cst,jacob] = model_dynamic(zeros(DynareModel.endo_nbr+ny1,1), ... zeros(2,size(DynareOutput.exo_simul, 2)), ... DynareModel.params, ... - DynareOutput.steadystate,2); + DynareOutput.steady_state,2); A0inv = inv(jacob(:,jdx)); A1 = jacob(:,nonzeros(DynareModel.lead_lag_incidence(1,:))); B = jacob(:,end-number_of_shocks+1:end); From df1793a49934009d7f1c1e5a9d8160acb17abb9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?= Date: Thu, 27 Jul 2017 14:15:12 +0200 Subject: [PATCH 03/47] Fixed issue with the size of x (exogenous variables). (cherry picked from commit ccfd809dd0984363e05ba77e27f2aaf9ce6fe548) --- matlab/backward/simul_backward_linear_model.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/matlab/backward/simul_backward_linear_model.m b/matlab/backward/simul_backward_linear_model.m index 7e630d0f4..40fc144d9 100644 --- a/matlab/backward/simul_backward_linear_model.m +++ b/matlab/backward/simul_backward_linear_model.m @@ -77,9 +77,9 @@ Y = DynareOutput.endo_simul; % get coefficients [cst,jacob] = model_dynamic(zeros(DynareModel.endo_nbr+ny1,1), ... - zeros(2,size(DynareOutput.exo_simul, 2)), ... + zeros(2,DynareModel.exo_nbr), ... DynareModel.params, ... - DynareOutput.steady_state,2); + DynareOutput.steady_state,1); A0inv = inv(jacob(:,jdx)); A1 = jacob(:,nonzeros(DynareModel.lead_lag_incidence(1,:))); B = jacob(:,end-number_of_shocks+1:end); From 1cd20acd7d0796648a24a761be621253e269cf43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?= Date: Thu, 27 Jul 2017 15:40:19 +0200 Subject: [PATCH 04/47] Code factorization. (cherry picked from commit 77b1d14083ea92220660631dbb7760c62cf4a7c9) --- matlab/backward/simul_backward_linear_model.m | 81 +++++--------- matlab/backward/simul_backward_model.m | 101 +++++------------- matlab/backward/simul_backward_model_init.m | 77 +++++++++++++ .../backward/simul_backward_nonlinear_model.m | 58 ++-------- 4 files changed, 137 insertions(+), 180 deletions(-) create mode 100644 matlab/backward/simul_backward_model_init.m diff --git a/matlab/backward/simul_backward_linear_model.m b/matlab/backward/simul_backward_linear_model.m index 40fc144d9..ccf38eb74 100644 --- a/matlab/backward/simul_backward_linear_model.m +++ b/matlab/backward/simul_backward_linear_model.m @@ -1,38 +1,25 @@ -function DynareOutput = simul_backward_linear_model(initial_conditions, sample_size, DynareOptions, DynareModel, DynareOutput, innovations) +function DynareOutput = simul_backward_linear_model(varargin) -%@info: -%! @deftypefn {Function File} {@var{DynareOutput} =} simul_backward_nonlinear_model (@var{sample_size},@var{DynareOptions}, @var{DynareModel}, @var{DynareOutput}) -%! @anchor{@simul_backward_nonlinear_model} -%! @sp 1 -%! Simulates a stochastic non linear backward looking model with arbitrary precision (a deterministic solver is used). -%! @sp 2 -%! @strong{Inputs} -%! @sp 1 -%! @table @ @var -%! @item sample_size -%! Scalar integer, size of the sample to be generated. -%! @item DynareOptions -%! Matlab/Octave structure (Options used by Dynare). -%! @item DynareDynareModel -%! Matlab/Octave structure (Description of the model). -%! @item DynareOutput -%! Matlab/Octave structure (Results reported by Dynare). -%! @end table -%! @sp 1 -%! @strong{Outputs} -%! @sp 1 -%! @table @ @var -%! @item DynareOutput -%! Matlab/Octave structure (Results reported by Dynare). -%! @end table -%! @sp 2 -%! @strong{This function is called by:} -%! @sp 2 -%! @strong{This function calls:} -%! @ref{dynTime} -%! -%! @end deftypefn -%@eod: +% Simulates a stochastic linear backward looking model. +% +% INPUTS +% - initialconditions [double] n*1 vector, initial conditions for the endogenous variables. +% - samplesize [integer] scalar, number of periods for the simulation. +% - DynareOptions [struct] Dynare's options_ global structure. +% - DynareModel [struct] Dynare's M_ global structure. +% - DynareOutput [struct] Dynare's oo_ global structure. +% - innovations [double] T*q matrix, innovations to be used for the simulation. +% +% OUTPUTS +% - DynareOutput [struct] Dynare's oo_ global structure. +% +% REMARKS +% [1] The innovations used for the simulation are saved in DynareOutput.exo_simul, and the resulting paths for the endogenous +% variables are saved in DynareOutput.endo_simul. +% [2] The last input argument is not mandatory. If absent we use random draws and rescale them with the informations provided +% through the shocks block. +% [3] If the first input argument is empty, the endogenous variables are initialized with 0, or if available with the informations +% provided thrtough the histval block. % Copyright (C) 2012-2017 Dynare Team % @@ -51,27 +38,15 @@ function DynareOutput = simul_backward_linear_model(initial_conditions, sample_s % You should have received a copy of the GNU General Public License % along with Dynare. If not, see . -number_of_shocks = size(DynareOutput.exo_simul,2); -% Get usefull vector of indices. -ny0 = nnz(DynareModel.lead_lag_incidence(2,:)); -ny1 = nnz(DynareModel.lead_lag_incidence(1,:)); -iy1 = find(DynareModel.lead_lag_incidence(1,:)>0); -idx = 1:DynareModel.endo_nbr; -jdx = idx+ny1; -hdx = 1:ny1; - -% Get the name of the dynamic model routine. -model_dynamic = str2func([DynareModel.fname,'_dynamic']); - -% initialization of vector y. -y = NaN(length(idx)+ny1,1); +[initialconditions, samplesize, innovations, DynareOptions, DynareModel, DynareOutput, nx, ny1, iy1, jdx, model_dynamic, y] = ... + simul_backward_model_init(varargin{:}); % initialization of the returned simulations. -DynareOutput.endo_simul = NaN(DynareModel.endo_nbr,sample_size+1); -if isempty(initial_conditions) +DynareOutput.endo_simul = NaN(DynareModel.endo_nbr,samplesize+1); +if isempty(initialconditions) DynareOutput.endo_simul(:,1) = DynareOutput.steady_state; else - DynareOutput.endo_simul(:,1) = initial_conditions; + DynareOutput.endo_simul(:,1) = initialconditions; end Y = DynareOutput.endo_simul; @@ -82,10 +57,10 @@ Y = DynareOutput.endo_simul; DynareOutput.steady_state,1); A0inv = inv(jacob(:,jdx)); A1 = jacob(:,nonzeros(DynareModel.lead_lag_incidence(1,:))); -B = jacob(:,end-number_of_shocks+1:end); +B = jacob(:,end-nx+1:end); % Simulations -for it = 2:sample_size+1 +for it = 2:samplesize+1 Y(:,it) = -A0inv*(cst + A1*Y(iy1,it-1) + B*DynareOutput.exo_simul(it,:)'); end diff --git a/matlab/backward/simul_backward_model.m b/matlab/backward/simul_backward_model.m index 32486e651..e61a9d712 100644 --- a/matlab/backward/simul_backward_model.m +++ b/matlab/backward/simul_backward_model.m @@ -1,38 +1,25 @@ -function DynareOutput = simul_backward_model(initial_conditions, sample_size, DynareOptions, DynareModel, DynareOutput, innovations) +function DynareOutput = simul_backward_model(varargin) -%@info: -%! @deftypefn {Function File} {@var{DynareOutput} =} simul_backward_nonlinear_model (@var{sample_size},@var{DynareOptions}, @var{DynareModel}, @var{DynareOutput}) -%! @anchor{@simul_backward_nonlinear_model} -%! @sp 1 -%! Simulates a stochastic non linear backward looking model with arbitrary precision (a deterministic solver is used). -%! @sp 2 -%! @strong{Inputs} -%! @sp 1 -%! @table @ @var -%! @item sample_size -%! Scalar integer, size of the sample to be generated. -%! @item DynareOptions -%! Matlab/Octave structure (Options used by Dynare). -%! @item DynareDynareModel -%! Matlab/Octave structure (Description of the model). -%! @item DynareOutput -%! Matlab/Octave structure (Results reported by Dynare). -%! @end table -%! @sp 1 -%! @strong{Outputs} -%! @sp 1 -%! @table @ @var -%! @item DynareOutput -%! Matlab/Octave structure (Results reported by Dynare). -%! @end table -%! @sp 2 -%! @strong{This function is called by:} -%! @sp 2 -%! @strong{This function calls:} -%! @ref{dynTime} -%! -%! @end deftypefn -%@eod: +% Simulates a stochastic backward looking model (with arbitrary precision). +% +% INPUTS +% - initialconditions [double] n*1 vector, initial conditions for the endogenous variables. +% - samplesize [integer] scalar, number of periods for the simulation. +% - DynareOptions [struct] Dynare's options_ global structure. +% - DynareModel [struct] Dynare's M_ global structure. +% - DynareOutput [struct] Dynare's oo_ global structure. +% - innovations [double] T*q matrix, innovations to be used for the simulation. +% +% OUTPUTS +% - DynareOutput [struct] Dynare's oo_ global structure. +% +% REMARKS +% [1] The innovations used for the simulation are saved in DynareOutput.exo_simul, and the resulting paths for the endogenous +% variables are saved in DynareOutput.endo_simul. +% [2] The last input argument is not mandatory. If absent we use random draws and rescale them with the informations provided +% through the shocks block. +% [3] If the first input argument is empty, the endogenous variables are initialized with 0, or if available with the informations +% provided thrtough the histval block. % Copyright (C) 2012-2017 Dynare Team % @@ -51,48 +38,10 @@ function DynareOutput = simul_backward_model(initial_conditions, sample_size, Dy % You should have received a copy of the GNU General Public License % along with Dynare. If not, see . -if DynareModel.maximum_lead - error(['simul_backward_nonlinear_model:: The specified model is not backward looking!']) -end - -if nargin<6 - % Set the covariance matrix of the structural innovations. - variances = diag(DynareModel.Sigma_e); - number_of_shocks = length(DynareModel.Sigma_e); - positive_var_indx = find(variances>0); - effective_number_of_shocks = length(positive_var_indx); - covariance_matrix = DynareModel.Sigma_e(positive_var_indx,positive_var_indx); - covariance_matrix_upper_cholesky = chol(covariance_matrix); - - % Set seed to its default state. - if DynareOptions.bnlms.set_dynare_seed_to_default - set_dynare_seed('default'); - end - - % Simulate structural innovations. - switch DynareOptions.bnlms.innovation_distribution - case 'gaussian' - DynareOutput.bnlms.shocks = randn(sample_size,effective_number_of_shocks)*covariance_matrix_upper_cholesky; - otherwise - error(['simul_backward_nonlinear_model:: ' DynareOption.bnlms.innovation_distribution ' distribution for the structural innovations is not (yet) implemented!']) - end - % Put the simulated innovations in DynareOutput.exo_simul. - DynareOutput.exo_simul = zeros(sample_size, number_of_shocks); - DynareOutput.exo_simul(2:end,positive_var_indx) = DynareOutput.bnlms.shocks; - if isfield(DynareModel,'exo_histval') && ~isempty(DynareModel.exo_histval) - DynareOutput.exo_simul = [M_.exo_histval; DynareOutput.exo_simul]; - else - DynareOutput.exo_simul = [zeros(1,number_of_shocks); DynareOutput.exo_simul]; - end -else - number_of_shocks = size(innovations,2); - DynareOutput.exo_simul = innovations; -end +[initialconditions, samplesize, innovations, DynareOptions, DynareModel, DynareOutput] = simul_backward_model_init(varargin{:}); if DynareOptions.linear - DynareOutput = simul_backward_linear_model(initial_conditions, sample_size, DynareOptions, ... - DynareModel, DynareOutput, innovations); + DynareOutput = simul_backward_linear_model(initialconditions, samplesize, DynareOptions, DynareModel, DynareOutput, innovations); else - DynareOutput = simul_backward_nonlinear_model(initial_conditions, sample_size, DynareOptions, ... - DynareModel, DynareOutput, innovations); -end + DynareOutput = simul_backward_nonlinear_model(initialconditions, samplesize, DynareOptions, DynareModel, DynareOutput, innovations); +end \ No newline at end of file diff --git a/matlab/backward/simul_backward_model_init.m b/matlab/backward/simul_backward_model_init.m new file mode 100644 index 000000000..d45f73ff3 --- /dev/null +++ b/matlab/backward/simul_backward_model_init.m @@ -0,0 +1,77 @@ +function [initialconditions, samplesize, innovations, DynareOptions, DynareModel, DynareOutput, nx, ny1, iy1, jdx, model_dynamic, y] = simul_backward_model_init(varargin) + +% Initialization of the routines simulating backward models. + +% Copyright (C) 2012-2017 Dynare Team +% +% This file is part of Dynare. +% +% Dynare is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with Dynare. If not, see . + +initialconditions = varargin{1}; +samplesize = varargin{2}; + +DynareOptions = varargin{3}; +DynareModel = varargin{4}; +DynareOutput = varargin{5}; + +if DynareModel.maximum_lead + error('simul_backward_nonlinear_model:: The specified model is not backward looking!') +end + +if nargin<6 + % Set the covariance matrix of the structural innovations. + variances = diag(DynareModel.Sigma_e); + number_of_shocks = length(DynareModel.Sigma_e); + positive_var_indx = find(variances>0); + effective_number_of_shocks = length(positive_var_indx); + covariance_matrix = DynareModel.Sigma_e(positive_var_indx,positive_var_indx); + covariance_matrix_upper_cholesky = chol(covariance_matrix); + % Set seed to its default state. + if DynareOptions.bnlms.set_dynare_seed_to_default + set_dynare_seed('default'); + end + % Simulate structural innovations. + switch DynareOptions.bnlms.innovation_distribution + case 'gaussian' + DynareOutput.bnlms.shocks = randn(samplesize,effective_number_of_shocks)*covariance_matrix_upper_cholesky; + otherwise + error(['simul_backward_nonlinear_model:: ' DynareOption.bnlms.innovation_distribution ' distribution for the structural innovations is not (yet) implemented!']) + end + % Put the simulated innovations in DynareOutput.exo_simul. + DynareOutput.exo_simul = zeros(samplesize,number_of_shocks); + DynareOutput.exo_simul(:,positive_var_indx) = DynareOutput.bnlms.shocks; + if isfield(DynareModel,'exo_histval') && ~ isempty(DynareModel.exo_histval) + DynareOutput.exo_simul = [transpose(DynareModel.exo_histval); DynareOutput.exo_simul]; + else + DynareOutput.exo_simul = [zeros(1,number_of_shocks); DynareOutput.exo_simul]; + end + innovations = DynareOutput.exo_simul; +else + innovations = varargin{6}; + DynareOutput.exo_simul = innovations; % innovations +end + +if nargout>6 + nx = size(DynareOutput.exo_simul,2); + ny0 = nnz(DynareModel.lead_lag_incidence(2,:)); + ny1 = nnz(DynareModel.lead_lag_incidence(1,:)); + iy1 = find(DynareModel.lead_lag_incidence(1,:)>0); + idx = 1:DynareModel.endo_nbr; + jdx = idx+ny1; + % Get the name of the dynamic model routine. + model_dynamic = str2func([DynareModel.fname,'_dynamic']); + % initialization of vector y. + y = NaN(length(idx)+ny1,1); +end \ No newline at end of file diff --git a/matlab/backward/simul_backward_nonlinear_model.m b/matlab/backward/simul_backward_nonlinear_model.m index fd5f8af90..8e8b14fbf 100644 --- a/matlab/backward/simul_backward_nonlinear_model.m +++ b/matlab/backward/simul_backward_nonlinear_model.m @@ -1,4 +1,4 @@ -function DynareOutput = simul_backward_nonlinear_model(initial_conditions, sample_size, DynareOptions, DynareModel, DynareOutput, innovations) +function DynareOutput = simul_backward_nonlinear_model(varargin) % Simulates a stochastic non linear backward looking model with arbitrary precision (a deterministic solver is used). % @@ -38,58 +38,14 @@ function DynareOutput = simul_backward_nonlinear_model(initial_conditions, sampl % You should have received a copy of the GNU General Public License % along with Dynare. If not, see . -if DynareModel.maximum_lead - error('simul_backward_nonlinear_model:: The specified model is not backward looking!') -end +[initialconditions, samplesize, innovations, DynareOptions, DynareModel, DynareOutput, nx, ny1, iy1, jdx, model_dynamic, y] = ... + simul_backward_model_init(varargin{:}); -if nargin<6 - % Set the covariance matrix of the structural innovations. - variances = diag(DynareModel.Sigma_e); - number_of_shocks = length(DynareModel.Sigma_e); - positive_var_indx = find(variances>0); - effective_number_of_shocks = length(positive_var_indx); - covariance_matrix = DynareModel.Sigma_e(positive_var_indx,positive_var_indx); - covariance_matrix_upper_cholesky = chol(covariance_matrix); - % Set seed to its default state. - if DynareOptions.bnlms.set_dynare_seed_to_default - set_dynare_seed('default'); - end - % Simulate structural innovations. - switch DynareOptions.bnlms.innovation_distribution - case 'gaussian' - DynareOutput.bnlms.shocks = randn(sample_size,effective_number_of_shocks)*covariance_matrix_upper_cholesky; - otherwise - error(['simul_backward_nonlinear_model:: ' DynareOption.bnlms.innovation_distribution ' distribution for the structural innovations is not (yet) implemented!']) - end - % Put the simulated innovations in DynareOutput.exo_simul. - DynareOutput.exo_simul = zeros(sample_size,number_of_shocks); - DynareOutput.exo_simul(:,positive_var_indx) = DynareOutput.bnlms.shocks; - if isfield(DynareModel,'exo_histval') && ~ isempty(DynareModel.exo_histval) - DynareOutput.exo_simul = [transpose(DynareModel.exo_histval); DynareOutput.exo_simul]; - else - DynareOutput.exo_simul = [zeros(1,number_of_shocks); DynareOutput.exo_simul]; - end -else - DynareOutput.exo_simul = innovations; -end - -% Get usefull vector of indices. -ny1 = nnz(DynareModel.lead_lag_incidence(1,:)); -iy1 = find(DynareModel.lead_lag_incidence(1,:)>0); -idx = 1:DynareModel.endo_nbr; -jdx = idx+ny1; -hdx = 1:ny1; - -% Get the name of the dynamic model routine. -model_dynamic = str2func([DynareModel.fname,'_dynamic']); model_dynamic_s = str2func('dynamic_backward_model_for_simulation'); -% initialization of vector y. -y = NaN(length(idx)+ny1,1); - % initialization of the returned simulations. -DynareOutput.endo_simul = NaN(DynareModel.endo_nbr,sample_size+1); -if isempty(initial_conditions) +DynareOutput.endo_simul = NaN(DynareModel.endo_nbr,samplesize+1); +if isempty(initialconditions) if isfield(DynareModel,'endo_histval') && ~isempty(DynareModel.endo_histval) DynareOutput.endo_simul(:,1:DynareModel.maximum_lag) = DynareModel.endo_histval; else @@ -97,13 +53,13 @@ if isempty(initial_conditions) DynareOutput.endo_simul(:,1) = 0; end else - DynareOutput.endo_simul(:,1) = initial_conditions; + DynareOutput.endo_simul(:,1) = initialconditions; end Y = DynareOutput.endo_simul; % Simulations (call a Newton-like algorithm for each period). -for it = 2:sample_size+1 +for it = 2:samplesize+1 ylag = Y(iy1,it-1); % Set lagged variables. y = Y(:,it-1); % A good guess for the initial conditions is the previous values for the endogenous variables. Y(:,it) = dynare_solve(model_dynamic_s, y, DynareOptions, model_dynamic, ylag, DynareOutput.exo_simul, DynareModel.params, DynareOutput.steady_state, it+(DynareModel.maximum_exo_lag-1)); From 8e6fd310c3040cc07d875036c8dce633851d0707 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?= Date: Sat, 29 Jul 2017 11:28:28 +0200 Subject: [PATCH 05/47] Fixed backward model simulation routines. (cherry picked from commit 45a14d768d40e20904ebd055bc4893994531702b) --- matlab/backward/simul_backward_linear_model.m | 30 ++++++++++++++----- .../backward/simul_backward_nonlinear_model.m | 22 +++++++++----- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/matlab/backward/simul_backward_linear_model.m b/matlab/backward/simul_backward_linear_model.m index ccf38eb74..5f0595e46 100644 --- a/matlab/backward/simul_backward_linear_model.m +++ b/matlab/backward/simul_backward_linear_model.m @@ -42,25 +42,39 @@ function DynareOutput = simul_backward_linear_model(varargin) simul_backward_model_init(varargin{:}); % initialization of the returned simulations. -DynareOutput.endo_simul = NaN(DynareModel.endo_nbr,samplesize+1); +DynareOutput.endo_simul = NaN(DynareModel.endo_nbr,samplesize); if isempty(initialconditions) - DynareOutput.endo_simul(:,1) = DynareOutput.steady_state; + if isfield(DynareModel,'endo_histval') && ~isempty(DynareModel.endo_histval) + DynareOutput.endo_simul = [DynareModel.endo_histval, DynareOutput.endo_simul]; + else + DynareOutput.endo_simul = [zeros(DynareModel.endo_nbr, DynareModel.max_lag_orig), DynareOutput.endo_simul]; + end else - DynareOutput.endo_simul(:,1) = initialconditions; + if ~isequal(size(initialconditions, 2), DynareModel.max_lag_orig) + error(['simul_backward_linear_model:: First argument should have %s columns!'], DynareModel.max_lag_orig) + end + DynareOutput.endo_simul = [initialconditions, DynareOutput.endo_simul]; end Y = DynareOutput.endo_simul; -% get coefficients -[cst,jacob] = model_dynamic(zeros(DynareModel.endo_nbr+ny1,1), ... - zeros(2,DynareModel.exo_nbr), ... +if ~DynareModel.max_exo_lag_orig + if DynareModel.max_endo_lag_orig>1 + DynareOutput.exo_simul = [ zeros(DynareModel.max_endo_lag_orig-1, DynareModel.exo_nbr); DynareOutput.exo_simul]; + end +end + +% Get coefficients +[cst, jacob] = model_dynamic(zeros(DynareModel.endo_nbr+ny1,1), ... + zeros(DynareModel.max_lag_orig+1,DynareModel.exo_nbr), ... DynareModel.params, ... - DynareOutput.steady_state,1); + DynareOutput.steady_state, DynareModel.max_lag_orig+1); + A0inv = inv(jacob(:,jdx)); A1 = jacob(:,nonzeros(DynareModel.lead_lag_incidence(1,:))); B = jacob(:,end-nx+1:end); % Simulations -for it = 2:samplesize+1 +for it = DynareModel.max_lag_orig+(1:samplesize) Y(:,it) = -A0inv*(cst + A1*Y(iy1,it-1) + B*DynareOutput.exo_simul(it,:)'); end diff --git a/matlab/backward/simul_backward_nonlinear_model.m b/matlab/backward/simul_backward_nonlinear_model.m index 8e8b14fbf..1465eee17 100644 --- a/matlab/backward/simul_backward_nonlinear_model.m +++ b/matlab/backward/simul_backward_nonlinear_model.m @@ -44,25 +44,33 @@ function DynareOutput = simul_backward_nonlinear_model(varargin) model_dynamic_s = str2func('dynamic_backward_model_for_simulation'); % initialization of the returned simulations. -DynareOutput.endo_simul = NaN(DynareModel.endo_nbr,samplesize+1); +DynareOutput.endo_simul = NaN(DynareModel.endo_nbr, samplesize); if isempty(initialconditions) if isfield(DynareModel,'endo_histval') && ~isempty(DynareModel.endo_histval) - DynareOutput.endo_simul(:,1:DynareModel.maximum_lag) = DynareModel.endo_histval; + DynareOutput.endo_simul = [DynareModel.endo_histval, DynareOutput.endo_simul]; else - warning('simul_backward_nonlinear_model:: Initial condition is zero for all variables! If the model is nonlinear, the model simulation may fail with the default initialization') - DynareOutput.endo_simul(:,1) = 0; + warning('simul_backward_nonlinear_model:: Initial condition is zero for all variables! The model simulation may fail with the default initialization.') + DynareOutput.endo_simul = [zeros(DynareModel.endo_nbr, DynareModel.max_lag_orig), DynareOutput.endo_simul]; end else - DynareOutput.endo_simul(:,1) = initialconditions; + if ~isequal(size(initialconditions, 2), DynareModel.max_lag_orig) + error(['simul_backward_nonlinear_model:: First argument should have %s columns!'], DynareModel.max_lag_orig) + end + DynareOutput.endo_simul = [initialconditions, DynareOutput.endo_simul]; end Y = DynareOutput.endo_simul; +if ~DynareModel.max_exo_lag_orig + if DynareModel.max_endo_lag_orig>1 + DynareOutput.exo_simul = [ zeros(DynareModel.max_endo_lag_orig-1, DynareModel.exo_nbr); DynareOutput.exo_simul]; + end +end % Simulations (call a Newton-like algorithm for each period). -for it = 2:samplesize+1 +for it = DynareModel.max_lag_orig+(1:samplesize) ylag = Y(iy1,it-1); % Set lagged variables. y = Y(:,it-1); % A good guess for the initial conditions is the previous values for the endogenous variables. - Y(:,it) = dynare_solve(model_dynamic_s, y, DynareOptions, model_dynamic, ylag, DynareOutput.exo_simul, DynareModel.params, DynareOutput.steady_state, it+(DynareModel.maximum_exo_lag-1)); + Y(:,it) = dynare_solve(model_dynamic_s, y, DynareOptions, model_dynamic, ylag, DynareOutput.exo_simul, DynareModel.params, DynareOutput.steady_state, it); end DynareOutput.endo_simul = Y; \ No newline at end of file From 550a7ad3b1a79c305bb8d97e6ebda8144c000af8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?= Date: Sat, 29 Jul 2017 11:29:18 +0200 Subject: [PATCH 06/47] Rewrote backward model inversion routine. (cherry picked from commit be6b1628d1518b2cc8678b68f0e7578ad15226ad) --- matlab/backward/backward_model_inversion.m | 44 +++++++++++++--------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/matlab/backward/backward_model_inversion.m b/matlab/backward/backward_model_inversion.m index 6acbcc606..52a7467a2 100644 --- a/matlab/backward/backward_model_inversion.m +++ b/matlab/backward/backward_model_inversion.m @@ -85,37 +85,45 @@ ModelInversion.J_id = [ModelInversion.y_free_id ; sum(DynareModel.lead_lag_incid model_dynamic = str2func([DynareModel.fname,'_dynamic']); model_dtransf = str2func('dynamic_backward_model_for_inversion'); -% Initialization of vector y (free endogenous variables and free innovations). -y = NaN(nyfree+nxfree); - % Initialization of the returned simulations (endogenous variables). -Y = NaN(DynareModel.endo_nbr, nobs(constraints)+1); -initialconditions -constraints.dates(1) -Y(:,1) = initialconditions(constraints.dates(1)-1).data(1:DynareModel.endo_nbr); +Y = NaN(DynareModel.endo_nbr, nobs(constraints)); + +Y = [transpose(initialconditions(constraints.dates(1)-1).data(1:DynareModel.endo_nbr)), Y]; for i=1:nyctrl Y(controlledendogenousvariables_id(i),2:end) = transpose(constraints.data(:,i)); end -% Initialization of the returned simulations (exogenous variables). -X = exogenousvariables{exo_names{:}}(constraints.dates(1)-max(1,DynareModel.maximum_exo_lag):constraints.dates(end)).data; +% Exogenous variables. +X = exogenousvariables.data; %{exo_names{:}}(constraints.dates(1)-max(1,DynareModel.max_exo_lag_orig):constraints.dates(end)).data; % Inversion of the model, solvers for the free endogenous and exogenous variables (call a Newton-like algorithm in each period). -for it = 2:nobs(constraints)+1 + +ity = 2; +itx = find(exogenousvariables.dates==constraints.dates(1)); +DynareOptions.solve_algo=4; +for t = 1:nobs(constraints) % Set the lagged values of the endogenous variables. - ylag = Y(iy1,it-1); + ylag = Y(iy1,ity-1); % Set the current values of the constrained endogenous variables. - ycur = Y(controlledendogenousvariables_id,it); + ycur = Y(controlledendogenousvariables_id,ity); % Vector z gather the free endogenous variables (initialized with lagged % values) and the free exogenous variables (initialized with 0). - z = [Y(freeendogenousvariables_id,it-1); zeros(nxfree, 1)]; + z = [Y(freeendogenousvariables_id,ity-1); zeros(nxfree, 1)]; % Solves for z. - z = dynare_solve(model_dtransf, z, DynareOptions, model_dynamic, ylag, ycur, X, DynareModel.params, DynareOutput.steady_state, it+DynareModel.maximum_exo_lag, ModelInversion); + [z, failed] = dynare_solve(model_dtransf, z, DynareOptions, model_dynamic, ylag, ycur, X, DynareModel.params, DynareOutput.steady_state, itx, ModelInversion); + if failed + error('Enable to solve the system of equations!') + end % Update the matrix of exogenous variables. - X(it,freeinnovations_id) = z(nyfree+1:end); + X(itx,freeinnovations_id) = z(nyfree+(1:nxfree)); % Update the matrix of endogenous variables. - Y(freeendogenousvariables_id,it) = z(1:nyfree); + if nyfree + Y(freeendogenousvariables_id,ity) = z(1:nyfree); + end + % Increment counters + ity = ity+1; + itx = itx+1; end -endogenousvariables = dseries(Y', constraints.dates(1)-1, endo_names); -exogenousvariables = dseries(X(max(DynareModel.maximum_exo_lag,1)+1:end,:), constraints.dates(1), exo_names); \ No newline at end of file +endogenousvariables = dseries(Y(:,2:end)', constraints.dates(1), endo_names); +exogenousvariables = dseries(X(find(exogenousvariables.dates==constraints.dates(1))+(0:(nobs(constraints)-1)),:), constraints.dates(1), exo_names); \ No newline at end of file From 81a1d803b409c8cbc1a64b9bbfa55750efdf147e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?= Date: Mon, 31 Jul 2017 12:14:01 +0200 Subject: [PATCH 07/47] Fixed initial period (lagged by one period without reason). (cherry picked from commit ef0afc1b7571df79d60812f65cbefa02a2ffc450) --- matlab/set_historical_values.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/matlab/set_historical_values.m b/matlab/set_historical_values.m index d57662f35..ef42f2563 100644 --- a/matlab/set_historical_values.m +++ b/matlab/set_historical_values.m @@ -36,7 +36,7 @@ if ischar(initialperiod) end % Initialize endo_histval. -M_.endo_histval = zeros(M_.endo_nbr, M_.maximum_endo_lag); +M_.endo_histval = zeros(M_.endo_nbr, M_.max_endo_lag_orig); % Fill endo_histval. k = 1; @@ -45,7 +45,7 @@ for i = 1:M_.endo_nbr if M_.lead_lag_incidence(1,i) > 0 if any(strcmp(deblank(M_.endo_names(i,:)),ds.name)) M_.endo_histval(i,M_.maximum_endo_lag) = ... - ds{deblank(M_.endo_names(i,:))}(initialperiod-1).data; + ds{deblank(M_.endo_names(i,:))}(initialperiod).data; else error(sprintf('Can''t find %s in dseries', deblank(M_.endo_names(i,:)))) end @@ -55,7 +55,7 @@ for i = 1:M_.endo_nbr if a.type == 1 if any(strcmp(deblank(M_.endo_names(a.orig_index,:)), ds.name)) M_.endo_histval(i,M_.maximum_endo_lag) = ... - ds{deblank(M_.endo_names(a.orig_index,:))}(initialperiod-1+a.orig_lead_lag).data; + ds{deblank(M_.endo_names(a.orig_index,:))}(initialperiod+a.orig_lead_lag).data; else error(sprintf('Can''t find %s in dseries', deblank(M_.endo_names(a.orig_index,:)))) end From 44cadbd51b93ac5a348de9ef161c23db4e01f7fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?= Date: Mon, 31 Jul 2017 16:25:55 +0200 Subject: [PATCH 08/47] Fixed errors introduced by recent changes in simul_backward_model. (cherry picked from commit f7399f4d7417653ee658f2ab6918cbee8bff7307) --- matlab/backward/backward_model_irf.m | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/matlab/backward/backward_model_irf.m b/matlab/backward/backward_model_irf.m index 043568351..a83f35cc1 100644 --- a/matlab/backward/backward_model_irf.m +++ b/matlab/backward/backward_model_irf.m @@ -86,24 +86,29 @@ irfs = struct(); Sigma = M_.Sigma_e + 1e-14*eye(M_.exo_nbr); sigma = transpose(chol(Sigma)); -% Put initial conditions in a vector of doubles -initialconditions = transpose(initialcondition{endo_names{:}}.data); - % Compute the IRFs (loop over innovations). for i=1:length(listofshocks) % Get transition paths induced by the initial condition. - innovations = zeros(periods+M_.maximum_exo_lag, M_.exo_nbr); + innovations = zeros(periods, M_.exo_nbr); if ~isempty(M_.exo_histval) - innovations(1:M_.maximum_exo_lag,:) = M_.exo_histval; + innovations = [transpose(M_.exo_histval); innovations]; + shift = size(M_.exo_histval, 2); + else + innovations = [zeros(1, M_.exo_nbr); innovations]; + shift = 1; end + innovations oo__0 = simul_backward_model(initialconditions, periods, options_, M_, oo_, innovations); % Add the shock. j = strmatch(listofshocks{i}, exo_names); if isempty(j) error('backward_model_irf: Exogenous variable %s is unknown!', listofshocks{i}) end - innovations(1+M_.maximum_exo_lag,:) = transpose(sigma(:,j)); - oo__1 = simul_backward_model(initialconditions, periods, options_, M_, oo_, innovations); + innovations(shift+1,:) = transpose(sigma(:,j)); + innovations + oo__1 = simul_backward_model(initialconditions, periods, options_, M_, ... + oo_, innovations); + oo__1.endo_simul-oo__0.endo_simul % Transform the endogenous variables if notransform endo_simul__0 = oo__0.endo_simul; From 16e0fca19c4fb775e66d606000d38526802051fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?= Date: Mon, 31 Jul 2017 16:26:43 +0200 Subject: [PATCH 09/47] Added two examples (forecasts and IRFs in backward models). (cherry picked from commit 949440ef9c0b92320ce05136d0e3613704c29c96) --- tests/ecb/backward-models/clean | 4 + tests/ecb/backward-models/solow_forecast.mod | 95 +++++++++++++++++ tests/ecb/backward-models/solow_irf.mod | 106 +++++++++++++++++++ 3 files changed, 205 insertions(+) create mode 100755 tests/ecb/backward-models/clean create mode 100644 tests/ecb/backward-models/solow_forecast.mod create mode 100644 tests/ecb/backward-models/solow_irf.mod diff --git a/tests/ecb/backward-models/clean b/tests/ecb/backward-models/clean new file mode 100755 index 000000000..f11c0cff5 --- /dev/null +++ b/tests/ecb/backward-models/clean @@ -0,0 +1,4 @@ +#!/bin/sh + +rm -rf solow_irf solow_forecast +rm -f *.m *.mat *.log diff --git a/tests/ecb/backward-models/solow_forecast.mod b/tests/ecb/backward-models/solow_forecast.mod new file mode 100644 index 000000000..669e527c3 --- /dev/null +++ b/tests/ecb/backward-models/solow_forecast.mod @@ -0,0 +1,95 @@ +close all + +var Efficiency $A$ + EfficiencyGrowth $X$ + Population $L$ + PopulationGrowth $N$ + Output $Y$ + PhysicalCapitalStock $K$ ; + +varexo e_x $\varepsilon_x$ + e_n $\varepsilon_n$; + +parameters alpha $\alpha$ + delta $\delta$ + s $s$ + rho_x $\rho_x$ + rho_n $\rho_n$ + EfficiencyGrowth_ss $X^{\star}$ + PopulationGrowth_ss $N^{\star}$ ; + +alpha = .33; +delta = .02; +s = .20; +rho_x = .90; +rho_n = .95; +EfficiencyGrowth_ss = 1.02; +PopulationGrowth_ss = 1.02; + +model; + Efficiency = EfficiencyGrowth*Efficiency(-1); + EfficiencyGrowth/EfficiencyGrowth_ss = (EfficiencyGrowth(-1)/EfficiencyGrowth_ss)^(rho_x)*exp(e_x); + Population = PopulationGrowth*Population(-1); + PopulationGrowth/PopulationGrowth_ss = (PopulationGrowth(-1)/PopulationGrowth_ss)^(rho_n)*exp(e_n); + Output = PhysicalCapitalStock(-1)^alpha*(Efficiency*Population)^(1-alpha); + PhysicalCapitalStock = (1-delta)*PhysicalCapitalStock(-1) + s*Output; +end; + + +shocks; + var e_x = 0.005; + var e_n = 0.001; +end; + +// Set initial condition for the forecast (we simulate a sample, forecast will start at the end of the sample) + +histval; + Efficiency(0) = 1; + EfficiencyGrowth(0) = .5; + Population(0) = 1; + PopulationGrowth(0) = .5; + PhysicalCapitalStock(0) = 1; +end; + +oo__ = simul_backward_nonlinear_model([], 10, options_, M_, oo_); + +initialcondition = dseries(transpose(oo__.endo_simul(:,10)), 2017Q1, cellstr(M_.endo_names)); + + +/* REMARKS +** +** dseries object initialcondition may have more variable than required. +*/ + +// Define the variables for which we want to compute the IRFs +listofvariables = {'Efficiency', 'Output'}; + +/* REMARKS +** +** If possible do not forecasts all the endogenous variables (this is the default). +*/ + +// Compute the forecasts +forecasts = backward_model_forecast(initialcondition, listofvariables, 16, true); + +/* REMARKS +** +** - The third argument is the number of periods for the forecast. Default is 8. +** - The last argument is for computing (or not) the confidence bands. If false (default), only point forecast is produced. +** - forecasts is a structure, each field is a dseries object for the point forecast (ie forecasts without innovations in the future), +** the mean forecast, the median forecast, the standard deviation of the predictive distribution and the lower/upper bounds of the +** interval containing 95% of the predictive distribution. +*/ + +// Plot forecast for output +plot(forecasts.meanforecast.Output, '-k', 'linewidth', 2) +hold on +plot(forecasts.lb.Output,'-r') +plot(forecasts.ub.Output,'-r') +hold off + +/* REMARKS +** +** In this model there is no steady state (only a stable balanced growth paths), this explains the +** shape of the forecast for Output. +*/ \ No newline at end of file diff --git a/tests/ecb/backward-models/solow_irf.mod b/tests/ecb/backward-models/solow_irf.mod new file mode 100644 index 000000000..0db1b5ab7 --- /dev/null +++ b/tests/ecb/backward-models/solow_irf.mod @@ -0,0 +1,106 @@ +close all + +var Efficiency $A$ + EfficiencyGrowth $X$ + Population $L$ + PopulationGrowth $N$ + Output $Y$ + PhysicalCapitalStock $K$ ; + +varexo e_x $\varepsilon_x$ + e_n $\varepsilon_n$; + +parameters alpha $\alpha$ + delta $\delta$ + s $s$ + rho_x $\rho_x$ + rho_n $\rho_n$ + EfficiencyGrowth_ss $X^{\star}$ + PopulationGrowth_ss $N^{\star}$ ; + +alpha = .33; +delta = .02; +s = .20; +rho_x = .90; +rho_n = .95; +EfficiencyGrowth_ss = 1.0; +PopulationGrowth_ss = 1.0; + +model; + Efficiency = EfficiencyGrowth*Efficiency(-1); + EfficiencyGrowth/EfficiencyGrowth_ss = (EfficiencyGrowth(-1)/EfficiencyGrowth_ss)^(rho_x)*exp(e_x); + Population = PopulationGrowth*Population(-1); + PopulationGrowth/PopulationGrowth_ss = (PopulationGrowth(-1)/PopulationGrowth_ss)^(rho_n)*exp(e_n); + Output = PhysicalCapitalStock(-1)^alpha*(Efficiency*Population)^(1-alpha); + PhysicalCapitalStock = (1-delta)*PhysicalCapitalStock(-1) + s*Output; +end; + + +shocks; + var e_x = 0.005; + var e_n = 0.001; +end; + +/* +** FIRST APPROACH (PASS A DSERIES OBJECT FOR THE INITIAL CONDITION) +*/ + +// Define a dseries object. +ds = dseries(repmat([1, .5, 1, .5, 0, 1], 10, 1), 1990Q1, cellstr(M_.endo_names), cellstr(M_.endo_names_tex)); + +// Alternatively we could build this object with a stochastic simulation of the model. +//oo_ = simul_backward_model(rand(6,1), 10, options_, M_, oo_); + +// Set the initial condition for the IRFs using observation 1991Q1 in ds. +set_historical_values ds 1991Q1; + +// Define the shocks for which we want to compute the IRFs +listofshocks = {'e_x', 'e_n'}; + +// Define the variables for which we want to compute the IRFs +listofvariables = {'Efficiency', 'Population', 'Output'}; + +// Compute the IRFs +irfs = backward_model_irf(1991Q1, listofshocks, listofvariables, 50); // 10 is the number of periods (default value is 40). + +// Plot an IRF (shock on technology) +figure(1) +plot(irfs.e_x.Output) +legend('Output') +title('IRF (shock on the growth rate of efficiency)') + +/* +** SECOND APPROACH (USE THE HISTVAL BLOCK FOR SETTING THE INITIAL CONDITION) +** +** In this case the first argument of the backward_model_irf routine is a date object (for specifying +** the period of the initial condition). +*/ + +histval; + Efficiency(0) = 1; + EfficiencyGrowth(0) = .5; + Population(0) = 1; + PopulationGrowth(0) = .5; + PhysicalCapitalStock(0) = 1; +end; + +// Define the shocks for which we want to compute the IRFs +listofshocks = {'e_x', 'e_n'}; + +// Define the variables for which we want to compute the IRFs +listofvariables = {'Efficiency', 'Population', 'Output'}; + +// Compute the IRFs +irfs = backward_model_irf(1991Q1, listofshocks, listofvariables, 50); // 10 is the number of periods (default value is 40). + +// Plot an IRF (shock on technology) +figure(2) +plot(irfs.e_x.Output) +legend('Output') +title('IRF (shock on the growth rate of efficiency)') + +/* REMARK +** ------ +** +** This model is nonlinear and non stationary. For different initial conditions the IRFs may look quite different. +*/ \ No newline at end of file From 57fd56c90a41bba62f413e0ced53ddc1a15f39f8 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Tue, 1 Aug 2017 11:04:46 +0200 Subject: [PATCH 10/47] sim1_linear.m: Fix evaluation of dynamic model at deterministic steady state Did not correctly account for exogenous variables being potentially present with leads and lags --- matlab/perfect-foresight-models/sim1_linear.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/matlab/perfect-foresight-models/sim1_linear.m b/matlab/perfect-foresight-models/sim1_linear.m index 85dc38405..080a60a5d 100644 --- a/matlab/perfect-foresight-models/sim1_linear.m +++ b/matlab/perfect-foresight-models/sim1_linear.m @@ -111,7 +111,8 @@ dynamicmodel = str2func([M.fname,'_dynamic']); z = steadystate_y([ip; ic; in]); % Evaluate the Jacobian of the dynamic model at the deterministic steady state. -[d1,jacobian] = dynamicmodel(z, transpose(steadystate_x), params, steadystate_y, 1); +[d1,jacobian] = dynamicmodel(z, repmat(transpose(steadystate_x),options.periods+M.maximum_lag+M.maximum_lead,1),... + params, steadystate_y, M.maximum_lag+1); % Check that the dynamic model was evaluated at the steady state. if max(abs(d1))>1e-12 From fdb24d6a1daa475a1543633d0bd935ce402abff5 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Tue, 1 Aug 2017 11:36:07 +0200 Subject: [PATCH 11/47] Add unit test for sim1_linear.m --- tests/Makefile.am | 1 + tests/simul/linear_state_space_ARMA.mod | 43 +++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 tests/simul/linear_state_space_ARMA.mod diff --git a/tests/Makefile.am b/tests/Makefile.am index 89f031db8..65c954fec 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -179,6 +179,7 @@ MODFILES = \ simul/simul_ZLB_purely_forward.mod \ simul/simul_ZLB_purely_forward_no_solution.mod \ simul/Irreversible_investment.mod \ + simul/linear_state_space_ARMA.mod \ conditional_forecasts/2/fs2000_est.mod \ conditional_forecasts/3/fs2000_conditional_forecast_initval.mod \ conditional_forecasts/4/fs2000_conditional_forecast_histval.mod \ diff --git a/tests/simul/linear_state_space_ARMA.mod b/tests/simul/linear_state_space_ARMA.mod new file mode 100644 index 000000000..8de3d47ce --- /dev/null +++ b/tests/simul/linear_state_space_ARMA.mod @@ -0,0 +1,43 @@ +%mod-file triggering the sim1_linear.m solver; +%The exogenous arma processes test whether the Jacobian at the +%deterministic steady state is correctly computed +var x + y + z; + +varexo u + v; + +parameters a1 a2 a3 a4 + b1 b2 b3 + c1; + +a1 = .50; +a2 = .00; +a3 = .70; +a4 = .40; +b1 = .90; +b2 = .00; +b3 = .80; +c1 = .95; + + +model(linear); + y = a1*x(-1) + a2*x(+1) + a3*z + a4*y(-1); + z = b1*z(-1) + b2*z(+1) + b3*x + u; + x = c1*x(-1) + v +v(-1)+v(+1); +end; + +initval; +y=-1; +x=-1; +z=-1; +end; + +endval; +y=0; +x=0; +z=0; +end; +steady; +simul(periods=1000,stack_solve_algo=0); From 637b0b02126c15c9edf5ebd2a4955558a70dc9af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?= Date: Thu, 10 Aug 2017 13:15:06 +0200 Subject: [PATCH 12/47] Fixed bug (missing 'exact' when calling strmatch). --- matlab/backward/backward_model_irf.m | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/matlab/backward/backward_model_irf.m b/matlab/backward/backward_model_irf.m index a83f35cc1..e1ed036c8 100644 --- a/matlab/backward/backward_model_irf.m +++ b/matlab/backward/backward_model_irf.m @@ -97,18 +97,14 @@ for i=1:length(listofshocks) innovations = [zeros(1, M_.exo_nbr); innovations]; shift = 1; end - innovations oo__0 = simul_backward_model(initialconditions, periods, options_, M_, oo_, innovations); % Add the shock. - j = strmatch(listofshocks{i}, exo_names); + j = strmatch(listofshocks{i}, exo_names, 'exact'); if isempty(j) error('backward_model_irf: Exogenous variable %s is unknown!', listofshocks{i}) end innovations(shift+1,:) = transpose(sigma(:,j)); - innovations - oo__1 = simul_backward_model(initialconditions, periods, options_, M_, ... - oo_, innovations); - oo__1.endo_simul-oo__0.endo_simul + oo__1 = simul_backward_model(initialconditions, periods, options_, M_, oo_, innovations); % Transform the endogenous variables if notransform endo_simul__0 = oo__0.endo_simul; From e5bbcf41b64fea67e170cb8acf8c4f44b1290802 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?= Date: Thu, 10 Aug 2017 13:26:47 +0200 Subject: [PATCH 13/47] Efficiency change. find(strcmp(,)) is faster than strmatch(,,'exact') and returns the same array of integers. --- matlab/backward/backward_model_forecast.m | 2 +- matlab/backward/backward_model_inversion.m | 4 ++-- matlab/backward/backward_model_irf.m | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/matlab/backward/backward_model_forecast.m b/matlab/backward/backward_model_forecast.m index 0c23abaef..951fb821f 100644 --- a/matlab/backward/backward_model_forecast.m +++ b/matlab/backward/backward_model_forecast.m @@ -60,7 +60,7 @@ endo_names = cellstr(M_.endo_names); n = length(listofvariables); idy = zeros(n,1); for i=1:n - j = strmatch(listofvariables{i}, endo_names, 'exact'); + j = find(strcmp(listofvariables{i}, endo_names)); if isempty(j) error('backward_model_forecast:: Variable %s is unknown!', listofvariables{i}) else diff --git a/matlab/backward/backward_model_inversion.m b/matlab/backward/backward_model_inversion.m index 52a7467a2..b9ce336f1 100644 --- a/matlab/backward/backward_model_inversion.m +++ b/matlab/backward/backward_model_inversion.m @@ -35,7 +35,7 @@ function [endogenousvariables, exogenousvariables] = backward_model_inversion(co freeinnovations_id = zeros(length(freeinnovations), 1); if length(freeinnovations) Date: Thu, 10 Aug 2017 14:56:22 +0200 Subject: [PATCH 14/47] Fixed typo. --- matlab/backward/backward_model_forecast.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/backward/backward_model_forecast.m b/matlab/backward/backward_model_forecast.m index 951fb821f..46269f25e 100644 --- a/matlab/backward/backward_model_forecast.m +++ b/matlab/backward/backward_model_forecast.m @@ -105,7 +105,7 @@ forecasts.pointforecast = dseries(transpose(oo__0.endo_simul(idy,:)), initialcon if withuncertainty % Preallocate an array gathering the simulations. - ArrayOfForectasts = zeros(n, periods+1, B); + ArrayOfForecasts = zeros(n, periods+1, B); for i=1:B innovations(max(M_.maximum_exo_lag, 1)+1:end,:) = transpose(sigma*randn(M_.exo_nbr, periods)); oo__ = simul_backward_model(initialconditions, periods, options_, M_, oo_, innovations); From 9c8f2a90e3a3d9f424d041934f1411b3be369322 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?= Date: Fri, 11 Aug 2017 11:47:34 +0200 Subject: [PATCH 15/47] Fixed timming of the innovations when computing confidence bands. Innovations were hitting the model one period too late. --- matlab/backward/backward_model_forecast.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/matlab/backward/backward_model_forecast.m b/matlab/backward/backward_model_forecast.m index 46269f25e..565648d35 100644 --- a/matlab/backward/backward_model_forecast.m +++ b/matlab/backward/backward_model_forecast.m @@ -91,7 +91,7 @@ end initialconditions = transpose(initialcondition{endo_names{:}}.data); % Compute forecast without shock -innovations = zeros(periods+max(M_.maximum_exo_lag, 1), M_.exo_nbr); +innovations = zeros(periods+M_.maximum_exo_lag, M_.exo_nbr); if M_.maximum_exo_lag if isempty(M_.exo_histval) error('You need to set the past values for the exogenous variables!') @@ -105,9 +105,9 @@ forecasts.pointforecast = dseries(transpose(oo__0.endo_simul(idy,:)), initialcon if withuncertainty % Preallocate an array gathering the simulations. - ArrayOfForecasts = zeros(n, periods+1, B); + ArrayOfForecasts = zeros(n, periods+size(initialconditions, 2), B); for i=1:B - innovations(max(M_.maximum_exo_lag, 1)+1:end,:) = transpose(sigma*randn(M_.exo_nbr, periods)); + innovations(M_.maximum_exo_lag+1:end,:) = transpose(sigma*randn(M_.exo_nbr, periods)); oo__ = simul_backward_model(initialconditions, periods, options_, M_, oo_, innovations); ArrayOfForecasts(:,:,i) = oo__.endo_simul(idy,:); end From db870b562a8398c7ecb9995e30b46041648880f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?= Date: Wed, 16 Aug 2017 10:57:22 +0200 Subject: [PATCH 16/47] Ignore scripts/dynare.elc. --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 9fc713587..6110fa3d6 100644 --- a/.gitignore +++ b/.gitignore @@ -197,6 +197,9 @@ mex/build/matlab/run_m2html.m # MacOS stuff .DS_Store +# Emacs stuff +scripts/dynare.elc + # MS-Sbvar /contrib/ms-sbvar/*.prn /contrib/ms-sbvar/*.dat @@ -215,4 +218,4 @@ tests/julia/rbc/rbc*.jl octave-workspace # VERSION generated file -VERSION \ No newline at end of file +VERSION From 1a4257ac4bd75f1db6988a650ef79c2cb9f4cc40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?= Date: Wed, 16 Aug 2017 15:44:00 +0200 Subject: [PATCH 17/47] Efficiency change. Reduced the size of the unnecessary large array for the exogenous variables introduced in 57fd56c90a41bba62f413e0ced53ddc1a15f39f8. --- matlab/perfect-foresight-models/sim1_linear.m | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/matlab/perfect-foresight-models/sim1_linear.m b/matlab/perfect-foresight-models/sim1_linear.m index 080a60a5d..72a44ff9d 100644 --- a/matlab/perfect-foresight-models/sim1_linear.m +++ b/matlab/perfect-foresight-models/sim1_linear.m @@ -108,11 +108,12 @@ if verbose end dynamicmodel = str2func([M.fname,'_dynamic']); + z = steadystate_y([ip; ic; in]); +x = repmat(transpose(steadystate_x), 1+M.maximum_exo_lag+M.maximum_exo_lead, 1); % Evaluate the Jacobian of the dynamic model at the deterministic steady state. -[d1,jacobian] = dynamicmodel(z, repmat(transpose(steadystate_x),options.periods+M.maximum_lag+M.maximum_lead,1),... - params, steadystate_y, M.maximum_lag+1); +[d1, jacobian] = dynamicmodel(z, x, params, steadystate_y, M.maximum_lag+1); % Check that the dynamic model was evaluated at the steady state. if max(abs(d1))>1e-12 From 97b894a1cdb2f47171e42448c4a6f416d26c8f31 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Tue, 1 Aug 2017 12:29:16 +0200 Subject: [PATCH 18/47] Provide meaningful error message if oo_.exo_simul is larger than options_.periods --- matlab/perfect-foresight-models/perfect_foresight_setup.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/matlab/perfect-foresight-models/perfect_foresight_setup.m b/matlab/perfect-foresight-models/perfect_foresight_setup.m index 341d70aad..1b502c4ad 100644 --- a/matlab/perfect-foresight-models/perfect_foresight_setup.m +++ b/matlab/perfect-foresight-models/perfect_foresight_setup.m @@ -51,6 +51,10 @@ if options_.periods == 0 error('PERFECT_FORESIGHT_SETUP: number of periods for the simulation isn''t specified') end +if options_.periods Date: Wed, 16 Aug 2017 16:04:15 +0200 Subject: [PATCH 19/47] Test if shocks are declared. Fixes bug introduced in 97b894a1cdb2f47171e42448c4a6f416d26c8f31, if no shocks are declared (for instance if the user is interested in the transition to the steady state). --- matlab/perfect-foresight-models/perfect_foresight_setup.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/perfect-foresight-models/perfect_foresight_setup.m b/matlab/perfect-foresight-models/perfect_foresight_setup.m index 1b502c4ad..fc6a4bce7 100644 --- a/matlab/perfect-foresight-models/perfect_foresight_setup.m +++ b/matlab/perfect-foresight-models/perfect_foresight_setup.m @@ -51,7 +51,7 @@ if options_.periods == 0 error('PERFECT_FORESIGHT_SETUP: number of periods for the simulation isn''t specified') end -if options_.periods Date: Wed, 16 Aug 2017 16:08:18 +0200 Subject: [PATCH 20/47] Renamed integration test (removed capital letters). --- .../{linear_state_space_ARMA.mod => linear_state_space_arma.mod} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/simul/{linear_state_space_ARMA.mod => linear_state_space_arma.mod} (100%) diff --git a/tests/simul/linear_state_space_ARMA.mod b/tests/simul/linear_state_space_arma.mod similarity index 100% rename from tests/simul/linear_state_space_ARMA.mod rename to tests/simul/linear_state_space_arma.mod From 131a68ea6fb85919a9564d25b21e690024b055a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?= Date: Wed, 16 Aug 2017 16:43:43 +0200 Subject: [PATCH 21/47] Provide more informations if expected shocks are declared after the terminal period. --- .../perfect_foresight_setup.m | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/matlab/perfect-foresight-models/perfect_foresight_setup.m b/matlab/perfect-foresight-models/perfect_foresight_setup.m index fc6a4bce7..97e2ee199 100644 --- a/matlab/perfect-foresight-models/perfect_foresight_setup.m +++ b/matlab/perfect-foresight-models/perfect_foresight_setup.m @@ -52,7 +52,16 @@ if options_.periods == 0 end if ~isempty(M_.det_shocks) && options_.periodsoptions_.periods); + mess = sprintf('%s\n At least one expected value for %s has been declared after the terminal period.', mess, deblank(M_.exo_names(M_.det_shocks(i).exo_id,:))); + end + end + disp(mess) + skipline() + error('PERFECT_FORESIGHT_SETUP: Please check the declaration of the shocks or increase the value of the periods option.') end if ~options_.initval_file From 8ccebd9e23b840fac0e0eea634cecb3ed1895c1f Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Thu, 10 Aug 2017 15:47:51 +0200 Subject: [PATCH 22/47] DsgeSmoother.m: provide informative error instead of crashing when model cannot be solved --- matlab/DsgeSmoother.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/matlab/DsgeSmoother.m b/matlab/DsgeSmoother.m index 997904afc..6466ad2f1 100644 --- a/matlab/DsgeSmoother.m +++ b/matlab/DsgeSmoother.m @@ -104,6 +104,10 @@ oo_.dr.restrict_columns = bayestopt_.smoother_restrict_columns; [T,R,SteadyState,info,M_,options_,oo_] = dynare_resolve(M_,options_,oo_); +if info~=0 + print_info(info,options_.noprint, options_); + return +end oo_.dr.restrict_var_list = oldoo.restrict_var_list; oo_.dr.restrict_columns = oldoo.restrict_columns; From b4a52b80765bb2b52109a7b5f0826e55901541cd Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Sun, 13 Aug 2017 19:56:44 +0200 Subject: [PATCH 23/47] conditional_forecasts: Fix errors in manual --- doc/dynare.texi | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/doc/dynare.texi b/doc/dynare.texi index 42788d1d9..a85aef6b7 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -7764,7 +7764,7 @@ Fields are of the form: @end defvr -@deffn Command conditional_forecast (@var{OPTIONS}@dots{}) [@var{VARIABLE_NAME}@dots{}]; +@deffn Command conditional_forecast (@var{OPTIONS}@dots{}); @anchor{conditional_forecast} @descriptionhead @@ -7819,7 +7819,7 @@ constrained endogenous, and their constrained future path. Option @code{controlled_varexo} is used to specify the structural shocks which will be matched to generate the constrained path. -Use @code{plot_conditional_forecast} to graph the results. +Use @ref{plot_conditional_forecast} to graph the results. @optionshead @@ -7915,7 +7915,8 @@ periods 1:5; values 3; end; -conditional_forecast(parameter_set = calibration, controlled_varexo = (e, u), replic = 3000); +conditional_forecast(parameter_set = calibration, controlled_varexo = (e, u), +replic = 3000); plot_conditional_forecast(periods = 10) a y; @end example @@ -7944,7 +7945,7 @@ it is necessary to specify the logarithm of the controlled variables. @deffn Command plot_conditional_forecast [@var{VARIABLE_NAME}@dots{}]; @deffnx Command plot_conditional_forecast (periods = @var{INTEGER}) [@var{VARIABLE_NAME}@dots{}]; - +@anchor{plot_conditional_forecast} @descriptionhead Plots the conditional (plain lines) and unconditional (dashed lines) forecasts. From f021909db50140c1e11c89c9bbed80d7e8ae6d8f Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Sun, 13 Aug 2017 19:56:59 +0200 Subject: [PATCH 24/47] Fix typo in ParsingDriver.hh --- preprocessor/ParsingDriver.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/preprocessor/ParsingDriver.hh b/preprocessor/ParsingDriver.hh index f6f04f8a0..80eb4c0a2 100644 --- a/preprocessor/ParsingDriver.hh +++ b/preprocessor/ParsingDriver.hh @@ -365,7 +365,7 @@ public: void end_shocks(bool overwrite); //! Writes a mshocks statement void end_mshocks(bool overwrite); - //! Adds a deterministic chock or a path element inside a conditional_forecast_paths block + //! Adds a deterministic shock or a path element inside a conditional_forecast_paths block void add_det_shock(string *var, bool conditional_forecast); //! Adds a std error chock void add_stderr_shock(string *var, expr_t value); From 4cd259baa61c073a1ee2e8c623191b48c626654c Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Wed, 16 Aug 2017 12:57:55 +0200 Subject: [PATCH 25/47] Fix plotting of measurement errors in non-MCMC case Number of plots was wrongly computed --- matlab/dynare_estimation_1.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/matlab/dynare_estimation_1.m b/matlab/dynare_estimation_1.m index a4b416614..3fe420a2b 100644 --- a/matlab/dynare_estimation_1.m +++ b/matlab/dynare_estimation_1.m @@ -609,10 +609,10 @@ if (~((any(bayestopt_.pshape > 0) && options_.mh_replic) || (any(bayestopt_.psha if nvn number_of_plots_to_draw = 0; index = []; - for i=1:n_varobs - if max(abs(measurement_error)) > 0.000000001 + for obs_iter=1:n_varobs + if max(abs(measurement_error(obs_iter,:))) > 0.0000001 number_of_plots_to_draw = number_of_plots_to_draw + 1; - index = cat(1,index,i); + index = cat(1,index,obs_iter); end end if ~options_.nograph @@ -627,7 +627,7 @@ if (~((any(bayestopt_.pshape > 0) && options_.mh_replic) || (any(bayestopt_.psha fh = dyn_figure(options_.nodisplay,'Name','Smoothed observation errors'); NAMES = []; if options_.TeX, TeXNAMES = []; end - nstar0=min(nstar,number_of_plots_to_draw-(nbplt-1)*nstar); + nstar0=min(nstar,number_of_plots_to_draw-(plt-1)*nstar); if gend==1 marker_string{1,1}='-ro'; marker_string{2,1}='-ko'; From 16a3e110349af075701ad3feb3cdbd937ca177c5 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Wed, 16 Aug 2017 13:11:35 +0200 Subject: [PATCH 26/47] Transform hard-coded plot tolerance into an undocumented option --- matlab/dynare_estimation_1.m | 2 +- matlab/global_initialization.m | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/matlab/dynare_estimation_1.m b/matlab/dynare_estimation_1.m index 3fe420a2b..c39d698e8 100644 --- a/matlab/dynare_estimation_1.m +++ b/matlab/dynare_estimation_1.m @@ -610,7 +610,7 @@ if (~((any(bayestopt_.pshape > 0) && options_.mh_replic) || (any(bayestopt_.psha number_of_plots_to_draw = 0; index = []; for obs_iter=1:n_varobs - if max(abs(measurement_error(obs_iter,:))) > 0.0000001 + if max(abs(measurement_error(obs_iter,:))) > options_.ME_plot_tol; number_of_plots_to_draw = number_of_plots_to_draw + 1; index = cat(1,index,obs_iter); end diff --git a/matlab/global_initialization.m b/matlab/global_initialization.m index d26b488c8..762a23281 100644 --- a/matlab/global_initialization.m +++ b/matlab/global_initialization.m @@ -467,6 +467,7 @@ options_.prior_trunc = 1e-10; options_.smoother = 0; options_.posterior_max_subsample_draws = 1200; options_.sub_draws = []; +options_.ME_plot_tol=1e-6; % options_.use_mh_covariance_matrix = 0; options_.gradient_method = 2; %used by csminwel and newrat options_.gradient_epsilon = 1e-6; %used by csminwel and newrat From 32c3beb27d33ebd743ced5b01c0cfc9abc8d7c49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?= Date: Wed, 16 Aug 2017 22:17:20 +0200 Subject: [PATCH 27/47] Fixed bug introduced in 7d180e2fcb76e31c0ba5d6d6097f72175a4b21aa. --- tests/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index 65c954fec..e28ed34a0 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -179,7 +179,7 @@ MODFILES = \ simul/simul_ZLB_purely_forward.mod \ simul/simul_ZLB_purely_forward_no_solution.mod \ simul/Irreversible_investment.mod \ - simul/linear_state_space_ARMA.mod \ + simul/linear_state_space_arma.mod \ conditional_forecasts/2/fs2000_est.mod \ conditional_forecasts/3/fs2000_conditional_forecast_initval.mod \ conditional_forecasts/4/fs2000_conditional_forecast_histval.mod \ From 542982171946421970d580e5fed9e727c3f2a976 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?= Date: Wed, 16 Aug 2017 23:29:15 +0200 Subject: [PATCH 28/47] Fixed incomplete commit 1a4257ac4bd75f1db6988a650ef79c2cb9f4cc40. --- matlab/perfect-foresight-models/sim1_linear.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/perfect-foresight-models/sim1_linear.m b/matlab/perfect-foresight-models/sim1_linear.m index 72a44ff9d..af75a61b7 100644 --- a/matlab/perfect-foresight-models/sim1_linear.m +++ b/matlab/perfect-foresight-models/sim1_linear.m @@ -113,7 +113,7 @@ z = steadystate_y([ip; ic; in]); x = repmat(transpose(steadystate_x), 1+M.maximum_exo_lag+M.maximum_exo_lead, 1); % Evaluate the Jacobian of the dynamic model at the deterministic steady state. -[d1, jacobian] = dynamicmodel(z, x, params, steadystate_y, M.maximum_lag+1); +[d1, jacobian] = dynamicmodel(z, x, params, steadystate_y, M.maximum_exo_lag+1); % Check that the dynamic model was evaluated at the steady state. if max(abs(d1))>1e-12 From 1551d33e9e3a6eaaec846be9ce352a3ef95516ab Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 24 Aug 2017 15:35:10 +0200 Subject: [PATCH 29/47] preprocessor: add write_equation_tags option to write_latex_original_model and write_latex_static_model. closes #1431 --- doc/dynare.texi | 25 +++++++++++++++++++++++-- preprocessor/ComputingTasks.cc | 14 ++++++++------ preprocessor/ComputingTasks.hh | 6 ++++-- preprocessor/DynamicModel.cc | 26 +++++++++++++++++--------- preprocessor/DynamicModel.hh | 7 +++++-- preprocessor/DynareBison.yy | 8 ++++++-- preprocessor/ModelTree.cc | 4 ++-- preprocessor/ModelTree.hh | 4 ++-- preprocessor/ParsingDriver.cc | 10 +++++----- preprocessor/ParsingDriver.hh | 4 ++-- preprocessor/StaticModel.cc | 4 ++-- preprocessor/StaticModel.hh | 2 +- 12 files changed, 77 insertions(+), 37 deletions(-) diff --git a/doc/dynare.texi b/doc/dynare.texi index a85aef6b7..22c811370 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -2112,6 +2112,7 @@ equations using the @code{write_latex_static_model} command. @anchor{write_latex_original_model} @deffn Command write_latex_original_model ; +@deffnx Command write_latex_original_model (@var{OPTIONS}) ; @descriptionhead @@ -2135,6 +2136,17 @@ appended to the variable names, as @LaTeX{} subscripts. Compiling the @TeX{} file requires the following @LaTeX{} packages: @code{geometry}, @code{fullpage}, @code{breqn}. +@optionshead + +@table @code + +@anchor{write_equation_tags} +@item write_equation_tags +Write the equation tags in the @LaTeX{} output. NB: the equation tags will be +interpreted with @LaTeX{} markups. + +@end table + @end deffn @anchor{write_latex_dynamic_model} @@ -2192,14 +2204,14 @@ For the required @LaTeX{} packages, @pxref{write_latex_original_model}. @table @code @item write_equation_tags -Write the equation tags in the @LaTeX{} output. NB: the equation tags will be -interpreted with @LaTeX{} markups. +@xref{write_equation_tags} @end table @end deffn @deffn Command write_latex_static_model ; +@deffnx Command write_latex_static_model (@var{OPTIONS}) ; @descriptionhead @@ -2227,6 +2239,15 @@ lags) of the dynamic model declared in the @code{model} block. For the required @LaTeX{} packages, @pxref{write_latex_original_model}. +@optionshead + +@table @code + +@item write_equation_tags +@xref{write_equation_tags} + +@end table + @end deffn @node Auxiliary variables diff --git a/preprocessor/ComputingTasks.cc b/preprocessor/ComputingTasks.cc index 5488b0905..a579ebb6f 100644 --- a/preprocessor/ComputingTasks.cc +++ b/preprocessor/ComputingTasks.cc @@ -2343,15 +2343,16 @@ WriteLatexDynamicModelStatement::writeJsonOutput(ostream &output) const output << "{\"statementName\": \"write_latex_dynamic_model\"}"; } -WriteLatexStaticModelStatement::WriteLatexStaticModelStatement(const StaticModel &static_model_arg) : - static_model(static_model_arg) +WriteLatexStaticModelStatement::WriteLatexStaticModelStatement(const StaticModel &static_model_arg, bool write_equation_tags_arg) : + static_model(static_model_arg), + write_equation_tags(write_equation_tags_arg) { } void WriteLatexStaticModelStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { - static_model.writeLatexFile(basename); + static_model.writeLatexFile(basename, write_equation_tags); } void @@ -2360,15 +2361,16 @@ WriteLatexStaticModelStatement::writeJsonOutput(ostream &output) const output << "{\"statementName\": \"write_latex_static_model\"}"; } -WriteLatexOriginalModelStatement::WriteLatexOriginalModelStatement(const DynamicModel &original_model_arg) : - original_model(original_model_arg) +WriteLatexOriginalModelStatement::WriteLatexOriginalModelStatement(const DynamicModel &original_model_arg, bool write_equation_tags_arg) : + original_model(original_model_arg), + write_equation_tags(write_equation_tags_arg) { } void WriteLatexOriginalModelStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { - original_model.writeLatexOriginalFile(basename); + original_model.writeLatexOriginalFile(basename, write_equation_tags); } void diff --git a/preprocessor/ComputingTasks.hh b/preprocessor/ComputingTasks.hh index a222950af..d49d9ea93 100644 --- a/preprocessor/ComputingTasks.hh +++ b/preprocessor/ComputingTasks.hh @@ -609,8 +609,9 @@ class WriteLatexStaticModelStatement : public Statement { private: const StaticModel &static_model; + const bool write_equation_tags; public: - WriteLatexStaticModelStatement(const StaticModel &static_model_arg); + WriteLatexStaticModelStatement(const StaticModel &static_model_arg, bool write_equation_tags_arg); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; virtual void writeJsonOutput(ostream &output) const; }; @@ -619,8 +620,9 @@ class WriteLatexOriginalModelStatement : public Statement { private: const DynamicModel &original_model; + const bool write_equation_tags; public: - WriteLatexOriginalModelStatement(const DynamicModel &original_model_arg); + WriteLatexOriginalModelStatement(const DynamicModel &original_model_arg, bool write_equation_tags_arg); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; virtual void writeJsonOutput(ostream &output) const; }; diff --git a/preprocessor/DynamicModel.cc b/preprocessor/DynamicModel.cc index c927a8736..207066ebb 100644 --- a/preprocessor/DynamicModel.cc +++ b/preprocessor/DynamicModel.cc @@ -3751,7 +3751,8 @@ DynamicModel::cloneDynamic(DynamicModel &dynamic_model) const // Convert static_only equations for (size_t i = 0; i < static_only_equations.size(); i++) dynamic_model.addStaticOnlyEquation(static_only_equations[i]->cloneDynamic(dynamic_model), - static_only_equations_lineno[i]); + static_only_equations_lineno[i], + static_only_equations_equation_tags[i]); dynamic_model.setLeadsLagsOrig(); } @@ -3862,12 +3863,14 @@ DynamicModel::toStatic(StaticModel &static_model) const { // Detect if equation is marked [dynamic] bool is_dynamic_only = false; + vector > eq_tags; for (vector > >::const_iterator it = equation_tags.begin(); it != equation_tags.end(); ++it) - if (it->first == i && it->second.first == "dynamic") + if (it->first == i) { - is_dynamic_only = true; - break; + eq_tags.push_back(it->second); + if (it->second.first == "dynamic") + is_dynamic_only = true; } try @@ -3875,11 +3878,11 @@ DynamicModel::toStatic(StaticModel &static_model) const // If yes, replace it by an equation marked [static] if (is_dynamic_only) { - static_model.addEquation(static_only_equations[static_only_index]->toStatic(static_model), static_only_equations_lineno[static_only_index]); + static_model.addEquation(static_only_equations[static_only_index]->toStatic(static_model), static_only_equations_lineno[static_only_index], static_only_equations_equation_tags[static_only_index]); static_only_index++; } else - static_model.addEquation(equations[i]->toStatic(static_model), equations_lineno[i]); + static_model.addEquation(equations[i]->toStatic(static_model), equations_lineno[i], eq_tags); } catch (DataTree::DivisionByZeroException) { @@ -4452,9 +4455,9 @@ DynamicModel::writeLatexFile(const string &basename, const bool write_equation_t } void -DynamicModel::writeLatexOriginalFile(const string &basename) const +DynamicModel::writeLatexOriginalFile(const string &basename, const bool write_equation_tags) const { - writeLatexModelFile(basename + "_original", oLatexDynamicModel); + writeLatexModelFile(basename + "_original", oLatexDynamicModel, write_equation_tags); } void @@ -4767,13 +4770,18 @@ DynamicModel::isModelLocalVariableUsed() const } void -DynamicModel::addStaticOnlyEquation(expr_t eq, int lineno) +DynamicModel::addStaticOnlyEquation(expr_t eq, int lineno, const vector > &eq_tags) { BinaryOpNode *beq = dynamic_cast(eq); assert(beq != NULL && beq->get_op_code() == oEqual); + vector > soe_eq_tags; + for (size_t i = 0; i < eq_tags.size(); i++) + soe_eq_tags.push_back(eq_tags[i]); + static_only_equations.push_back(beq); static_only_equations_lineno.push_back(lineno); + static_only_equations_equation_tags.push_back(soe_eq_tags); } size_t diff --git a/preprocessor/DynamicModel.hh b/preprocessor/DynamicModel.hh index 8b68744d8..ada85d140 100644 --- a/preprocessor/DynamicModel.hh +++ b/preprocessor/DynamicModel.hh @@ -39,6 +39,9 @@ private: //! Stores line numbers of equations declared as [static] vector static_only_equations_lineno; + //! Stores the equation tags of equations declared as [static] + vector > > static_only_equations_equation_tags; + typedef map, int> deriv_id_table_t; //! Maps a pair (symbol_id, lag) to a deriv ID deriv_id_table_t deriv_id_table; @@ -298,7 +301,7 @@ public: void replaceMyEquations(DynamicModel &dynamic_model) const; //! Adds an equation marked as [static] - void addStaticOnlyEquation(expr_t eq, int lineno); + void addStaticOnlyEquation(expr_t eq, int lineno, const vector > &eq_tags); //! Returns number of static only equations size_t staticOnlyEquationsNbr() const; @@ -310,7 +313,7 @@ public: void writeLatexFile(const string &basename, const bool write_equation_tags) const; //! Writes LaTeX file with the equations of the dynamic model (for the original model) - void writeLatexOriginalFile(const string &basename) const; + void writeLatexOriginalFile(const string &basename, const bool write_equation_tags) const; virtual int getDerivID(int symb_id, int lag) const throw (UnknownDerivIDException); virtual int getDynJacobianCol(int deriv_id) const throw (UnknownDerivIDException); diff --git a/preprocessor/DynareBison.yy b/preprocessor/DynareBison.yy index d9e3169ea..0d05478e0 100644 --- a/preprocessor/DynareBison.yy +++ b/preprocessor/DynareBison.yy @@ -2118,11 +2118,15 @@ write_latex_dynamic_model : WRITE_LATEX_DYNAMIC_MODEL ';' ; write_latex_static_model : WRITE_LATEX_STATIC_MODEL ';' - { driver.write_latex_static_model(); } + { driver.write_latex_static_model(false); } + | WRITE_LATEX_STATIC_MODEL '(' WRITE_EQUATION_TAGS ')' ';' + { driver.write_latex_static_model(true); } ; write_latex_original_model : WRITE_LATEX_ORIGINAL_MODEL ';' - { driver.write_latex_original_model(); } + { driver.write_latex_original_model(false); } + | WRITE_LATEX_ORIGINAL_MODEL '(' WRITE_EQUATION_TAGS ')' ';' + { driver.write_latex_original_model(true); } ; shock_decomposition : SHOCK_DECOMPOSITION ';' diff --git a/preprocessor/ModelTree.cc b/preprocessor/ModelTree.cc index 2282f292d..61be06e4f 100644 --- a/preprocessor/ModelTree.cc +++ b/preprocessor/ModelTree.cc @@ -1690,7 +1690,7 @@ ModelTree::writeLatexModelFile(const string &basename, ExprNodeOutputType output content_output << iteqt->second.first; - if (iteqt->second.second.empty()) + if (!(iteqt->second.second.empty())) content_output << "= `" << iteqt->second.second << "'"; wrote_eq_tag = true; @@ -1723,7 +1723,7 @@ ModelTree::addEquation(expr_t eq, int lineno) } void -ModelTree::addEquation(expr_t eq, int lineno, vector > &eq_tags) +ModelTree::addEquation(expr_t eq, int lineno, const vector > &eq_tags) { int n = equations.size(); for (size_t i = 0; i < eq_tags.size(); i++) diff --git a/preprocessor/ModelTree.hh b/preprocessor/ModelTree.hh index 24db008ab..be6b66cbb 100644 --- a/preprocessor/ModelTree.hh +++ b/preprocessor/ModelTree.hh @@ -200,7 +200,7 @@ protected: void compileModelEquations(ostream &code_file, unsigned int &instruction_number, const temporary_terms_t &tt, const map_idx_t &map_idx, bool dynamic, bool steady_dynamic) const; //! Writes LaTeX model file - void writeLatexModelFile(const string &basename, ExprNodeOutputType output_type, const bool write_equation_tags = false) const; + void writeLatexModelFile(const string &basename, ExprNodeOutputType output_type, const bool write_equation_tags) const; //! Sparse matrix of double to store the values of the Jacobian /*! First index is equation number, second index is endogenous type specific ID */ @@ -318,7 +318,7 @@ public: //! Declare a node as an equation of the model; also give its line number void addEquation(expr_t eq, int lineno); //! Declare a node as an equation of the model, also giving its tags - void addEquation(expr_t eq, int lineno, vector > &eq_tags); + void addEquation(expr_t eq, int lineno, const vector > &eq_tags); //! Declare a node as an auxiliary equation of the model, adding it at the end of the list of auxiliary equations void addAuxEquation(expr_t eq); //! Returns the number of equations in the model diff --git a/preprocessor/ParsingDriver.cc b/preprocessor/ParsingDriver.cc index f8b1e8814..679ae3196 100644 --- a/preprocessor/ParsingDriver.cc +++ b/preprocessor/ParsingDriver.cc @@ -1968,15 +1968,15 @@ ParsingDriver::write_latex_dynamic_model(bool write_equation_tags) } void -ParsingDriver::write_latex_static_model() +ParsingDriver::write_latex_static_model(bool write_equation_tags) { - mod_file->addStatement(new WriteLatexStaticModelStatement(mod_file->static_model)); + mod_file->addStatement(new WriteLatexStaticModelStatement(mod_file->static_model, write_equation_tags)); } void -ParsingDriver::write_latex_original_model() +ParsingDriver::write_latex_original_model(bool write_equation_tags) { - mod_file->addStatement(new WriteLatexOriginalModelStatement(mod_file->original_model)); + mod_file->addStatement(new WriteLatexOriginalModelStatement(mod_file->original_model, write_equation_tags)); } void @@ -2212,7 +2212,7 @@ ParsingDriver::add_model_equal(expr_t arg1, expr_t arg2) if (!id->isInStaticForm()) error("An equation tagged [static] cannot contain leads, lags, expectations or STEADY_STATE operators"); - dynamic_model->addStaticOnlyEquation(id, location.begin.line); + dynamic_model->addStaticOnlyEquation(id, location.begin.line, eq_tags); } else model_tree->addEquation(id, location.begin.line, eq_tags); diff --git a/preprocessor/ParsingDriver.hh b/preprocessor/ParsingDriver.hh index 80eb4c0a2..f7bb115b3 100644 --- a/preprocessor/ParsingDriver.hh +++ b/preprocessor/ParsingDriver.hh @@ -563,9 +563,9 @@ public: //! Adds a write_latex_dynamic_model statement void write_latex_dynamic_model(bool write_equation_tags); //! Adds a write_latex_static_model statement - void write_latex_static_model(); + void write_latex_static_model(bool write_equation_tags); //! Adds a write_latex_original_model statement - void write_latex_original_model(); + void write_latex_original_model(bool write_equation_tags); //! BVAR marginal density void bvar_density(string *maxnlags); //! BVAR forecast diff --git a/preprocessor/StaticModel.cc b/preprocessor/StaticModel.cc index a398d1c4f..dc24f6ee6 100644 --- a/preprocessor/StaticModel.cc +++ b/preprocessor/StaticModel.cc @@ -2112,9 +2112,9 @@ StaticModel::writeChainRuleDerivative(ostream &output, int eqr, int varr, int la } void -StaticModel::writeLatexFile(const string &basename) const +StaticModel::writeLatexFile(const string &basename, bool write_equation_tags) const { - writeLatexModelFile(basename + "_static", oLatexStaticModel); + writeLatexModelFile(basename + "_static", oLatexStaticModel, write_equation_tags); } void diff --git a/preprocessor/StaticModel.hh b/preprocessor/StaticModel.hh index 2dcc81976..8c0e9d443 100644 --- a/preprocessor/StaticModel.hh +++ b/preprocessor/StaticModel.hh @@ -183,7 +183,7 @@ public: void writeParamsDerivativesFile(const string &basename, bool julia) const; //! Writes LaTeX file with the equations of the static model - void writeLatexFile(const string &basename) const; + void writeLatexFile(const string &basename, const bool write_equation_tags) const; //! Writes initializations in oo_.steady_state or steady state file for the auxiliary variables void writeAuxVarInitval(ostream &output, ExprNodeOutputType output_type) const; From fe14007a16534ad60a26b3b919eef584bd0bca6e Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 24 Aug 2017 16:43:36 +0200 Subject: [PATCH 30/47] preprocessor: ramsey_model: remove unused symbol_list syntax. Closes #1392 --- preprocessor/ComputingTasks.cc | 4 +--- preprocessor/ComputingTasks.hh | 4 +--- preprocessor/DynareBison.yy | 4 ---- preprocessor/ParsingDriver.cc | 3 +-- 4 files changed, 3 insertions(+), 12 deletions(-) diff --git a/preprocessor/ComputingTasks.cc b/preprocessor/ComputingTasks.cc index a579ebb6f..a9320ed15 100644 --- a/preprocessor/ComputingTasks.cc +++ b/preprocessor/ComputingTasks.cc @@ -363,9 +363,7 @@ ForecastStatement::writeJsonOutput(ostream &output) const output << "}"; } -RamseyModelStatement::RamseyModelStatement(const SymbolList &symbol_list_arg, - const OptionsList &options_list_arg) : - symbol_list(symbol_list_arg), +RamseyModelStatement::RamseyModelStatement(const OptionsList &options_list_arg) : options_list(options_list_arg) { } diff --git a/preprocessor/ComputingTasks.hh b/preprocessor/ComputingTasks.hh index d49d9ea93..2e5a69700 100644 --- a/preprocessor/ComputingTasks.hh +++ b/preprocessor/ComputingTasks.hh @@ -133,11 +133,9 @@ public: class RamseyModelStatement : public Statement { private: - const SymbolList symbol_list; const OptionsList options_list; public: - RamseyModelStatement(const SymbolList &symbol_list_arg, - const OptionsList &options_list_arg); + RamseyModelStatement(const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; virtual void writeJsonOutput(ostream &output) const; diff --git a/preprocessor/DynareBison.yy b/preprocessor/DynareBison.yy index 0d05478e0..b8a6107c3 100644 --- a/preprocessor/DynareBison.yy +++ b/preprocessor/DynareBison.yy @@ -2034,10 +2034,6 @@ ramsey_model : RAMSEY_MODEL ';' { driver.ramsey_model(); } | RAMSEY_MODEL '(' ramsey_model_options_list ')' ';' { driver.ramsey_model(); } - | RAMSEY_MODEL symbol_list ';' - { driver.ramsey_model(); } - | RAMSEY_MODEL '(' ramsey_model_options_list ')' symbol_list ';' - { driver.ramsey_model(); } ; ramsey_policy : RAMSEY_POLICY ';' diff --git a/preprocessor/ParsingDriver.cc b/preprocessor/ParsingDriver.cc index 679ae3196..b606365dc 100644 --- a/preprocessor/ParsingDriver.cc +++ b/preprocessor/ParsingDriver.cc @@ -1929,8 +1929,7 @@ ParsingDriver::ramsey_model() { if (!mod_file->symbol_table.exists("optimal_policy_discount_factor")) declare_optimal_policy_discount_factor_parameter(data_tree->One); - mod_file->addStatement(new RamseyModelStatement(symbol_list, options_list)); - symbol_list.clear(); + mod_file->addStatement(new RamseyModelStatement(options_list)); options_list.clear(); } From 4a5b72af15da8b083d7eee58d273b2a5ee6d461d Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Thu, 24 Aug 2017 18:13:33 +0200 Subject: [PATCH 31/47] check_list_of_variables.m: Cosmetic change to warning message --- matlab/check_list_of_variables.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/check_list_of_variables.m b/matlab/check_list_of_variables.m index 7bf05e478..88312097a 100644 --- a/matlab/check_list_of_variables.m +++ b/matlab/check_list_of_variables.m @@ -106,7 +106,7 @@ elseif isempty(varlist) && isempty(options_.endo_vars_for_moment_computations_in end if ~isempty(cas) string = [ cas , ' will be computed for the ' num2str(M_.endo_nbr) ' endogenous variables']; - string = [ string ' of your model, this can be very long....']; + string = [ string ' of your model, this can take a long time ....']; format_text(string, 10) if options_.nointeractive % Default behaviour is to consider all the endogenous variables. From 14bccd8d20337e810f42b63af210d664171ad6ee Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 25 Aug 2017 12:07:55 +0200 Subject: [PATCH 32/47] preprocessor: fix spacing in message --- preprocessor/DynareMain.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/preprocessor/DynareMain.cc b/preprocessor/DynareMain.cc index 49c260252..62ae04270 100644 --- a/preprocessor/DynareMain.cc +++ b/preprocessor/DynareMain.cc @@ -62,7 +62,7 @@ usage() #if defined(_WIN32) || defined(__CYGWIN32__) || defined(__MINGW32__) << " [cygwin] [msvc] [mingw]" #endif - << "[json=parse|check|transform|compute] [jsonstdout] [onlyjson] [jsonderivsimple]" + << " [json=parse|check|transform|compute] [jsonstdout] [onlyjson] [jsonderivsimple]" << endl; exit(EXIT_FAILURE); } From 38996c7449c16005180c26d766461eb5c62563c3 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 25 Aug 2017 12:11:12 +0200 Subject: [PATCH 33/47] preprocessor: add missing option to dynare options message --- preprocessor/DynareMain.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/preprocessor/DynareMain.cc b/preprocessor/DynareMain.cc index 62ae04270..5e5ff6ca5 100644 --- a/preprocessor/DynareMain.cc +++ b/preprocessor/DynareMain.cc @@ -62,7 +62,7 @@ usage() #if defined(_WIN32) || defined(__CYGWIN32__) || defined(__MINGW32__) << " [cygwin] [msvc] [mingw]" #endif - << " [json=parse|check|transform|compute] [jsonstdout] [onlyjson] [jsonderivsimple]" + << " [json=parse|check|transform|compute] [jsonstdout] [onlyjson] [jsonderivsimple] [nopathchange]" << endl; exit(EXIT_FAILURE); } From d730353f4e5b0ae43df9fe0ce40158c61f229103 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 25 Aug 2017 13:04:40 +0200 Subject: [PATCH 34/47] check_matlab_path: fix English --- matlab/check_matlab_path.m | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/matlab/check_matlab_path.m b/matlab/check_matlab_path.m index 8f0d187c3..58a0babc1 100644 --- a/matlab/check_matlab_path.m +++ b/matlab/check_matlab_path.m @@ -52,7 +52,7 @@ else % Dynare is on top of matlab's path! Nothing to do here... return else - str0 = sprintf('Dynare is not on top of matlab''s path!'); + str0 = sprintf('Dynare is not on top of the Matlab/Octave path!'); % Check that this will not create a problem MATLAB_PATH_ = path2cell(MATLAB_PATH); DYNARE_ROUTINES = getallroutinenames(DYNARE_PATH, getalldirectories(DYNARE_PATH)); @@ -66,19 +66,19 @@ else warning off backtrace skipline() if length(COMMON_ROUTINES)==1 - warning(sprintf('%s This can cause problems because the Dynare version of %s will be overriden.', str0, COMMON_ROUTINES{1})); + warning(sprintf('%s This can cause problems because the Dynare implementation of %s will be overriden.', str0, COMMON_ROUTINES{1})); else str1 = repmat('%s, ', 1, length(COMMON_ROUTINES)-1); str2 = 'and %s '; - str3 = sprintf(['%s This can cause problems because the Dynare versions of ' str1, str2, 'will be overriden.'], str0, COMMON_ROUTINES{:}); + str3 = sprintf(['%s This can cause problems because the Dynare implementations of ' str1, str2, 'will be overriden.'], str0, COMMON_ROUTINES{:}); warning(str3); end if change_path_flag skipline() - msg = sprintf('I put %s on top of your matlab''s path. Note that this is a', DYNARE_PATH); - msg = sprintf(' %s a temporary change (ie will not affect future matlab''s session).', msg); - msg = sprintf(' %s If the ordering was intentional, ie if you really want to override the routines distributed with Dynare,', msg); - msg = sprintf(' %s you can change this behaviour using option nopathchange (see the reference manual).', msg); + msg = sprintf(['I put %s on top of your Matlab/Ocatve path.' ... + '\nNote that this is a temporary change (i.e. it will not affect future Matlab/Octave sessions).\n' ... + '\nIf the ordering was intentional, i.e. if you really want to override the routines distributed with Dynare,' ... + ' you can change this behavior using the ''nopathchange'' option (see the reference manual).'], DYNARE_PATH); warning(msg); skipline() rmpath(DYNARE_PATH) @@ -96,9 +96,9 @@ else MATLAB_PATH = path2cell(MATLAB_PATH); for i=1:length(mexpath) if exist([mexpath{i} filesep 'mjdgges.' mexext],'file') && ismember([DYNARE_PATH filesep 'qz'],MATLAB_PATH) - msg = sprintf(['You put all the dynare/matlab subfolders in matlab''s path! Only ' ... - 'the dynare/matlab folder (without subfolders)\nshould be in the ' ... - 'path, Dynare will automatically add any required subfolders in the ' ... + msg = sprintf(['You put all the subfolders of the Dynare matlab folder in the Matlab/Octave path! Only ' ... + 'the dynare ' filesep 'matlab folder (without subfolders)\nshould be in the ' ... + 'path. Dynare automatically adds any required subfolders to the ' ... 'path.']); error(msg) end From 41e6ecaacdead14b48434376e26646f9944614dd Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 25 Aug 2017 13:05:40 +0200 Subject: [PATCH 35/47] bug: nopathchange was always being set, regardless of whether or not the flag was passed --- matlab/dynare.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/matlab/dynare.m b/matlab/dynare.m index 267d2d202..ad9382b8f 100644 --- a/matlab/dynare.m +++ b/matlab/dynare.m @@ -51,9 +51,9 @@ change_path_flag = true; % Filter out some options. if nargin>1 id = strfind(varargin,'nopathchange'); - if ~isempty(id) + if ~all(cellfun(@isempty, id)) change_path_flag = false; - varargin(id{1}) = []; + varargin(cellfun(@isempty, id) == 0) = []; end end From 1c485c894fc4a326bfd80d60b0f77e2ddb240a48 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 25 Aug 2017 14:19:48 +0200 Subject: [PATCH 36/47] Add nopreprocessoroutput option to dynare. Closes #1390 --- matlab/dynare.m | 34 ++++++++++++++++++++++++++-------- preprocessor/DynareMain.cc | 2 +- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/matlab/dynare.m b/matlab/dynare.m index ad9382b8f..2cb1bdee0 100644 --- a/matlab/dynare.m +++ b/matlab/dynare.m @@ -49,19 +49,25 @@ end change_path_flag = true; % Filter out some options. +preprocessoroutput = true; if nargin>1 id = strfind(varargin,'nopathchange'); if ~all(cellfun(@isempty, id)) change_path_flag = false; varargin(cellfun(@isempty, id) == 0) = []; end + id = strfind(varargin, 'nopreprocessoroutput'); + if ~all(cellfun(@isempty, id)) + preprocessoroutput = false; + varargin(cellfun(@isempty, id) == 0) = []; + end end % Check matlab path check_matlab_path(change_path_flag); % Detect if MEX files are present; if not, use alternative M-files -dynareroot = dynare_config; +dynareroot = dynare_config('', preprocessoroutput); warning_config() @@ -177,10 +183,14 @@ end if isempty(strfind(arch, '64')) arch_ext = '32'; - disp('Using 32-bit preprocessor'); + if preprocessoroutput + disp('Using 32-bit preprocessor'); + end else arch_ext = '64'; - disp('Using 64-bit preprocessor'); + if preprocessoroutput + disp('Using 64-bit preprocessor'); + end end % Read options from the first line in mod/dyn file. @@ -208,18 +218,26 @@ for i=1:length(varargin) command = [command ' ' varargin{i}]; end -fprintf('Calling Dynare with arguments: '); -disp(varargin); +if preprocessoroutput + fprintf('Calling Dynare with arguments: '); + disp(varargin); +end [status, result] = system(command); -disp(result) +if status ~= 0 || preprocessoroutput + disp(result) +end if ismember('onlymacro', varargin) - disp('Preprocesser stopped after macroprocessing step because of ''onlymacro'' option.'); + if preprocessoroutput + disp('Preprocesser stopped after macroprocessing step because of ''onlymacro'' option.'); + end return end if ismember('onlyjson', varargin) - disp('Preprocesser stopped after preprocessing step because of ''onlyjson'' option.'); + if preprocessoroutput + disp('Preprocesser stopped after preprocessing step because of ''onlyjson'' option.'); + end return; end diff --git a/preprocessor/DynareMain.cc b/preprocessor/DynareMain.cc index 5e5ff6ca5..bee2ce3a3 100644 --- a/preprocessor/DynareMain.cc +++ b/preprocessor/DynareMain.cc @@ -62,7 +62,7 @@ usage() #if defined(_WIN32) || defined(__CYGWIN32__) || defined(__MINGW32__) << " [cygwin] [msvc] [mingw]" #endif - << " [json=parse|check|transform|compute] [jsonstdout] [onlyjson] [jsonderivsimple] [nopathchange]" + << " [json=parse|check|transform|compute] [jsonstdout] [onlyjson] [jsonderivsimple] [nopathchange] [nopreprocessoroutput]" << endl; exit(EXIT_FAILURE); } From a8073a8d31f0a7cf2cd8f9f533e24b5902360cb4 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 25 Aug 2017 17:40:46 +0200 Subject: [PATCH 37/47] doc: add documentation for nopreprocessoroutput option. #1390 --- doc/dynare.texi | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/dynare.texi b/doc/dynare.texi index 22c811370..3daf01406 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -901,6 +901,10 @@ used. Alternatively, the path can be temporarly modified by the user at the top of the @file{*.mod} file (using Matlab/Octave's @code{addpath} command). +@item nopreprocessoroutput +Prevent Dynare from printing the output of the steps leading up to the +preprocessor as well as the preprocessor output itself. + @item mingw Tells Dynare that your MATLAB is configured for compiling MEX files with the MinGW-compiler from TDM-GCC (@pxref{Compiler installation}). This option is From 628c4cf27bc4180a0e4bf284201b86abed167a81 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Mon, 28 Aug 2017 15:14:11 +0200 Subject: [PATCH 38/47] preprocessor: add model_local_variable declaration for declaring model local variables with tex names. Closes #563 --- doc/dynare.texi | 39 +++++++++++++----- preprocessor/DataTree.cc | 1 + preprocessor/DataTree.hh | 2 + preprocessor/DynamicModel.cc | 12 +++--- preprocessor/DynareBison.yy | 19 ++++++++- preprocessor/DynareFlex.ll | 1 + preprocessor/ModelTree.cc | 74 +++++++++++++++++++---------------- preprocessor/ParsingDriver.cc | 9 +++++ preprocessor/ParsingDriver.hh | 2 + 9 files changed, 109 insertions(+), 50 deletions(-) diff --git a/doc/dynare.texi b/doc/dynare.texi index 3daf01406..90d6e4ed4 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -1539,6 +1539,24 @@ a variable with a multiplicative trend). @end deffn +@anchor{model_local_variable} +@deffn Command model_local_variable @var{VARIABLE_NAME} [$@var{LATEX_NAME}$] @dots{}; + +@descriptionhead + +This optional command declares a model local variable. @xref{Conventions}, for +the syntax of @var{VARIABLE_NAME}. As you can create model local variables on +the fly in the model block (@pxref{model_local_variables_in_model_block}), the +interest of this command is primarily to assign a @var{LATEX_NAME} to the model +local variable. + +@examplehead + +@example +model_local_variable GDP_US $GDPUS$; +@end example + +@end deffn @node Expressions @section Expressions @@ -1918,16 +1936,19 @@ equation. A homogenous equation looks like: @var{MODEL_EXPRESSION}; @end example +@anchor{model_local_variables_in_model_block} Inside the model block, Dynare allows the creation of @emph{model-local -variables}, which constitute a simple way to share a common expression -between several equations. The syntax consists of a pound sign -(@code{#}) followed by the name of the new model local variable (which -must @strong{not} be declared as in @ref{Variable declarations}), an equal -sign, and the expression for which this new variable will stand. Later -on, every time this variable appears in the model, Dynare will -substitute it by the expression assigned to the variable. Note that the -scope of this variable is restricted to the model block; it cannot be -used outside. A model local variable declaration looks like: +variables}, which constitute a simple way to share a common expression between +several equations. The syntax consists of a pound sign (@code{#}) followed by +the name of the new model local variable (which must @strong{not} be declared +as in @ref{Variable declarations}, but may have been declared by +@ref{model_local_variable}), an equal sign, and the expression for which this +new variable will stand. Later on, every time this variable appears in the +model, Dynare will substitute it by the expression assigned to the +variable. Note that the scope of this variable is restricted to the model +block; it cannot be used outside. To assign a @LaTeX{} name to the model local +variable, use the declaration syntax outlined by @ref{model_local_variable}. A +model local variable declaration looks like: @example # @var{VARIABLE_NAME} = @var{MODEL_EXPRESSION}; @end example diff --git a/preprocessor/DataTree.cc b/preprocessor/DataTree.cc index e748e7598..dac7c157b 100644 --- a/preprocessor/DataTree.cc +++ b/preprocessor/DataTree.cc @@ -507,6 +507,7 @@ DataTree::AddLocalVariable(int symb_id, expr_t value) throw (LocalVariableExcept throw LocalVariableException(symbol_table.getName(symb_id)); local_variables_table[symb_id] = value; + local_variables_vector.push_back(symb_id); } expr_t diff --git a/preprocessor/DataTree.hh b/preprocessor/DataTree.hh index 5efb57bdb..26a438604 100644 --- a/preprocessor/DataTree.hh +++ b/preprocessor/DataTree.hh @@ -84,6 +84,8 @@ protected: //! Stores local variables value (maps symbol ID to corresponding node) map local_variables_table; + //! Stores the order of appearance of local variables in the model block. Needed following change in #563 + vector local_variables_vector; //! Internal implementation of AddVariable(), without the check on the lag VariableNode *AddVariableInternal(int symb_id, int lag); diff --git a/preprocessor/DynamicModel.cc b/preprocessor/DynamicModel.cc index 207066ebb..18024f2cf 100644 --- a/preprocessor/DynamicModel.cc +++ b/preprocessor/DynamicModel.cc @@ -3728,9 +3728,9 @@ DynamicModel::cloneDynamic(DynamicModel &dynamic_model) const assert(&symbol_table == &dynamic_model.symbol_table); // Convert model local variables (need to be done first) - for (map::const_iterator it = local_variables_table.begin(); - it != local_variables_table.end(); it++) - dynamic_model.AddLocalVariable(it->first, it->second->cloneDynamic(dynamic_model)); + for (vector::const_iterator it = local_variables_vector.begin(); + it != local_variables_vector.end(); it++) + dynamic_model.AddLocalVariable(*it, local_variables_table.find(*it)->second->cloneDynamic(dynamic_model)); // Convert equations for (size_t i = 0; i < equations.size(); i++) @@ -3853,9 +3853,9 @@ DynamicModel::toStatic(StaticModel &static_model) const assert(&symbol_table == &static_model.symbol_table); // Convert model local variables (need to be done first) - for (map::const_iterator it = local_variables_table.begin(); - it != local_variables_table.end(); it++) - static_model.AddLocalVariable(it->first, it->second->toStatic(static_model)); + for (vector::const_iterator it = local_variables_vector.begin(); + it != local_variables_vector.end(); it++) + static_model.AddLocalVariable(*it, local_variables_table.find(*it)->second->toStatic(static_model)); // Convert equations int static_only_index = 0; diff --git a/preprocessor/DynareBison.yy b/preprocessor/DynareBison.yy index b8a6107c3..52931d891 100644 --- a/preprocessor/DynareBison.yy +++ b/preprocessor/DynareBison.yy @@ -129,7 +129,7 @@ class ParsingDriver; %token TEX RAMSEY_MODEL RAMSEY_POLICY RAMSEY_CONSTRAINTS PLANNER_DISCOUNT DISCRETIONARY_POLICY DISCRETIONARY_TOL %token TEX_NAME %token UNIFORM_PDF UNIT_ROOT_VARS USE_DLL USEAUTOCORR GSA_SAMPLE_FILE USE_UNIVARIATE_FILTERS_IF_SINGULARITY_IS_DETECTED -%token VALUES VAR VAREXO VAREXO_DET VAROBS PREDETERMINED_VARIABLES PLOT_SHOCK_DECOMPOSITION +%token VALUES VAR VAREXO VAREXO_DET VAROBS PREDETERMINED_VARIABLES PLOT_SHOCK_DECOMPOSITION MODEL_LOCAL_VARIABLE %token WRITE_LATEX_DYNAMIC_MODEL WRITE_LATEX_STATIC_MODEL WRITE_LATEX_ORIGINAL_MODEL %token XLS_SHEET XLS_RANGE LMMCP OCCBIN BANDPASS_FILTER COLORMAP QOQ YOY AOA %left COMMA @@ -203,6 +203,7 @@ statement : parameters | varexo | varexo_det | predetermined_variables + | model_local_variable | change_type | periods | model @@ -381,6 +382,8 @@ predetermined_variables : PREDETERMINED_VARIABLES predetermined_variables_list ' parameters : PARAMETERS parameter_list ';'; +model_local_variable : MODEL_LOCAL_VARIABLE model_local_variable_list ';'; + named_var_elem : symbol EQUAL QUOTED_STRING { pair *pr = new pair($1, $3); @@ -525,6 +528,20 @@ predetermined_variables_list : predetermined_variables_list symbol { driver.add_predetermined_variable($1); } ; +model_local_variable_list : model_local_variable_list symbol + { driver.declare_model_local_variable($2); } + | model_local_variable_list COMMA symbol + { driver.declare_model_local_variable($3); } + | symbol + { driver.declare_model_local_variable($1); } + | model_local_variable_list symbol TEX_NAME + { driver.declare_model_local_variable($2, $3); } + | model_local_variable_list COMMA symbol TEX_NAME + { driver.declare_model_local_variable($3, $4); } + | symbol TEX_NAME + { driver.declare_model_local_variable($1, $2); } + ; + change_type : CHANGE_TYPE '(' change_type_arg ')' change_type_var_list ';' { driver.change_type($3, $5); } ; diff --git a/preprocessor/DynareFlex.ll b/preprocessor/DynareFlex.ll index 9553fab45..092d39d9b 100644 --- a/preprocessor/DynareFlex.ll +++ b/preprocessor/DynareFlex.ll @@ -111,6 +111,7 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2 log_trend_var {BEGIN DYNARE_STATEMENT; return token::LOG_TREND_VAR;} predetermined_variables {BEGIN DYNARE_STATEMENT; return token::PREDETERMINED_VARIABLES;} parameters {BEGIN DYNARE_STATEMENT; return token::PARAMETERS;} +model_local_variable {BEGIN DYNARE_STATEMENT; return token::MODEL_LOCAL_VARIABLE;} periods {BEGIN DYNARE_STATEMENT; return token::PERIODS;} model_info {BEGIN DYNARE_STATEMENT; return token::MODEL_INFO;} estimation {BEGIN DYNARE_STATEMENT; return token::ESTIMATION;} diff --git a/preprocessor/ModelTree.cc b/preprocessor/ModelTree.cc index 61be06e4f..cb3523a62 100644 --- a/preprocessor/ModelTree.cc +++ b/preprocessor/ModelTree.cc @@ -1418,24 +1418,25 @@ ModelTree::writeModelLocalVariables(ostream &output, ExprNodeOutputType output_t for (size_t i = 0; i < equations.size(); i++) equations[i]->collectVariables(eModelLocalVariable, used_local_vars); - for (set::const_iterator it = used_local_vars.begin(); - it != used_local_vars.end(); ++it) - { - int id = *it; - expr_t value = local_variables_table.find(id)->second; - value->writeExternalFunctionOutput(output, output_type, tt, tef_terms); + for (vector::const_iterator it = local_variables_vector.begin(); + it != local_variables_vector.end(); it++) + if (used_local_vars.find(*it) != used_local_vars.end()) + { + int id = *it; + expr_t value = local_variables_table.find(id)->second; + value->writeExternalFunctionOutput(output, output_type, tt, tef_terms); - if (IS_C(output_type)) - output << "double "; - else if (IS_JULIA(output_type)) - output << " @inbounds "; + if (IS_C(output_type)) + output << "double "; + else if (IS_JULIA(output_type)) + output << " @inbounds "; - /* We append underscores to avoid name clashes with "g1" or "oo_" (see - also VariableNode::writeOutput) */ - output << symbol_table.getName(id) << "__ = "; - value->writeOutput(output, output_type, tt, tef_terms); - output << ";" << endl; - } + /* We append underscores to avoid name clashes with "g1" or "oo_" (see + also VariableNode::writeOutput) */ + output << symbol_table.getName(id) << "__ = "; + value->writeOutput(output, output_type, tt, tef_terms); + output << ";" << endl; + } } void @@ -1468,21 +1469,26 @@ ModelTree::writeJsonModelLocalVariables(ostream &output, deriv_node_temp_terms_t } output << "]" << ", \"model_local_variables\": ["; - for (set::const_iterator it = used_local_vars.begin(); - it != used_local_vars.end(); ++it) - { - if (it != used_local_vars.begin()) - output << ", "; - int id = *it; - expr_t value = local_variables_table.find(id)->second; + bool printed = false; + for (vector::const_iterator it = local_variables_vector.begin(); + it != local_variables_vector.end(); it++) + if (used_local_vars.find(*it) != used_local_vars.end()) + { + int id = *it; + expr_t value = local_variables_table.find(id)->second; - /* We append underscores to avoid name clashes with "g1" or "oo_" (see - also VariableNode::writeOutput) */ - output << "{\"variable\": \"" << symbol_table.getName(id) << "__\"" - << ", \"value\": \""; - value->writeJsonOutput(output, tt, tef_terms); - output << "\"}" << endl; - } + if (printed) + output << ", "; + else + printed = true; + + /* We append underscores to avoid name clashes with "g1" or "oo_" (see + also VariableNode::writeOutput) */ + output << "{\"variable\": \"" << symbol_table.getName(id) << "__\"" + << ", \"value\": \""; + value->writeJsonOutput(output, tt, tef_terms); + output << "\"}" << endl; + } output << "]"; } @@ -1660,11 +1666,11 @@ ModelTree::writeLatexModelFile(const string &basename, ExprNodeOutputType output << "\\footnotesize" << endl; // Write model local variables - for (map::const_iterator it = local_variables_table.begin(); - it != local_variables_table.end(); it++) + for (vector::const_iterator it = local_variables_vector.begin(); + it != local_variables_vector.end(); it++) { - int id = it->first; - expr_t value = it->second; + int id = *it; + expr_t value = local_variables_table.find(id)->second; content_output << "\\begin{dmath*}" << endl << symbol_table.getTeXName(id) << " = "; diff --git a/preprocessor/ParsingDriver.cc b/preprocessor/ParsingDriver.cc index b606365dc..f2615caee 100644 --- a/preprocessor/ParsingDriver.cc +++ b/preprocessor/ParsingDriver.cc @@ -2226,6 +2226,15 @@ ParsingDriver::add_model_equal_with_zero_rhs(expr_t arg) return add_model_equal(arg, model_tree->Zero); } +void +ParsingDriver::declare_model_local_variable(string *name, string *tex_name) +{ + declare_symbol(name, eModelLocalVariable, tex_name, NULL); + delete name; + if (tex_name != NULL) + delete tex_name; +} + void ParsingDriver::declare_and_init_model_local_variable(string *name, expr_t rhs) { diff --git a/preprocessor/ParsingDriver.hh b/preprocessor/ParsingDriver.hh index f7bb115b3..74ee8ff66 100644 --- a/preprocessor/ParsingDriver.hh +++ b/preprocessor/ParsingDriver.hh @@ -303,6 +303,8 @@ public: void declare_exogenous_det(string *name, string *tex_name = NULL, vector *> *partition_value = NULL); //! Declares a parameter void declare_parameter(string *name, string *tex_name = NULL, vector *> *partition_value = NULL); + //! Declares a model local variable + void declare_model_local_variable(string *name, string *tex_name = NULL); //! Declares a statement local variable void declare_statement_local_variable(string *name); //! Completes a subsample statement From b09f6affa96c35f4973d9ac8d178476b4d0d30d8 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Mon, 28 Aug 2017 17:46:50 +0200 Subject: [PATCH 39/47] preprocessor: aesthetic fix --- preprocessor/ComputingTasks.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/preprocessor/ComputingTasks.cc b/preprocessor/ComputingTasks.cc index a9320ed15..51f48e2d4 100644 --- a/preprocessor/ComputingTasks.cc +++ b/preprocessor/ComputingTasks.cc @@ -4346,9 +4346,9 @@ CalibSmootherStatement::writeOutput(ostream &output, const string &basename, boo { options_list.writeOutput(output); symbol_list.writeOutput("var_list_", output); - output << "options_.smoother = 1;" << endl; - output << "options_.order = 1;" << endl; - output << "[oo_,M_,options_,bayestopt_]=evaluate_smoother('calibration',var_list_,M_,oo_,options_,bayestopt_,estim_params_);" << endl; + output << "options_.smoother = 1;" << endl + << "options_.order = 1;" << endl + << "[oo_, M_, options_, bayestopt_] = evaluate_smoother('calibration', var_list_, M_, oo_, options_, bayestopt_, estim_params_);" << endl; } void From a5e44e3e90b85f5ef3fb81f1d17c44858b5e08ef Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Mon, 28 Aug 2017 18:22:11 +0200 Subject: [PATCH 40/47] evaluate_smoother: fix typo --- matlab/evaluate_smoother.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/evaluate_smoother.m b/matlab/evaluate_smoother.m index 9ab94654b..c6d3d7113 100644 --- a/matlab/evaluate_smoother.m +++ b/matlab/evaluate_smoother.m @@ -2,7 +2,7 @@ function [oo_,M_,options_,bayestopt_,Smoothed_variables_declaration_order_deviat % Evaluate the smoother at parameters. % % INPUTS -% o parameters a string ('posterior mode','posterior mean','posterior median','prior mode','prior mean','mle_mode') or a vector of values for +% o parameters a string ('posterior mode','posterior mean','posterior median','prior mode','prior mean','mle_mode','calibration') or a vector of values for % the (estimated) parameters of the model. % o var_list subset of endogenous variables % o M_ [structure] Definition of the model From 09d44c89fdbd3366ac1ef2b7f916b46bf0d5e32c Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Mon, 28 Aug 2017 18:19:41 +0200 Subject: [PATCH 41/47] preprocessor: add parameter_set option to evaluate_smoother command. Closes #1477 --- doc/dynare.texi | 3 +++ preprocessor/ComputingTasks.cc | 5 ++++- preprocessor/DynareBison.yy | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/doc/dynare.texi b/doc/dynare.texi index 90d6e4ed4..63c0bc2e9 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -7622,6 +7622,9 @@ more details. @item prefilter = @var{INTEGER} @xref{prefilter}. +@item parameter_set = @code{calibration} | @code{prior_mode} | @code{prior_mean} | @code{posterior_mode} | @code{posterior_mean} | @code{posterior_median} | @code{mle_mode} +@xref{parameter_set}. + @item loglinear @xref{loglinear}. diff --git a/preprocessor/ComputingTasks.cc b/preprocessor/ComputingTasks.cc index 51f48e2d4..400630bbc 100644 --- a/preprocessor/ComputingTasks.cc +++ b/preprocessor/ComputingTasks.cc @@ -4345,10 +4345,13 @@ void CalibSmootherStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { options_list.writeOutput(output); + OptionsList::string_options_t::const_iterator it = options_list.string_options.find("parameter_set"); + if (it == options_list.string_options.end()) + output << "options_.parameter_set = 'calibration';" << endl; symbol_list.writeOutput("var_list_", output); output << "options_.smoother = 1;" << endl << "options_.order = 1;" << endl - << "[oo_, M_, options_, bayestopt_] = evaluate_smoother('calibration', var_list_, M_, oo_, options_, bayestopt_, estim_params_);" << endl; + << "[oo_, M_, options_, bayestopt_] = evaluate_smoother(options_.parameter_set, var_list_, M_, oo_, options_, bayestopt_, estim_params_);" << endl; } void diff --git a/preprocessor/DynareBison.yy b/preprocessor/DynareBison.yy index 52931d891..0c1e6f2b1 100644 --- a/preprocessor/DynareBison.yy +++ b/preprocessor/DynareBison.yy @@ -2700,6 +2700,7 @@ calib_smoother_option : o_filtered_vars | o_diffuse_kalman_tol | o_diffuse_filter | o_smoothed_state_uncertainty + | o_parameter_set ; extended_path : EXTENDED_PATH ';' From 9a3ea532742fbc91148735992bef6bb908a80fa2 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 29 Aug 2017 10:25:39 +0200 Subject: [PATCH 42/47] test suite: change test to test for existence of files in current directory only --- tests/dynare-command-options/ramst.mod | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/dynare-command-options/ramst.mod b/tests/dynare-command-options/ramst.mod index bdfd472a8..8e88da9bf 100644 --- a/tests/dynare-command-options/ramst.mod +++ b/tests/dynare-command-options/ramst.mod @@ -38,6 +38,6 @@ perfect_foresight_solver; rplot c; rplot k; -if ~exist('ramst.json') || exist('ramst.log') +if ~exist('./ramst.json', 'file') || exist('./ramst.log', 'file') error('dynare command did not honour the options provided in the mod file!') -end \ No newline at end of file +end From 6fcc26ce2b55f8caf876b776318d58fc9fed8bbf Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 29 Aug 2017 10:27:49 +0200 Subject: [PATCH 43/47] test suite: aesthetic fix: remove British English :) --- tests/dynare-command-options/ramst.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/dynare-command-options/ramst.mod b/tests/dynare-command-options/ramst.mod index 8e88da9bf..d15baca5a 100644 --- a/tests/dynare-command-options/ramst.mod +++ b/tests/dynare-command-options/ramst.mod @@ -39,5 +39,5 @@ rplot c; rplot k; if ~exist('./ramst.json', 'file') || exist('./ramst.log', 'file') - error('dynare command did not honour the options provided in the mod file!') + error('The dynare command did not honor the options provided in the mod file!') end From cfc7413e96b4d32cfebb39e45c94160d5927869e Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Tue, 29 Aug 2017 10:52:48 +0200 Subject: [PATCH 44/47] Add calib_smoother command with parameter_set option to integration Following #1477 --- tests/fs2000/fs2000.mod | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/fs2000/fs2000.mod b/tests/fs2000/fs2000.mod index 54a6d6bf6..38eeb1583 100644 --- a/tests/fs2000/fs2000.mod +++ b/tests/fs2000/fs2000.mod @@ -73,3 +73,4 @@ varobs gp_obs gy_obs; options_.solve_tolf = 1e-12; estimation(order=1,datafile=fsdat_simul,nobs=192,loglinear,mh_replic=2000,mh_nblocks=2,mh_jscale=0.8,moments_varendo,consider_only_observed); +calib_smoother(parameter_set=posterior_mean) y; \ No newline at end of file From bd81ebc55d01153dac009ed5578de3643bf4af31 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 29 Aug 2017 11:51:11 +0200 Subject: [PATCH 45/47] evaluate_steady_state: simplify check: the only time this variable is used both of these conditions hold --- matlab/evaluate_steady_state.m | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/matlab/evaluate_steady_state.m b/matlab/evaluate_steady_state.m index d51c08bc8..c288cff8b 100644 --- a/matlab/evaluate_steady_state.m +++ b/matlab/evaluate_steady_state.m @@ -46,11 +46,9 @@ steadystate_flag = options.steadystate_flag; params = M.params; exo_ss = [oo.exo_steady_state; oo.exo_det_steady_state]; -if length(M.aux_vars) > 0 +if length(M.aux_vars) > 0 && ~steadystate_flag h_set_auxiliary_variables = str2func([M.fname '_set_auxiliary_variables']); - if ~steadystate_flag - ys_init = h_set_auxiliary_variables(ys_init,exo_ss,M.params); - end + ys_init = h_set_auxiliary_variables(ys_init,exo_ss,M.params); end if options.ramsey_policy From 718ff3d61c5f94f097ee506ea4200daadcde78a1 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 29 Aug 2017 10:58:39 +0200 Subject: [PATCH 46/47] preprocessor: only create *set_auxiliary_variables.m file if there will be something in it. Closes #1384 --- matlab/PosteriorIRF.m | 4 +++- matlab/dyn_ramsey_static.m | 14 +++++++++----- matlab/evaluate_steady_state.m | 8 ++++++-- matlab/evaluate_steady_state_file.m | 20 +++++++++++++++----- matlab/posterior_sampler.m | 4 +++- matlab/prior_posterior_statistics.m | 4 +++- preprocessor/ModFile.cc | 3 ++- preprocessor/StaticModel.cc | 11 +++++++---- 8 files changed, 48 insertions(+), 20 deletions(-) diff --git a/matlab/PosteriorIRF.m b/matlab/PosteriorIRF.m index 157a5e3a1..de0f625d2 100644 --- a/matlab/PosteriorIRF.m +++ b/matlab/PosteriorIRF.m @@ -235,7 +235,9 @@ else % which files have to be copied to run remotely NamFileInput(1,:) = {'',[M_.fname '_static.m']}; NamFileInput(2,:) = {'',[M_.fname '_dynamic.m']}; - NamFileInput(3,:) = {'',[M_.fname '_set_auxiliary_variables.m']}; + if M_.set_auxiliary_variables + NamFileInput(3,:) = {'',[M_.fname '_set_auxiliary_variables.m']}; + end if options_.steadystate_flag if options_.steadystate_flag == 1 NamFileInput(length(NamFileInput)+1,:)={'',[M_.fname '_steadystate.m']}; diff --git a/matlab/dyn_ramsey_static.m b/matlab/dyn_ramsey_static.m index 25b5301e6..ee97f265b 100644 --- a/matlab/dyn_ramsey_static.m +++ b/matlab/dyn_ramsey_static.m @@ -136,11 +136,15 @@ xx(1:M.orig_endo_nbr) = x(1:M.orig_endo_nbr); %set values of original endogenous % setting steady state of auxiliary variables that depends on original endogenous variables if any([M.aux_vars.type] ~= 6) %auxiliary variables other than multipliers needs_set_auxiliary_variables = 1; - fh = str2func([M.fname '_set_auxiliary_variables']); - s_a_v_func = @(z) fh(z,... - [oo.exo_steady_state,... - oo.exo_det_steady_state],... - params); + if M.set_auxiliary_variables + fh = str2func([M.fname '_set_auxiliary_variables']); + s_a_v_func = @(z) fh(z,... + [oo.exo_steady_state,... + oo.exo_det_steady_state],... + params); + else + s_a_v_func = z; + end xx = s_a_v_func(xx); else needs_set_auxiliary_variables = 0; diff --git a/matlab/evaluate_steady_state.m b/matlab/evaluate_steady_state.m index c288cff8b..02374f919 100644 --- a/matlab/evaluate_steady_state.m +++ b/matlab/evaluate_steady_state.m @@ -48,7 +48,9 @@ exo_ss = [oo.exo_steady_state; oo.exo_det_steady_state]; if length(M.aux_vars) > 0 && ~steadystate_flag h_set_auxiliary_variables = str2func([M.fname '_set_auxiliary_variables']); - ys_init = h_set_auxiliary_variables(ys_init,exo_ss,M.params); + if M.set_auxiliary_variables + ys_init = h_set_auxiliary_variables(ys_init,exo_ss,M.params); + end end if options.ramsey_policy @@ -288,7 +290,9 @@ if check info(1)= 20; %make sure ys contains auxiliary variables in case of problem with dynare_solve if length(M.aux_vars) > 0 && ~steadystate_flag - ys = h_set_auxiliary_variables(ys,exo_ss,M.params); + if M.set_auxiliary_variables + ys = h_set_auxiliary_variables(ys,exo_ss,M.params); + end end resid = evaluate_static_model(ys,exo_ss,params,M,options); info(2) = resid'*resid ; diff --git a/matlab/evaluate_steady_state_file.m b/matlab/evaluate_steady_state_file.m index 67a3b0c4d..50cc9ef69 100644 --- a/matlab/evaluate_steady_state_file.m +++ b/matlab/evaluate_steady_state_file.m @@ -74,14 +74,18 @@ h_set_auxiliary_variables = str2func([M.fname '_set_auxiliary_variables']); if isnan(updated_params_flag) || (updated_params_flag && any(isnan(params(~isnan(params))-params1(~isnan(params))))) %checks if new NaNs were added info(1) = 24; info(2) = NaN; - ys = h_set_auxiliary_variables(ys,exo_ss,params); + if M.set_auxiliary_variables + ys = h_set_auxiliary_variables(ys,exo_ss,params); + end return end if updated_params_flag && ~isreal(params1) info(1) = 23; info(2) = sum(imag(params).^2); - ys = h_set_auxiliary_variables(ys,exo_ss,params); + if M.set_auxiliary_variables + ys = h_set_auxiliary_variables(ys,exo_ss,params); + end return end @@ -94,16 +98,22 @@ if length(M.aux_vars) > 0 && ~options.ramsey_policy if debug ys0 = ys; end - ys = h_set_auxiliary_variables(ys,exo_ss,params); + if M.set_auxiliary_variables + ys = h_set_auxiliary_variables(ys,exo_ss,params); + end if debug ys1 = ys; end - ys = h_set_auxiliary_variables(ys,exo_ss,params); + if M.set_auxiliary_variables + ys = h_set_auxiliary_variables(ys,exo_ss,params); + end if debug ys2 = ys; end if debug - ys = h_set_auxiliary_variables(ys,exo_ss,params); + if M.set_auxiliary_variables + ys = h_set_auxiliary_variables(ys,exo_ss,params); + end ys3 = ys; idx = find(abs(ys0-ys1)>0); if ~isempty(idx) diff --git a/matlab/posterior_sampler.m b/matlab/posterior_sampler.m index 70f7b5de9..bfd209619 100644 --- a/matlab/posterior_sampler.m +++ b/matlab/posterior_sampler.m @@ -127,7 +127,9 @@ else % which files have to be copied to run remotely NamFileInput(1,:) = {'',[ModelName '_static.m']}; NamFileInput(2,:) = {'',[ModelName '_dynamic.m']}; - NamFileInput(3,:) = {'',[M_.fname '_set_auxiliary_variables.m']}; + if M.set_auxiliary_variables + NamFileInput(3,:) = {'',[M_.fname '_set_auxiliary_variables.m']}; + end if options_.steadystate_flag if options_.steadystate_flag == 1 NamFileInput(length(NamFileInput)+1,:)={'',[M_.fname '_steadystate.m']}; diff --git a/matlab/prior_posterior_statistics.m b/matlab/prior_posterior_statistics.m index 064e7874a..f08a18d85 100644 --- a/matlab/prior_posterior_statistics.m +++ b/matlab/prior_posterior_statistics.m @@ -294,7 +294,9 @@ else % which files have to be copied to run remotely NamFileInput(1,:) = {'',[M_.fname '_static.m']}; NamFileInput(2,:) = {'',[M_.fname '_dynamic.m']}; - NamFileInput(3,:) = {'',[M_.fname '_set_auxiliary_variables.m']}; + if M.set_auxiliary_variables + NamFileInput(3,:) = {'',[M_.fname '_set_auxiliary_variables.m']}; + end if options_.steadystate_flag if options_.steadystate_flag == 1 NamFileInput(length(NamFileInput)+1,:)={'',[M_.fname '_steadystate.m']}; diff --git a/preprocessor/ModFile.cc b/preprocessor/ModFile.cc index 71f5f33a0..39f9b5b17 100644 --- a/preprocessor/ModFile.cc +++ b/preprocessor/ModFile.cc @@ -813,7 +813,8 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo mOutputFile << "M_.orig_eq_nbr = " << mod_file_struct.orig_eq_nbr << ";" << endl << "M_.eq_nbr = " << dynamic_model.equation_number() << ";" << endl - << "M_.ramsey_eq_nbr = " << mod_file_struct.ramsey_eq_nbr << ";" << endl; + << "M_.ramsey_eq_nbr = " << mod_file_struct.ramsey_eq_nbr << ";" << endl + << "M_.set_auxiliary_variables = exist(['./' M_.fname '_set_auxiliary_variables.m'], 'file') == 2;" << endl; if (dynamic_model.equation_number() > 0) { diff --git a/preprocessor/StaticModel.cc b/preprocessor/StaticModel.cc index dc24f6ee6..97f4f38b5 100644 --- a/preprocessor/StaticModel.cc +++ b/preprocessor/StaticModel.cc @@ -2130,6 +2130,11 @@ StaticModel::writeAuxVarInitval(ostream &output, ExprNodeOutputType output_type) void StaticModel::writeSetAuxiliaryVariables(const string &basename, const bool julia) const { + ostringstream output_func_body; + writeAuxVarRecursiveDefinitions(output_func_body, oMatlabStaticModel); + + if (output_func_body.str().empty()) + return; string func_name = basename + "_set_auxiliary_variables"; string filename = julia ? func_name + ".jl" : func_name + ".m"; @@ -2148,10 +2153,8 @@ StaticModel::writeSetAuxiliaryVariables(const string &basename, const bool julia << comment << " Status : Computes static model for Dynare" << endl << comment << endl << comment << " Warning : this file is generated automatically by Dynare" << endl - << comment << " from model file (.mod)" << endl - << endl; - - writeAuxVarRecursiveDefinitions(output, oMatlabStaticModel); + << comment << " from model file (.mod)" << endl << endl + << output_func_body.str(); } void From 85d00ad267fb09641f7c78a7fa14c447b01dc184 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 29 Aug 2017 17:15:06 +0200 Subject: [PATCH 47/47] test suite: remove practicing directory. closes #1500 --- .../practicing/AssetPricingApproximation.mod | 47 ------- tests/practicing/AssetPricingEstimate.mod | 58 -------- tests/practicing/BansalYaronBayes.mod | 42 ------ tests/practicing/BansalYaronML.mod | 44 ------ tests/practicing/Fig1131.mod | 79 ----------- tests/practicing/Fig1131commented.mod | 130 ------------------ tests/practicing/Fig1132.mod | 79 ----------- tests/practicing/Fig1151.mod | 80 ----------- tests/practicing/Fig1152.mod | 80 ----------- tests/practicing/Fig1171.mod | 80 ----------- tests/practicing/Fig1172.mod | 80 ----------- tests/practicing/GrowthApproximate.mod | 41 ------ tests/practicing/GrowthEstimate.mod | 44 ------ tests/practicing/HSTBayes.mod | 62 --------- tests/practicing/HSTML.mod | 62 --------- tests/practicing/TwocountryApprox.mod | 45 ------ tests/practicing/TwocountryEst.mod | 51 ------- tests/practicing/cagan_data.mat | Bin 801 -> 0 bytes tests/practicing/dataHST.mat | Bin 7771 -> 0 bytes tests/practicing/data_consRicardoypg.mat | Bin 1959 -> 0 bytes tests/practicing/datasaver.m | 58 -------- tests/practicing/hall1.mod | 46 ------- tests/practicing/hall1estimateBayes.mod | 54 -------- tests/practicing/hall1estimateML.mod | 56 -------- tests/practicing/rosen.mod | 55 -------- tests/practicing/rosenestimateBayes.mod | 63 --------- tests/practicing/rosenestimateML.mod | 65 --------- tests/practicing/sargent77.mod | 41 ------ tests/practicing/sargent77Bayes.mod | 48 ------- tests/practicing/sargent77ML.mod | 52 ------- 30 files changed, 1642 deletions(-) delete mode 100644 tests/practicing/AssetPricingApproximation.mod delete mode 100644 tests/practicing/AssetPricingEstimate.mod delete mode 100644 tests/practicing/BansalYaronBayes.mod delete mode 100644 tests/practicing/BansalYaronML.mod delete mode 100644 tests/practicing/Fig1131.mod delete mode 100644 tests/practicing/Fig1131commented.mod delete mode 100644 tests/practicing/Fig1132.mod delete mode 100644 tests/practicing/Fig1151.mod delete mode 100644 tests/practicing/Fig1152.mod delete mode 100644 tests/practicing/Fig1171.mod delete mode 100644 tests/practicing/Fig1172.mod delete mode 100644 tests/practicing/GrowthApproximate.mod delete mode 100644 tests/practicing/GrowthEstimate.mod delete mode 100644 tests/practicing/HSTBayes.mod delete mode 100644 tests/practicing/HSTML.mod delete mode 100644 tests/practicing/TwocountryApprox.mod delete mode 100644 tests/practicing/TwocountryEst.mod delete mode 100644 tests/practicing/cagan_data.mat delete mode 100644 tests/practicing/dataHST.mat delete mode 100644 tests/practicing/data_consRicardoypg.mat delete mode 100644 tests/practicing/datasaver.m delete mode 100644 tests/practicing/hall1.mod delete mode 100644 tests/practicing/hall1estimateBayes.mod delete mode 100644 tests/practicing/hall1estimateML.mod delete mode 100644 tests/practicing/rosen.mod delete mode 100644 tests/practicing/rosenestimateBayes.mod delete mode 100644 tests/practicing/rosenestimateML.mod delete mode 100644 tests/practicing/sargent77.mod delete mode 100644 tests/practicing/sargent77Bayes.mod delete mode 100644 tests/practicing/sargent77ML.mod diff --git a/tests/practicing/AssetPricingApproximation.mod b/tests/practicing/AssetPricingApproximation.mod deleted file mode 100644 index 57679f38c..000000000 --- a/tests/practicing/AssetPricingApproximation.mod +++ /dev/null @@ -1,47 +0,0 @@ -periods 500; -var dc, dd, v_c, v_d, x; -varexo e_c, e_x, e_d; - -parameters DELTA THETA PSI MU_C MU_D RHO_X LAMBDA_DX; - -DELTA=.99; -PSI=1.5; -THETA=(1-7.5)/(1-1/PSI); -MU_C=0.0015; -MU_D=0.0015; -RHO_X=.979; -LAMBDA_DX=3; - -model; -v_c = DELTA^THETA * exp((-THETA/PSI)*dc(+1) + (THETA-1)*log((1+v_c(+1))*exp(dc(+1))/v_c) ) * (1+v_c(+1))*exp(dc(+1)); -v_d = DELTA^THETA * exp((-THETA/PSI)*dc(+1) + (THETA-1)*log((1+v_c(+1))*exp(dc(+1))/v_c) ) * (1+v_d(+1))*exp(dd(+1)); -dc = MU_C + x(-1) + e_c; -dd = MU_D + LAMBDA_DX*x(-1) + e_d; -x = RHO_X * x(-1) + e_x; -end; - -initval; -v_c=15; -v_d=15; -dc=MU_C; -dd=MU_D; -x=0; -e_c=0; -e_x=0; -e_d=0; -end; - -shocks; -var e_c; -stderr .0078; -var e_x; -stderr .0078*.044; -var e_d; -stderr .0078*4.5; -end; - -steady(solve_algo=0); -check; - -stoch_simul(dr_algo=1, order=1, periods=1000, irf=30); -datasaver('simudata',[]); \ No newline at end of file diff --git a/tests/practicing/AssetPricingEstimate.mod b/tests/practicing/AssetPricingEstimate.mod deleted file mode 100644 index 482b54457..000000000 --- a/tests/practicing/AssetPricingEstimate.mod +++ /dev/null @@ -1,58 +0,0 @@ -var dc, dd, v_c, v_d, x; -varexo e_c, e_x, e_d; - -parameters DELTA THETA PSI MU_C MU_D RHO_X LAMBDA_DX; - -DELTA=.99; -PSI=1.5; -THETA=(1-7.5)/(1-1/PSI); -MU_C=0.0015; -MU_D=0.0015; -RHO_X=.979; -LAMBDA_DX=3; - - -model; -v_c = DELTA^THETA * exp((-THETA/PSI)*dc(+1) + (THETA-1)*log((1+v_c(+1))*exp(dc(+1))/v_c) ) * (1+v_c(+1))*exp(dc(+1)); -v_d = DELTA^THETA * exp((-THETA/PSI)*dc(+1) + (THETA-1)*log((1+v_c(+1))*exp(dc(+1))/v_c) ) * (1+v_d(+1))*exp(dd(+1)); -dc = MU_C + x(-1) + e_c; -dd = MU_D + LAMBDA_DX*x(-1) + e_d; -x = RHO_X * x(-1) + e_x; -end; - -initval; -v_c=15; -v_d=15; -dc=MU_C; -dd=MU_D; -x=0; -e_c=0; -e_x=0; -e_d=0; -end; - -shocks; -var e_d; stderr .001; -var e_c; stderr .001; -var e_x; stderr .001; -end; - -steady; - -estimated_params; -DELTA, beta_pdf, 0.98,.005; -THETA,normal_pdf,-19.5, 0.0025; -PSI,normal_pdf,1.6, 0.1; -MU_C,normal_pdf,0.001, 0.001; -MU_D,normal_pdf,0.001, 0.001; -RHO_X,normal_pdf,.98, 0.005; -LAMBDA_DX,normal_pdf,3, 0.05; -stderr e_d,inv_gamma_pdf,.0025, 30; -stderr e_x,inv_gamma_pdf,.0003, 30; -stderr e_c,inv_gamma_pdf,.01, 30; -end; - - -varobs v_d dd dc; - -estimation(datafile=simudata,mh_replic=1000,mh_jscale=.4,nodiagnostic); \ No newline at end of file diff --git a/tests/practicing/BansalYaronBayes.mod b/tests/practicing/BansalYaronBayes.mod deleted file mode 100644 index 4d8530610..000000000 --- a/tests/practicing/BansalYaronBayes.mod +++ /dev/null @@ -1,42 +0,0 @@ -var x y; -varexo e_x e_u; - -parameters rho sig_x sig_u mu_y; - -rho = .98; -mu_y=.015; -sig_x=0.00025; -sig_u=.0078; - -model(linear); -x=rho*x(-1) + sig_x*e_x; -y=mu_y + x(-1) + sig_u*e_u; -end; - -initval; -x=0; -y=mu_y; -end; - -steady; - -shocks; -var e_x; -stderr 1; -var e_u; -stderr 1; -end; - -estimated_params; - -rho, beta_pdf, .98, .01; -mu_y, uniform_pdf, .005, .0025; -sig_u, inv_gamma_pdf, .003, inf; -sig_x, inv_gamma_pdf, .003, inf; -// The syntax for to input the priors is the following: -// variable name, prior distribution, parameters of distribution. - -end; - -varobs y; -estimation(datafile=data_consRicardoypg,first_obs=1,nobs=227,mh_replic=5000,mh_nblocks=1,mh_jscale=1); \ No newline at end of file diff --git a/tests/practicing/BansalYaronML.mod b/tests/practicing/BansalYaronML.mod deleted file mode 100644 index 331e6b9be..000000000 --- a/tests/practicing/BansalYaronML.mod +++ /dev/null @@ -1,44 +0,0 @@ - -var x y; -varexo e_x e_u; - -parameters rho sig_x sig_u mu_y; - -rho = .98; -mu_y=.015; -sig_x=0.00025; -sig_u=.0078; - -model(linear); -x=rho*x(-1) + sig_x*e_x; -y=mu_y + x(-1) + sig_u*e_u; -end; - -initval; -x=0; -y=mu_y; -end; - -steady; - -shocks; -var e_x; -stderr 1; -var e_u; -stderr 1; -end; - -estimated_params; -// ML estimation setup -// parameter name, initial value, boundaries_low, ..._up; - rho, 0, -0.99, 0.999; // use this for unconstrained max likelihood -// rho, .98, .975, .999 ; // use this for long run risk model -// sig_x, .0004,.0001,.05 ; // use this for the long run risk model - sig_x, .0005, .00000000001, .01; // use this for unconstrained max likelihood -sig_u, .007,.001, .1; -mu_y, .014, .0001, .04; - -end; - -varobs y; -estimation(datafile=data_consRicardoypg,first_obs=1,nobs=227,mh_replic=0,mode_compute=4,mode_check); \ No newline at end of file diff --git a/tests/practicing/Fig1131.mod b/tests/practicing/Fig1131.mod deleted file mode 100644 index 41bf69a33..000000000 --- a/tests/practicing/Fig1131.mod +++ /dev/null @@ -1,79 +0,0 @@ -// This program replicates figure 11.3.1 from chapter 11 of RMT2 by Ljungqvist and Sargent - -var c k; -varexo taui tauc tauk g; -parameters bet gam del alpha A; -bet=.95; -gam=2; -del=.2; -alpha=.33; -A=1; - -model; -k=A*k(-1)^alpha+(1-del)*k(-1)-c-g; -c^(-gam)= bet*(c(+1)^(-gam))*((1+tauc(-1))/(1+tauc))*((1-taui)*(1-del)/(1-taui(-1))+ - ((1-tauk)/(1-taui(-1)))*alpha*A*k(-1)^(alpha-1)); -end; - -initval; -k=1.5; -c=0.6; -g = 0.2; -tauc = 0; -taui = 0; -tauk = 0; -end; -steady; - -endval; -k=1.5; -c=0.4; -g =.4; -tauc =0; -taui =0; -tauk =0; -end; -steady; - -shocks; -var g; -periods 1:9; -values 0.2; -end; - -simul(periods=100); - -co=ys0_(var_index('c')); -ko = ys0_(var_index('k')); -go = ex_(1,1); - -rbig0=1/bet; -rbig=y_(var_index('c'),2:101).^(-gam)./(bet*y_(var_index('c'),3:102).^(-gam)); -rq0=alpha*A*ko^(alpha-1); -rq=alpha*A*y_(var_index('k'),1:100).^(alpha-1); -wq0=A*ko^alpha-ko*alpha*A*ko^(alpha-1); -wq=A*y_(var_index('k'),1:100).^alpha-y_(var_index('k'),1:100).*alpha*A.*y_(var_index('k'),1:100).^(alpha-1); -sq0=(1-ex_(1,4))*A*alpha*ko^(alpha-1)+(1-del); -sq=(1-ex_(1:100,4)')*A*alpha.*y_(var_index('k'),1:100).^(alpha-1)+(1-del); - -figure -subplot(2,3,1) -plot([ko*ones(100,1) y_(var_index('k'),1:100)' ]) -title('k') -subplot(2,3,2) -plot([co*ones(100,1) y_(var_index('c'),2:101)' ]) -title('c') -subplot(2,3,3) -plot([rbig0*ones(100,1) rbig' ]) -title('R') -subplot(2,3,4) -plot([wq0*ones(100,1) wq' ]) -title('w/q') -subplot(2,3,5) -plot([sq0*ones(100,1) sq' ]) -title('s/q') -subplot(2,3,6) -plot([rq0*ones(100,1) rq' ]) -title('r/q') - -print -depsc fig1131.ps diff --git a/tests/practicing/Fig1131commented.mod b/tests/practicing/Fig1131commented.mod deleted file mode 100644 index 57311cd6e..000000000 --- a/tests/practicing/Fig1131commented.mod +++ /dev/null @@ -1,130 +0,0 @@ -// This program replicates figure 11.3.1 from chapter 11 of RMT2 by Ljungqvist and Sargent -// This is a commented version of the program given in the handout. - -// Note: y_ records the simulated endogenous variables in alphabetical order -// ys0_ records the initial steady state -// ys_ records the terminal steady state -// We check that these line up at the end points -// Note: y_ has ys0_ in first column, ys_ in last column, explaining why it is 102 long; -// The sample of size 100 is in between. - -// Warning: we align c, k, and the taxes to exploit the dynare syntax. See comments below. -// So k in the program corresponds to k_{t+1} and the same timing holds for the taxes. - -//Declares the endogenous variables; -var c k; -//declares the exogenous variables // investment tax credit, consumption tax, capital tax, government spending -varexo taui tauc tauk g; - -parameters bet gam del alpha A; - -bet=.95; // discount factor -gam=2; // CRRA parameter -del=.2; // depreciation rate -alpha=.33; // capital's share -A=1; // productivity - -// Alignment convention: -// g tauc taui tauk are now columns of ex_. Because of a bad design decision -// the date of ex_(1,:) doesn't necessarily match the date in y_. Whether they match depends -// on the number of lag periods in endogenous versus exogenous variables. -// In this example they match because tauc(-1) and taui(-1) enter the model. - -// These decisions and the timing conventions mean that -// y_(:,1) records the initial steady state, while y_(:,102) records the terminal steady state values. -// For j > 2, y_(:,j) records [c(j-1) .. k(j-1) .. G(j-1)] where k(j-1) means -// end of period capital in period j-1, which equals k(j) in chapter 11 notation. -// Note that the jump in G occurs in y_(;,11), which confirms this timing. -// the jump occurs now in ex_(11,1) - -model; -// equation 11.3.8.a -k=A*k(-1)^alpha+(1-del)*k(-1)-c-g; -// equation 11.3.8e + 11.3.8.g -c^(-gam)= bet*(c(+1)^(-gam))*((1+tauc(-1))/(1+tauc))*((1-taui)*(1-del)/(1-taui(-1))+ - ((1-tauk)/(1-taui(-1)))*alpha*A*k(-1)^(alpha-1)); -end; - -initval; -k=1.5; -c=0.6; -g = 0.2; -tauc = 0; -taui = 0; -tauk = 0; -end; -steady; // put this in if you want to start from the initial steady state, comment it out to start from the indicated values - -endval; // The following values determine the new steady state after the shocks. -k=1.5; -c=0.4; -g =.4; -tauc =0; -taui =0; -tauk =0; -end; - -steady; // We use steady again and the enval provided are initial guesses for dynare to compute the ss. - -// The following lines produce a g sequence with a once and for all jump in g -shocks; -// we use shocks to undo that for the first 9 periods and leave g at -// it's initial value of 0 - -var g; -periods 1:9; -values 0.2; -end; - - -// now solve the model -simul(periods=100); - -// Note: y_ records the simulated endogenous variables in alphabetical order -// ys0_ records the initial steady state -// ys_ records the terminal steady state -// check that these line up at the end points -y_(:,1) -ys0_(:) -y_(:,102) - ys_(:) - -// Compute the initial steady state for consumption to later do the plots. -co=ys0_(var_index('c')); -ko = ys0_(var_index('k')); -// g is in ex_(:,1) since it is stored in alphabetical order -go = ex_(1,1) - -// The following equation compute the other endogenous variables use in the plots below -// Since they are function of capital and consumption, so we can compute them from the solved -// model above. - -// These equations were taken from page 333 of RMT2 -rbig0=1/bet; -rbig=y_(var_index('c'),2:101).^(-gam)./(bet*y_(var_index('c'),3:102).^(-gam)); -rq0=alpha*A*ko^(alpha-1); -rq=alpha*A*y_(var_index('k'),1:100).^(alpha-1); -wq0=A*ko^alpha-ko*alpha*A*ko^(alpha-1); -wq=A*y_(var_index('k'),1:100).^alpha-y_(var_index('k'),1:100).*alpha*A.*y_(var_index('k'),1:100).^(alpha-1); -sq0=(1-ex_(1,4))*A*alpha*ko^(alpha-1)+(1-del); -sq=(1-ex_(1:100,4)')*A*alpha.*y_(var_index('k'),1:100).^(alpha-1)+(1-del); - -//Now we plot the responses of the endogenous variables to the shock. - -figure -subplot(2,3,1) -plot([ko*ones(100,1) y_(var_index('k'),1:100)' ]) // note the timing: we lag capital to correct for syntax -title('k') -subplot(2,3,2) -plot([co*ones(100,1) y_(var_index('c'),2:101)' ]) -title('c') -subplot(2,3,3) -plot([rbig0*ones(100,1) rbig' ]) -title('R') -subplot(2,3,4) -plot([wq0*ones(100,1) wq' ]) -title('w/q') -subplot(2,3,5) -plot([sq0*ones(100,1) sq' ]) -title('s/q') -subplot(2,3,6) -plot([rq0*ones(100,1) rq' ]) -title('r/q') diff --git a/tests/practicing/Fig1132.mod b/tests/practicing/Fig1132.mod deleted file mode 100644 index 646602f26..000000000 --- a/tests/practicing/Fig1132.mod +++ /dev/null @@ -1,79 +0,0 @@ -// This program replicates figure 11.3.1 from chapter 11 of RMT2 by Ljungqvist and Sargent - -var c k; -varexo taui tauc tauk g; -parameters bet gam del alpha A; -bet=.95; -gam=2; -del=.2; -alpha=.33; -A=1; - -model; -k=A*k(-1)^alpha+(1-del)*k(-1)-c-g; -c^(-gam)= bet*(c(+1)^(-gam))*((1+tauc(-1))/(1+tauc))*((1-taui)*(1-del)/(1-taui(-1))+ - ((1-tauk)/(1-taui(-1)))*alpha*A*k(-1)^(alpha-1)); -end; - -initval; -k=1.5; -c=0.6; -g = 0.2; -tauc = 0; -taui = 0; -tauk = 0; -end; -steady; - -endval; -k=1.5; -c=0.6; -g = 0.2; -tauc =0.2; -taui =0; -tauk =0; -end; -steady; - -shocks; -var tauc; -periods 1:9; -values 0; -end; - -simul(periods=100); - -co=ys0_(var_index('c')); -ko = ys0_(var_index('k')); -go = ex_(1,1); - -rbig0=1/bet; -rbig=y_(var_index('c'),2:101).^(-gam)./(bet*y_(var_index('c'),3:102).^(-gam)); -rq0=alpha*A*ko^(alpha-1); -rq=alpha*A*y_(var_index('k'),1:100).^(alpha-1); -wq0=A*ko^alpha-ko*alpha*A*ko^(alpha-1); -wq=A*y_(var_index('k'),1:100).^alpha-y_(var_index('k'),1:100).*alpha*A.*y_(var_index('k'),1:100).^(alpha-1); -sq0=(1-ex_(1,4))*A*alpha*ko^(alpha-1)+(1-del); -sq=(1-ex_(1:100,4)')*A*alpha.*y_(var_index('k'),1:100).^(alpha-1)+(1-del); - -figure -subplot(2,3,1) -plot([ko*ones(100,1) y_(var_index('k'),1:100)' ]) -title('k') -subplot(2,3,2) -plot([co*ones(100,1) y_(var_index('c'),2:101)' ]) -title('c') -subplot(2,3,3) -plot([rbig0*ones(100,1) rbig' ]) -title('R') -subplot(2,3,4) -plot([wq0*ones(100,1) wq' ]) -title('w/q') -subplot(2,3,5) -plot([sq0*ones(100,1) sq' ]) -title('s/q') -subplot(2,3,6) -plot([rq0*ones(100,1) rq' ]) -title('r/q') - -print -depsc fig1132.ps diff --git a/tests/practicing/Fig1151.mod b/tests/practicing/Fig1151.mod deleted file mode 100644 index 0922b1e46..000000000 --- a/tests/practicing/Fig1151.mod +++ /dev/null @@ -1,80 +0,0 @@ -// This program replicates figure 11.3.1 from chapter 11 of RMT2 by Ljungqvist and Sargent - -var c k; -varexo taui tauc tauk g; -parameters bet gam del alpha A; -bet=.95; -gam=2; -del=.2; -alpha=.33; -A=1; - -model; -k=A*k(-1)^alpha+(1-del)*k(-1)-c-g; -c^(-gam)= bet*(c(+1)^(-gam))*((1+tauc(-1))/(1+tauc))*((1-taui)*(1-del)/(1-taui(-1))+ - ((1-tauk)/(1-taui(-1)))*alpha*A*k(-1)^(alpha-1)); -end; - -initval; -k=1.5; -c=0.6; -g = 0.2; -tauc = 0; -taui = 0; -tauk = 0; -end; -steady; - -endval; -k=1.5; -c=0.6; -g =0.2; -tauc =0; -taui =0.20; -tauk =0; -end; -steady; - -shocks; -var taui; -periods 1:9; -values 0; -end; - -simul(periods=100); - -co=ys0_(var_index('c')); -ko = ys0_(var_index('k')); -go = ex_(1,1); - -rbig0=1/bet; -rbig=y_(var_index('c'),2:101).^(-gam)./(bet*y_(var_index('c'),3:102).^(-gam)); -rq0=alpha*A*ko^(alpha-1); -rq=alpha*A*y_(var_index('k'),1:100).^(alpha-1); -wq0=A*ko^alpha-ko*alpha*A*ko^(alpha-1); -wq=A*y_(var_index('k'),1:100).^alpha-y_(var_index('k'),1:100).*alpha*A.*y_(var_index('k'),1:100).^(alpha-1); -sq0=(1-ex_(1,4))*A*alpha*ko^(alpha-1)+(1-del); -sq=(1-ex_(1:100,4)')*A*alpha.*y_(var_index('k'),1:100).^(alpha-1)+(1-del); - -figure -subplot(2,3,1) -plot([ko*ones(100,1) y_(var_index('k'),1:100)' ]) -title('k') -subplot(2,3,2) -plot([co*ones(100,1) y_(var_index('c'),2:101)' ]) -title('c') -subplot(2,3,3) -plot([rbig0*ones(100,1) rbig' ]) -title('R') -subplot(2,3,4) -plot([wq0*ones(100,1) wq' ]) -title('w/q') -subplot(2,3,5) -plot([sq0*ones(100,1) sq' ]) -title('s/q') -subplot(2,3,6) -plot([rq0*ones(100,1) rq' ]) -title('r/q') - -print -depsc fig1151.ps - diff --git a/tests/practicing/Fig1152.mod b/tests/practicing/Fig1152.mod deleted file mode 100644 index 0296a090a..000000000 --- a/tests/practicing/Fig1152.mod +++ /dev/null @@ -1,80 +0,0 @@ -// This program replicates figure 11.3.1 from chapter 11 of RMT2 by Ljungqvist and Sargent - -var c k; -varexo taui tauc tauk g; -parameters bet gam del alpha A; -bet=.95; -gam=2; -del=.2; -alpha=.33; -A=1; - -model; -k=A*k(-1)^alpha+(1-del)*k(-1)-c-g; -c^(-gam)= bet*(c(+1)^(-gam))*((1+tauc(-1))/(1+tauc))*((1-taui)*(1-del)/(1-taui(-1))+ - ((1-tauk)/(1-taui(-1)))*alpha*A*k(-1)^(alpha-1)); -end; - -initval; -k=1.5; -c=0.6; -g = 0.2; -tauc = 0; -taui = 0; -tauk = 0; -end; -steady; - -endval; -k=1.5; -c=0.6; -g =0.2; -tauc =0; -taui =0; -tauk = 0.2; -end; -steady; - -shocks; -var tauk; -periods 1:9; -values 0; -end; - -simul(periods=100); - -co=ys0_(var_index('c')); -ko = ys0_(var_index('k')); -go = ex_(1,1); - -rbig0=1/bet; -rbig=y_(var_index('c'),2:101).^(-gam)./(bet*y_(var_index('c'),3:102).^(-gam)); -rq0=alpha*A*ko^(alpha-1); -rq=alpha*A*y_(var_index('k'),1:100).^(alpha-1); -wq0=A*ko^alpha-ko*alpha*A*ko^(alpha-1); -wq=A*y_(var_index('k'),1:100).^alpha-y_(var_index('k'),1:100).*alpha*A.*y_(var_index('k'),1:100).^(alpha-1); -sq0=(1-ex_(1,4))*A*alpha*ko^(alpha-1)+(1-del); -sq=(1-ex_(1:100,4)')*A*alpha.*y_(var_index('k'),1:100).^(alpha-1)+(1-del); - -figure -subplot(2,3,1) -plot([ko*ones(100,1) y_(var_index('k'),1:100)' ]) -title('k') -subplot(2,3,2) -plot([co*ones(100,1) y_(var_index('c'),2:101)' ]) -title('c') -subplot(2,3,3) -plot([rbig0*ones(100,1) rbig' ]) -title('R') -subplot(2,3,4) -plot([wq0*ones(100,1) wq' ]) -title('w/q') -subplot(2,3,5) -plot([sq0*ones(100,1) sq' ]) -title('s/q') -subplot(2,3,6) -plot([rq0*ones(100,1) rq' ]) -title('r/q') - -print -depsc fig1152.ps - diff --git a/tests/practicing/Fig1171.mod b/tests/practicing/Fig1171.mod deleted file mode 100644 index 3870a8587..000000000 --- a/tests/practicing/Fig1171.mod +++ /dev/null @@ -1,80 +0,0 @@ -// This program replicates figure 11.3.1 from chapter 11 of RMT2 by Ljungqvist and Sargent - -var c k; -varexo taui tauc tauk g; -parameters bet gam del alpha A; -bet=.95; -gam=2; -del=.2; -alpha=.33; -A=1; - -model; -k=A*k(-1)^alpha+(1-del)*k(-1)-c-g; -c^(-gam)= bet*(c(+1)^(-gam))*((1+tauc(-1))/(1+tauc))*((1-taui)*(1-del)/(1-taui(-1))+ - ((1-tauk)/(1-taui(-1)))*alpha*A*k(-1)^(alpha-1)); -end; - -initval; -k=1.5; -c=0.6; -g = 0.2; -tauc = 0; -taui = 0; -tauk = 0; -end; -steady; - -endval; -k=1.5; -c=0.6; -g = 0.2; -tauc =0; -taui =0; -tauk =0; -end; -steady; - -shocks; -var g; -periods 10; -values 0.4; -end; - -simul(periods=100); - -co=ys0_(var_index('c')); -ko = ys0_(var_index('k')); -go = ex_(1,1); - -rbig0=1/bet; -rbig=y_(var_index('c'),2:101).^(-gam)./(bet*y_(var_index('c'),3:102).^(-gam)); -rq0=alpha*A*ko^(alpha-1); -rq=alpha*A*y_(var_index('k'),1:100).^(alpha-1); -wq0=A*ko^alpha-ko*alpha*A*ko^(alpha-1); -wq=A*y_(var_index('k'),1:100).^alpha-y_(var_index('k'),1:100).*alpha*A.*y_(var_index('k'),1:100).^(alpha-1); -sq0=(1-ex_(1,4))*A*alpha*ko^(alpha-1)+(1-del); -sq=(1-ex_(1:100,4)')*A*alpha.*y_(var_index('k'),1:100).^(alpha-1)+(1-del); - -figure -subplot(2,3,1) -plot([ko*ones(100,1) y_(var_index('k'),1:100)' ]) -title('k') -subplot(2,3,2) -plot([co*ones(100,1) y_(var_index('c'),2:101)' ]) -title('c') -subplot(2,3,3) -plot([rbig0*ones(100,1) rbig' ]) -title('R') -subplot(2,3,4) -plot([wq0*ones(100,1) wq' ]) -title('w/q') -subplot(2,3,5) -plot([sq0*ones(100,1) sq' ]) -title('s/q') -subplot(2,3,6) -plot([rq0*ones(100,1) rq' ]) -title('r/q') - -print -depsc fig1171.ps - diff --git a/tests/practicing/Fig1172.mod b/tests/practicing/Fig1172.mod deleted file mode 100644 index e1c74ee5c..000000000 --- a/tests/practicing/Fig1172.mod +++ /dev/null @@ -1,80 +0,0 @@ -// This program replicates figure 11.3.1 from chapter 11 of RMT2 by Ljungqvist and Sargent - -var c k; -varexo taui tauc tauk g; -parameters bet gam del alpha A; -bet=.95; -gam=2; -del=.2; -alpha=.33; -A=1; - -model; -k=A*k(-1)^alpha+(1-del)*k(-1)-c-g; -c^(-gam)= bet*(c(+1)^(-gam))*((1+tauc(-1))/(1+tauc))*((1-taui)*(1-del)/(1-taui(-1))+ - ((1-tauk)/(1-taui(-1)))*alpha*A*k(-1)^(alpha-1)); -end; - -initval; -k=1.5; -c=0.6; -g = 0.2; -tauc = 0; -taui = 0; -tauk = 0; -end; -steady; - -endval; -k=1.5; -c=0.6; -g =0.2; -tauc =0; -taui =0; -tauk =0; -end; -steady; - -shocks; -var taui; -periods 10; -values 0.2; -end; - -simul(periods=100); - -co=ys0_(var_index('c')); -ko = ys0_(var_index('k')); -go = ex_(1,1); - -rbig0=1/bet; -rbig=y_(var_index('c'),2:101).^(-gam)./(bet*y_(var_index('c'),3:102).^(-gam)); -rq0=alpha*A*ko^(alpha-1); -rq=alpha*A*y_(var_index('k'),1:100).^(alpha-1); -wq0=A*ko^alpha-ko*alpha*A*ko^(alpha-1); -wq=A*y_(var_index('k'),1:100).^alpha-y_(var_index('k'),1:100).*alpha*A.*y_(var_index('k'),1:100).^(alpha-1); -sq0=(1-ex_(1,4))*A*alpha*ko^(alpha-1)+(1-del); -sq=(1-ex_(1:100,4)')*A*alpha.*y_(var_index('k'),1:100).^(alpha-1)+(1-del); - -figure -subplot(2,3,1) -plot([ko*ones(100,1) y_(var_index('k'),1:100)' ]) -title('k') -subplot(2,3,2) -plot([co*ones(100,1) y_(var_index('c'),2:101)' ]) -title('c') -subplot(2,3,3) -plot([rbig0*ones(100,1) rbig' ]) -title('R') -subplot(2,3,4) -plot([wq0*ones(100,1) wq' ]) -title('w/q') -subplot(2,3,5) -plot([sq0*ones(100,1) sq' ]) -title('s/q') -subplot(2,3,6) -plot([rq0*ones(100,1) rq' ]) -title('r/q') - -print -depsc fig1172.ps - diff --git a/tests/practicing/GrowthApproximate.mod b/tests/practicing/GrowthApproximate.mod deleted file mode 100644 index 03b936a59..000000000 --- a/tests/practicing/GrowthApproximate.mod +++ /dev/null @@ -1,41 +0,0 @@ - - -periods 1000; - -var c k lab z; -varexo e; - -parameters bet the del alp tau rho s; - -bet = 0.987; -the = 0.357; -del = 0.012; -alp = 0.4; -tau = 2; -rho = 0.95; -s = 0.007; - -model; - (c^the*(1-lab)^(1-the))^(1-tau)/c=bet*((c(+1)^the*(1-lab(+1))^(1-the))^(1-tau)/c(+1))*(1+alp*exp(z(+1))*k^(alp-1)*lab(+1)^(1-alp)-del); - c=the/(1-the)*(1-alp)*exp(z)*k(-1)^alp*lab^(-alp)*(1-lab); - k=exp(z)*k(-1)^alp*lab^(1-alp)-c+(1-del)*k(-1); - z=rho*z(-1)+s*e; -end; - -initval; -k = 1; -c = 1; -lab = 0.3; -z = 0; -e = 0; -end; - -shocks; -var e; -stderr 1; -end; - -steady; - -stoch_simul(dr_algo=0,periods=1000,irf=40); -datasaver('simudata',[]); diff --git a/tests/practicing/GrowthEstimate.mod b/tests/practicing/GrowthEstimate.mod deleted file mode 100644 index 8c33ea92f..000000000 --- a/tests/practicing/GrowthEstimate.mod +++ /dev/null @@ -1,44 +0,0 @@ - -var c k lab z; -varexo e; - -parameters bet del alp rho the tau s; - -bet = 0.987; -the = 0.357; -del = 0.012; -alp = 0.4; -tau = 2; -rho = 0.95; -s = 0.007; - -model; - (c^the*(1-lab)^(1-the))^(1-tau)/c=bet*((c(+1)^the*(1-lab(+1))^(1-the))^(1-tau)/c(+1))*(1+alp*exp(z(+1))*k^(alp-1)*lab(+1)^(1-alp)-del); - c=the/(1-the)*(1-alp)*exp(z)*k(-1)^alp*lab^(-alp)*(1-lab); - k=exp(z)*k(-1)^alp*lab^(1-alp)-c+(1-del)*k(-1); - z=rho*z(-1)+s*e; -end; - -initval; -k = 1; -c = 1; -lab = 0.3; -z = 0; -e = 0; -end; - -shocks; -var e; -stderr 1; -end; - -estimated_params; -stderr e, inv_gamma_pdf, 0.95,30; -rho, beta_pdf,0.93,0.02; -the, normal_pdf,0.3,0.05; -tau, normal_pdf,2.1,0.3; -end; - -varobs c; - -estimation(datafile=simudata,mh_replic=1000,mh_jscale=0.9,nodiagnostic); diff --git a/tests/practicing/HSTBayes.mod b/tests/practicing/HSTBayes.mod deleted file mode 100644 index ef5db051c..000000000 --- a/tests/practicing/HSTBayes.mod +++ /dev/null @@ -1,62 +0,0 @@ -// Estimates the Hansen Sargent and Tallarini model by maximum likelihood. - -var s c h k i d dhat dbar mus muc muh gamma R; -varexo e_dhat e_dbar; - -parameters lambda deltah deltak mud b bet phi1 phi2 cdbar alpha1 alpha2 cdhat; -bet=0.9971; -deltah=0.682; -lambda=2.443; -alpha1=0.813; -alpha2=0.189; -phi1=0.998; -phi2=0.704; -mud=13.710; -cdhat=0.155; -cdbar=0.108; -b=32; -deltak=0.975; - -model(linear); -R=deltak+gamma; -R*bet=1; -s=(1+lambda)*c-lambda*h(-1); -h=deltah*h(-1)+(1-deltah)*c; -k=deltak*k(-1)+i; -c+i=gamma*k(-1)+d; -mus=b-s; -muc=(1+lambda)*mus+(1-deltah)*muh; -muh=bet*(deltah*muh(+1)-lambda*mus(+1)); -muc=bet*R*muc(+1); -d=mud+dbar+dhat; -dbar=(phi1+phi2)*dbar(-1) - phi1*phi2*dbar(-2) + cdbar*e_dbar; -dhat=(alpha1+alpha2)*dhat(-1) - alpha1*alpha2*dhat(-2) + cdhat*e_dhat; -end; - -shocks; -var e_dhat; -stderr 1; -var e_dbar; -stderr 1; -end; - -stoch_simul(irf=0, periods=500); -// save dataHST c i; - -estimated_params; -bet,uniform_pdf, .9499999999, 0.0288675134306; -deltah,uniform_pdf, 0.45, 0.202072594216; -lambda,uniform_pdf, 25.05, 14.4048892163; -alpha1,uniform_pdf, 0.8, 0.115470053809; -alpha2,uniform_pdf, 0.25, 0.144337567297; -phi1,uniform_pdf, 0.8, 0.115470053809; -phi2,uniform_pdf, 0.5, 0.288675134595; -mud,uniform_pdf, 24.5, 14.1450815951; -cdhat,uniform_pdf, 0.175, 0.0721687836487; -cdbar,uniform_pdf, 0.175, 0.0721687836487; - -end; - -varobs c i; -// estimation(datafile=dataHST,first_obs=1,nobs=500,mode_compute=4,MH_jscale=2); -estimation(datafile=dataHST,first_obs=1,nobs=500,mode_compute=4,mode_check,mh_replic=5000,mh_nblocks=1,mh_jscale=0.3); diff --git a/tests/practicing/HSTML.mod b/tests/practicing/HSTML.mod deleted file mode 100644 index 6e94f0f30..000000000 --- a/tests/practicing/HSTML.mod +++ /dev/null @@ -1,62 +0,0 @@ -// Estimates the Hansen Sargent and Tallarini model by maximum likelihood. - -var s c h k i d dhat dbar mus muc muh gamma R; -varexo e_dhat e_dbar; - -parameters lambda deltah deltak mud b bet phi1 phi2 cdbar alpha1 alpha2 cdhat; -bet=0.9971; -deltah=0.682; -lambda=2.443; -alpha1=0.813; -alpha2=0.189; -phi1=0.998; -phi2=0.704; -mud=13.710; -cdhat=0.155; -cdbar=0.108; -b=32; -deltak=0.975; - -model(linear); -R=deltak+gamma; -R*bet=1; -s=(1+lambda)*c-lambda*h(-1); -h=deltah*h(-1)+(1-deltah)*c; -k=deltak*k(-1)+i; -c+i=gamma*k(-1)+d; -mus=b-s; -muc=(1+lambda)*mus+(1-deltah)*muh; -muh=bet*(deltah*muh(+1)-lambda*mus(+1)); -muc=bet*R*muc(+1); -d=mud+dbar+dhat; -dbar=(phi1+phi2)*dbar(-1) - phi1*phi2*dbar(-2) + cdbar*e_dbar; -dhat=(alpha1+alpha2)*dhat(-1) - alpha1*alpha2*dhat(-2) + cdhat*e_dhat; -end; - -shocks; -var e_dhat; -stderr 1; -var e_dbar; -stderr 1; -end; - -// stoch_simul(irf=0, periods=500); -// save dataHST c i; - -estimated_params; -bet, .91, .9, .99999; -deltah, 0.4, 0.1, 0.8; -lambda, 2, 0.1, 50; -alpha1, 0.8, 0.6, 0.99999; -alpha2, 0.2, 0.01, 0.5; -phi1, 0.8, 0.6, 0.99999; -phi2, 0.5, 0.3, 0.9; -mud, 10, 1, 50; -cdhat, 0.1, 0.05, 0.2; -cdbar, 0.1, 0.05, 0.2; - -end; - -varobs c i; -estimation(datafile=dataHST,first_obs=1,nobs=500,mode_compute=4,mode_check); - diff --git a/tests/practicing/TwocountryApprox.mod b/tests/practicing/TwocountryApprox.mod deleted file mode 100644 index 02b2ced97..000000000 --- a/tests/practicing/TwocountryApprox.mod +++ /dev/null @@ -1,45 +0,0 @@ -periods 200; -var c1 c2 k1 k2 a1 a2 y1 y2; -varexo e1 e2; - -parameters gamma delta alpha beta rho; - -gamma=2; -delta=.05; -alpha=.4; -beta=.98; -rho=.85; - -model; -c1=c2; -exp(c1)^(-gamma) = beta*exp(c1(+1))^(-gamma)*(alpha*exp(a1(+1))*exp(k1)^(alpha-1)+1-delta); -exp(c2)^(-gamma) = beta*exp(c2(+1))^(-gamma)*(alpha*exp(a2(+1))*exp(k2)^(alpha-1)+1-delta); -exp(c1)+exp(c2)+exp(k1)-exp(k1(-1))*(1-delta)+exp(k2)-exp(k2(-1))*(1-delta) = exp(a1)*exp(k1(-1))^alpha+exp(a2)*exp(k2(-1))^alpha; -a1=rho*a1(-1)+e1; -a2=rho*a2(-1)+e2; -exp(y1)=exp(a1)*exp(k1(-1))^alpha; -exp(y2)=exp(a2)*exp(k2(-1))^alpha; -end; - -initval; -y1=1.1; -y2=1.1; -k1=2.8; -k2=2.8; -c1=.8; -c2=.8; -a1=0; -a2=0; -e1=0; -e2=0; -end; - -shocks; -var e1; stderr .08; -var e2; stderr .08; -end; - -steady; - -stoch_simul(dr_algo=0,periods=200); -datatomfile('simu2',[]); \ No newline at end of file diff --git a/tests/practicing/TwocountryEst.mod b/tests/practicing/TwocountryEst.mod deleted file mode 100644 index 1594a2a1a..000000000 --- a/tests/practicing/TwocountryEst.mod +++ /dev/null @@ -1,51 +0,0 @@ -periods 200; -var c1 c2 k1 k2 a1 a2 y1 y2; -varexo e1 e2; - -parameters gamma delta alpha beta rho; - -gamma=2; -delta=.05; -alpha=.4; -beta=.98; -rho=.85; - -model; -c1=c2; -exp(c1)^(-gamma) = beta*exp(c1(+1))^(-gamma)*(alpha*exp(a1(+1))*exp(k1)^(alpha-1)+1-delta); -exp(c2)^(-gamma) = beta*exp(c2(+1))^(-gamma)*(alpha*exp(a2(+1))*exp(k2)^(alpha-1)+1-delta); -exp(c1)+exp(c2)+exp(k1)-exp(k1(-1))*(1-delta)+exp(k2)-exp(k2(-1))*(1-delta) = exp(a1)*exp(k1(-1))^alpha+exp(a2)*exp(k2(-1))^alpha; -a1=rho*a1(-1)+e1; -a2=rho*a2(-1)+e2; -exp(y1)=exp(a1)*exp(k1(-1))^alpha; -exp(y2)=exp(a2)*exp(k2(-1))^alpha; -end; - -initval; -y1=1.1; -y2=1.1; -k1=2.8; -k2=2.8; -c1=.8; -c2=.8; -a1=0; -a2=0; -e1=0; -e2=0; -end; - -shocks; -var e1; stderr .08; -var e2; stderr .08; -end; - -steady; -estimated_params; -alpha, normal_pdf, .35, .05; -rho, normal_pdf, .8, .05; -stderr e1, inv_gamma_pdf, .09, 10; -stderr e2, inv_gamma_pdf, .09, 10; -end; - -varobs y1 y2; -estimation(datafile=simu2,mh_replic=1200,mh_jscale=.7,nodiagnostic); \ No newline at end of file diff --git a/tests/practicing/cagan_data.mat b/tests/practicing/cagan_data.mat deleted file mode 100644 index 0d27da163c26c5a996e548287c3a6dd4c699bb11..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 801 zcmeZu4DoSvQZUssQ1EpO(M`+DN!3vZ$Vn_o%P-2cQV4Jk_w>_Ia4t$sEJ;mK$j`G< z@XgOt@G8wyFfdUtw6roYvNAMOFfuSOS0EWMFnap(GcYi?Gcqt#%z2!gkWi42l90fB zNrp#2iX~!UjjBQ#OR`$qogg+gKZR%p4TZOlXDZ4R7X07%Je^#dougizaQc&@^3$xp*L-po zj6SpO*7+OD%y(aZI^*xcUF_3ecjeuVpQBM%>i5d^ciS@A>JV4{oB9v>cD^mGT=sX~ zuKwkb{&P0||7P8H{?mcvYKE>=Q|m#&>4i5q-P*Vm&T<}Ma%c>et>1GfE&fLRf}~@| z|L*pC>p$mTMeg>SOaJb^({hcwY|icZwc4xH!X91v$7iOitbDBd_j51H|669(*X^G% zfA+-wAFY2s=RaARcE^6>|DDs1H!fE9d-MLnN}fllaoO>cZ|rb>e`n&~_n++c#0zdo z{69DQzudel_wxQPi2Chv^X%o{;a7fMKbvB?(f-c&{0xr6jeq&&p5|=+v*F6WZlBh~ zcl&gI_nzm}E%&zBY@eI>itT)7`}gXYJ7KqqO6S||PCD^NT5J28yIN(b?Hgpaif?=O z{`JP4$^XmC-n4dp{QgGx+4=py4=%a4&#iHH-nzSX)e8?^mF+xx!n;_uf7 ut()}v@!!e6m+So2e0pNb`G4+jmj3x$=l{lDWZs*9`X7$TF}!J*I1K<)0FIFW diff --git a/tests/practicing/dataHST.mat b/tests/practicing/dataHST.mat deleted file mode 100644 index 107ce6fbcbbe85cfab742a06b5dcd92b34a64913..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 7771 zcmb7|WkVAT!$ws?x;u4_wfA7s(d1c%;Z{7^yym{lB%cq4dsBN$; zQzG94#`Nb8iaU80Y%x72LC>CNh^-3%<@<})1KdDFF zpD?nn&Yuvkuc9!&#ip6I`!-n5ddp%yClk{mD;pF4_brCT*Wp(&^;ZEZybpxMCh(Ye zpjxg{0lQG2(eb8+gD}+#HOw&k@w5&dw}rDeQSXNca)~VFN;FwaK{eLoq#0gbciu8$ zc%#DD3nYV#M4!gBUx$QMWpBci@sT@IjI7Q89Z4gH8#u^_rEh}^xHKmd@f=eLE}k;o ztcOuLb6Bf-E~|c02$S@K#_c#s`LoPWE%!Z^QkCS}A*(3P4aPfm6|FM+w+C9zj3w%e z+8)(F|K1qmUb@4c&%Sc|CO7J7=tuYS9&7j?j$_FdjU*Z!v{(K1-a?l`RqtY|!GTT| zeme~56^#tFFiD7-c0&D>Hj2yKV_nGNK(@a=xDl<`=Kx`#O7HvS9Fx5LQ(`O1enE+9 zeWDIK{oMNEiMqhCho#}oXSH-srn)3;r%UZw^bHUVaG05mYZ4#3^*9g{0(;ts;F5Fj0 zC$Q9=_czXJU3lPXnDeD$l6tKV1yGaWjY!af_{(?Mkwo+NAiLkOR>kv!2veoGhwA1t z^G7$+75+7{qSiRn9E>S;!m6wN7Qmzrb&X07{sodzrmsD>#LchPmm&3}riEFZw(ho= z;aN=|^I8Kf3O~bbLj^=(ZXtwvOQ@(LziJP$QLrMWm@vbCk>x(0wRX*<9c{Uvn|tc!dF+uQ0D*PCf^fe`8Y96h$nMkZRC9pEN?=j}}gU-Uza|?0u;q?N>76-*+xb^a9c22Qyvby2vBquFB_(qdYo6( zs6PK&C>{LZH+#XU+d2~)O*tjfWT-=Bt%y32ezwuimTMrel=wca+d*UrN#v{e(bY@t zI1;{W-@nJu_v6a`!GMK;gWOg9@%bg8<1g>iuT;GmIYhpJzeSYDr<`4?soz+h9}0=> zh<>HL|Bf3_PY4ZBKsU8Ua9j*ozSYj>H(6oC`>luYixLBUb2#f6mUn(9qL{q&HI7h1 z@g(h~Ir<%gXS}wiJf>P>(7s1YBvJehoK6ShFD1EHvLi#pQ1Q-(UT8$SU((KF1)ABl zOS^McDxRbq1z?C1&%DXvpS_kStq?Yyjl&A&&*Wm(wq==^vV%CUkWqA65#f;IOKIAz zq##{tPvscdN8x!Yg*dMEoo~_gzt94N?pU#xW4Pc}R&^8P_`#_pZ7l||g@&uUr`>W9 zP4SN@X{|A)X^T!z{ffwK8H8n2-b7}PJ3V4QqUa#rfmBtq#GBw=DXrmObjgK@(5e!d zv6dh5xiBW_^~%Tna*f=h?lDlKZVaKm&(JRQUpTne1)9$hQC`zILg+&au>u^N_>j=K z?R8@xANql$wX3Ug(D8W@9E>W4Xk7#^oN1D8^_x1V-BY9C4|%*Y;>fxm7;mizhATPe zX!iqM)`ZjB?nRIF+jCv=1A&nEK!cx^PyL%UY+4wZs`_LsR?+`NO{7Bhhk)jIj^E$j(rdd)vE=IE`2cu znh+L=Mp(R4EYiDF!MmHOA}{d_BjG!D>2FrWn*{fV0mAWt;Xd2%x+%abz0r&GQo-5I za2koF+rgrF&)1r8bHTG^pA?JB1-k##}4ic|Spb^WFiAz8Gks@`l& z^e=&n5gi(s3o}9mRb3h~?MrS8Y_WI8)*a+sAQj|FZ@b%%Omss5-LX##`VkxOb@S(N zx(Xd?a$<2nSgo_({MaY_Bu%KV=KI*$nira%r!i=KH#x6a#Oy_Z>waWkMq@jQ*KkHF zaYmxUn-01m;}o?KXr0cDMapv=_;rHu9~|~$HnP*NPcAj^Pk1zyc3`m$ExbaL#VXPs zV+&?8$!O*&_KK}D)@I3Y@3`8xn8S$GC)U2k_5guSM+kWM=H1NG-jW`~Z?f|wd-O|X zafMSugp7OGaxl1!-I_zho2EK(IO=`mH4j`DE&atk_?RUgKr$INsDO-!#7$ZT(6#q| zGPDb4>|dz{zqWT|Z47+1y8|(Yfw+%hJ14ZW9qd7zyIlQ5##^g7p~yajY{TIe=z&ho za1}Nhu0;(2o+_s0%v+#nVV0@EQTF;UkqdJAcOE;O+BLgYw-mty(h2cLmOp0yvI4hX z3XnZQj-m^4e*ZkvTv54=r6>cpXOVgm1ezJL%e|J}jx}V2Q4@UK{WNu<#N5!;H6CKY z)1N}&H18Uh@?7JO6ODfZC4SD@1YI;ZRPgi0Y{X2=X1BfxyIpHo2OYOme?=4bNd7G{ zeR4@5BnA`&j2z*;^+d@10ftr9*!ca{3(Lg1pNLk`5VKD>Isy<#_pJmm3PfxaJU^=e zKcKOb7<6Y6O1X;lUAh|+^>2ghUbZsO)ft=+p7nSXzcx<$yz(Ui9u_ToJ|biG0^0q% zBWO-097-F@kpr@wK@B~M$>05NyZu=ug0oW!U#C zmP-HUS=6xE5|>b82Q+wU+jR10hRmiK83Sms(Hp8mb8@OltYKE5MLvw zxQ%B0iE^dXH|=goyr`rsb7P^Hab>hXjncBY<)wld4JZ3Wwl~gHUu8shm@w?~loUx= z2D0QL&;RGm;4r2=VOBy=!p_ z{@#>|)vr)ZbPif$*Dg)yXb&`XTfJTTIWxr$5yf@z&1kBCbOB9Tl84)1^#C1to6Ab~ zeWj3WT!*8d#+MN?-c$c(rQuXo4(|=?e;v$Co=t+szB;gibpRR{yU{tp8ks1(zY+WKO@_BK*qp!*UaoTLeh z@~$Wku8wQxgMXCSAsA^ZXOR>PcU_TPh$%CxLZ!t+9}4p4QlzV1_Y1%bBDgJMa4(<@ z>9+h}ki~1F5gJ6ne@99}`nqG<%HB3?9wpX17rrGhGcR`=w>Iy-Kkw(Vnk1$P8C~|< z4N{B-4&6`Y`MJeNg$AcU+TP-X9mI6;*BplA6;<(Ea64euVsIKt- z=L`k#CYse=R`8(7$u5_V|GqdXt=?(9cNmzQMO0wo@k$pP-`08^FT?tjPn+( z^OPOS2~&8v6!Kvv_|Z*uh^e+{*KX27>)xUiQ|)w`g_vO^$<}%5o@*V>AO>CfFMa2fR&eQ z%;vA^=WgA5zW6PTL*q*bn8XK?k@aGF*<4gIW*lm|k)>5Qr0(x>r~Ns$ivT(9hgIqz zdfi>~^yXg*{R|K8(c0wSRg}W9fTG!tS zj}{~IKip6W-GVA3KlVhwzMpa(A^5+Reg7Z+YgtV{K_bH^sy|rPqzPoaDU8rbQf`aM zLY6j02F;jXI_d0on=+VcF8W_t^;w)&*l9~khOfqRnt!CS>#;h0{gj5->k5Y58}4_U z9p^szon7ZXfs2)B@cb*0->Jo2MZAu_My!V1Z}T9BdCF@<;eC=pu}fDxwitXR)I{Je z+;jgjcc^$U;_ypPD|+`Y6=We!T){%tsH6ugi>MekFiRb^#IsW9Sa&0G-A@AkRK$M? zt=}RU|9-g~vF6we03_L<2*ZZbC03fPTx?ivk*ZM zcCKp~BU0TUk!i2yu88?om;B=Oafdbu^T1V$*34fuA+al zU+Q-9trdyd5`d@Z@BUnGDp1g^`R1jllCl@gvSoG(mgN&*MBJXj0|;&RJ5<)N0>_1HK1`ePYdBX}Y$%(^N&mAaq{%H2Cyn{_7r%tRH|~Jy*oy z>fS5V!TBSsC^c7AgO#jvod2V`98sf2BaPxb2p@Y~ZcRs?TcU>VI-3N&^qh?T31bJp zj4H_Vk<3qUO3e6_Q}lk-@{!9e>D`_&*0P~{N{sF9k2hTeboy0yo|eD78HVQ%(x_6L#+Z8LR%WtdIzN~h zwxYX7u(g5+Y=5eW8afcr{o5iKRG_QFuoz8iXK4SklmOZN;VR|`j~nzM=BnMjYre|E zAZ23f;0&Mx+k>uT6n#*dgOe)jvQ(v^RRt-X>@w}(<&6FL)Z`BnO01nKp?WPZPevR> zx`<^X;oiuw-l<60ZWSIxHk;;|P_mhaZOJ3tn33#&p4g(Ty=nTv&}*hH;r4$YDjTF<1KT3_KtHgs*UI%Ze<$; zk6Milc&~*WD$Mf|N3J@EdFOrAkIJ`tKqehUf&Ee02cfl5j6<2zoksHOsNp$#$-E&M z^?C8VniPq>Zu**$+Ak?=x7CNOAQ+_Zce`ebNmSIo*l=(AP{XM)UBD#mS!aeW1cfZdH?60ne z$GK`lgm#~CQGn;watmQ;_~-3M&>l?9hx%K_Xbnhmn?f*DBA(p&k%{A;VYVS#zP zGinH2nqtiN*-_ayJ>?-LY9|)>7S>~{iq30x`+1IQkyB_GSegU~9nu1E9FkT6ifde~ zelu^c3hdirJBpevIp0bm#hz{YgA=mQT3C6^M;r>vSp=(tDp3=(S(=YQT)$7S1m%6l zzb#CM(>MDHy*P_ca_A|Kx-s7tOu+tLe%^rd*S{5tpjIGZNFl2btuu6%GyBc*ikR|6 zLhaSn=)Lpgo;87fCl3CK^eZ;n9F2${A*XeOGd3*&(wLdv4pf$AXch@}w?pkzdbDoo}Ip%QR~^9Ow5 z^LI>!Z5n8Lf0U5_?)N2}+JuD+Eah`$L|XJ)uukGLu|~-KATMkB4xfdyFlHyJcio&( z4v<|4pux?iGDDkqVk>Kd9X(Gn>-UiOgU{zV*t$nY;%yD|T{$sZ1iGyK`pmb6{O4D% zg|k%8U`ui?rbU|tXdo~S6J0g+LJB938AbX|4@+bu2fwtMGt0;E$!CkrKHb8YIjOc+ z^WyViw=+wzkGK^al3Het%j{65a-o4Qdn4K6xl6pWJ>?;So=r?!2}TLpbIqy__{AhG z%9wHsm>)#yAVY17$EEcneB8vDh%?uC63_OdrvSR#U8qApm{MSE zJCuYIXq#W^Z@;~n#(te^#-S7<^vEV#l86q#cGt+}=N#e(PAD%)UIi}Q9LxwE3v(OIt%Rx4W=Dq+su5PIhGnn;V zi0QvFmL$yA#wnb(+MBUBL7gl$l){eCs(98c@*-9Z+{0Gd89$qwYmGJ3JRCs!NXzI6L=yL@KDvaZk1Wc2&YVE(~x2ZUO?*l zC~x(~s}J#CvD^zCU#rig8QTGt1+HxQvHIHeRgED6Xc;A4slDf;oR zavhoTi+4jD;P~`%=&x`i->;Pjc++fJG{=#m$cy8ine=Bz$KU%uXRiBc3z`gva`_1W zw)-@^nVlNY$oQXoYdRb*9^di!7iNks3;o36AYJkCwY1L~r_lC?xrZpi=ZJX!sH*r! zIw}&_xUo?3nABz!Y5FG72e6z=+|Z^7o?z^#T#nz^?ykCHI{D_@_4C9uD(Pm~*5X-; zP9k2Zvrn-NIklEI3Mi4|Ax71&_n{e=y7~Ovrq*+NyS1qAY*vo`@Rflo?dGD9Mc-IF z&N^YYCzSVrz{1xr&)N`+PuAiYGP@)*;(Fn0*_~mNFv$ndwJ#e{RsR#z{DebIc;Yeu znn`didVZ;nol@`dGkQ-??ptvsTJX#i9gTP1;)T0@Y3gf+4;33js~7O}>;YOtNcQRX zOa+SRr$18lT@IpgZtLa2T@q(6{Q@BPY-0ZN%c*?=my%{Wh}%{$u1$DSX1=7Dg7fz} zEtRkP;pa`9FYKC1`0qJ2C&RwH%tY|XDY<$_vRK@ILl2v>bh%~C*>XU)kbGd$$i?iX z7t}S48~+R%$a2^4<*s=0oKvFpAF6L`cZs_xO63@Um1VZ-NZq&AypiufXgC{{*+Swg zjy!o}{tbZ(N)43%Hgtz-fIe*W{Q1F;g)v*10%-7O{C!kRx$RH?E*ES!-iVK}89eI( zVlzV1e4`cpX8%2U)_0N*L^CaF939)r{1oie3Sc?qLJ9SoEay@ge_Hz+ z*r4-m4|!yF{ma{ds2%FbK01lZIz2+9#&?s{@LtBiq&JJiVc*Wp-@=iy*XlCSE>aFt z^G80I_B=*uaaz9<{8(1!e2-VyDZlG~O!u~R1;!3!q?g{R8;LAdj6jR`@4J$U!n=e6 zdiC@0zr4csIqr`lVs^ajtyb~3VrEeC9n0}h3YuGOu`y`x?e*(Ay2mzf|5t$5}FOcg-2 zFFQ>izZj!pHu77Eu6ZXmzpg;_?KANf|F|$&R7X~r?|%sVLo%@AHt{Di=iW`hx(u&IHmx!RhEh>g(CNshgOY7Alg}62d|oA#JlAYzzN|$H zO~6$#sgge6OJVtH_8nShL#2fpK;9~}rw3wFYiFAuBGfPZdp3-~4*GutLG&@iD1EmL^MFjPX2o;m8giw>caRe#%3OW!w$vpY>PakxbNp>%G zM9YcTyqSa}pjSsZOnxb%gJ2S_l<`&YZ&g(=j*r+OL*6MYp6!0D9ny>P1G zzk5bEta>mChuKDcc86>_4(t1GZkgAqGimgO5}E3g3S_q%t$W6EhS_>Ub>d{E&;{)L zM8iyEk2vB~q)A3W!$l#yTH5}p<|Zfgpw8 zSw0a>zrks)qZ|lbr9EmgSoD+ZAkuW?T-IE`KTfahIbf3h0>xJ&cFDgZFDtfDH$5(F zvg{*6s`YvgE=`@t{bJ?LhZ61N2#`v@tBU$V7DfS=z$kXYiodYPYU!e}8 z$%$mUGV-jt4u_l02scgxI+Q7#yXGmO752|(Ac+yKaN#sblVrgDmYJE!y0H}{>Uz3f zEX(@sIKA5T3@7I2eFUZJ=syC3wWy*Mv)CF!@OzTUCh49EFmaWAtW1!AHbtOCXlJm` eAibkvLYIL7u7jR=sx80E+!(>@dkVB~!2bb7u}`G{ diff --git a/tests/practicing/data_consRicardoypg.mat b/tests/practicing/data_consRicardoypg.mat deleted file mode 100644 index d8a94dc7db42bfd73c337b55fbe7c48e816bd547..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1959 zcmV;Y2Uz$`K~zjZLLfCRFd$7qR4ry{Y-KDUP;6mzW^ZzBIv`L(S4mDRAVYFxVRU6= zAa8CuAXjB%AWC6wATTr_F)%tYHaapiATls8HXtA%ARr(hARr(hARr(hARr(hARr(h zARr(hARr(hARr(hARr(hARr(hARr(hARr(B0ZB~{0000V2LJ$goGp@jG}H+j#|LE_ z5w)6zO=_9mR94AK$$lv!tu9h>3*&B@!Wc8gU}g;Ce!pZIlFIFbinZmkKb2`Stxbhc zHZ2t;q4%xbNU!(uobx%K^F8M|&p*$18Hq%4_=-eQUGNgp|NNg>{Qo?%fYN_aB1JEl zya07!-`R1mhO(;|?xYIKk)$I;cW-%SgkBE87pnBQ&;!v^(Is#DO$gFACWk9DwTZQ~ zdyV9+DIk-p!{1Fs;1i`hCQ%v=|Asf8G)JNd>UG=g2R;jNrT5v~sp%w0Kgm6G<};B# zTj+mnR)8*k)0qP_2_c^2=Zduwq5X15Ll(>>?&Q;SSYBxeGlfhwEfoEaSb2TpF0ig? zAs=6n1M{XwshW3EP*=F+R&1*T!Rx}*?X!e%i%+izZWKYb!_$&&>_cSetllPf<`S|G zEd2+O96Z{@A8&Syfcdkx{*SAYu{4FLan?5p%iK>i#;+8?YRH+O9GUNld+?S2~vN>xV18E+PH zWXyHyTRHeWS~mWs<2XEPb$!PAqEO$qmOgEl2u5L-$LA&%-ZIQvRI}3HFsjU%zL18V zZ69u5tVn^&e#)lq2V9tyr?)FU$06Zn-b>w`3DEW*Rjaw02)bB$i*l*}fgP8N9hEo; znxB_?>j|KHDN{i+kAzKj_?IaaCh~t@bF@ZV2tTch&ezSvba7 z#jbf-8R)$ zuB%=+iCRVV+t-K0IM%yTukkxE+RS`<sk zioCoNKezKhb-%d%-Jcn-Ola&m%w~WjWn6YjjlmJm7xffg2CfJmUKSJ!;eBWIg!N(( zEJ|Lcd`p+$a%#gM3nI|M{3`*k$aLw9j+52SiP6h*B3~bhAdLt5puA>bF_Bw^)6z}cyh41 z-UavSEe1Zt1*7ZA$c~B`CRViXG`noigZr$X(U*n{WHJh}mA^~G$)8l5*Qg|-X+-Y_ z`Dhw4n+@|XUP}PA?Bk`GQ+}BA47TbkPR5)llzjG0Jo-kLw|aC6A=5}7)}yAOsa~=7 z^%6eb%@1veU7d&sXUQ7RgV88`u3n(j8iiednXJY~9!zBu^}oIkgOnz!phpUjY#6~9 zFBQW6)D|;#6(3{Gx3Z>r;dnkikZgJ|3Xd0g-zW(ZV|mG^>AVfmURw9DptR2)|my6l=t^Kc$)&woBLiJrhFgR#VV8)zLUalkU3y4X9rFnSH*}wbts0Nar=}Ln#V6q~ zeNIlk8-p)~Wv&4)mcaI(rj8U09+JBUFiBW9nc($=94s8zp{5mfolFnB-#7=PWsz`Dw{R0nE zzVgX+ZSI7)A-A}Ej~y%(A#}kqKm2u&T>s<3-@6RI^2%)%Vtvj8Y_6~{xTE30Gpobk tyKU^!+{46BvY4psVxd{t%_jeq3w{jI8BntoV3%F${Y$r_@ozk9Rt{ggsEGgo diff --git a/tests/practicing/datasaver.m b/tests/practicing/datasaver.m deleted file mode 100644 index 0ac532a4a..000000000 --- a/tests/practicing/datasaver.m +++ /dev/null @@ -1,58 +0,0 @@ -function datasaver (s,var_list) -% datasaver saves variables simulated by Dynare -% INPUT -% s: a string containing the name of the destination *.m file -% var_list: a character matrix containting the name of the variables -% to be saved (optional, default: all endogenous variables) -% OUTPUT -% none -% This is part of the examples included in F. Barillas, R. Colacito, -% S. Kitao, C. Matthes, T. Sargent and Y. Shin (2007) "Practicing -% Dynare". - -% Modified by M. Juillard to make it also compatible with Dynare -% version 4 (12/4/07) - - -global lgy_ lgx_ y_ endo_nbr M_ oo_ - -% test and adapt for Dynare version 4 -if isempty(lgy_) - lgy_ = M_.endo_names; - lgx_ + M_.exo_names; - y_ = oo_.endo_simul; - endo_nbr = M_.endo_nbr; -end - -sm=[s,'.m']; -fid=fopen(sm,'w') ; - -n = size(var_list,1); -if n == 0 - n = endo_nbr; - ivar = [1:n]'; - var_list = lgy_; -else - ivar=zeros(n,1); - for i=1:n - i_tmp = strmatch(var_list(i,:),lgy_,'exact'); - if isempty(i_tmp) - error (['One of the specified variables does not exist']) ; - else - ivar(i) = i_tmp; - end - end -end - - -for i = 1:n - fprintf(fid,[lgy_(ivar(i),:), '=['],'\n') ; - fprintf(fid,'\n') ; - fprintf(fid,'%15.8g\n',y_(ivar(i),:)') ; - fprintf(fid,'\n') ; - fprintf(fid,'];\n') ; - fprintf(fid,'\n') ; -end -fclose(fid) ; - -return ; diff --git a/tests/practicing/hall1.mod b/tests/practicing/hall1.mod deleted file mode 100644 index 8383715f5..000000000 --- a/tests/practicing/hall1.mod +++ /dev/null @@ -1,46 +0,0 @@ -periods 5000; - -var c k mu_c b d in; -varexo e_d e_b; - -parameters R rho rho_b mu_b mu_d; -R=1.05; -//rho=0.9; -rho = 0; -mu_b=30; -mu_d=5; -rho_b = 0; - -model(linear); - - c+k = R*k(-1) + d; - mu_c = b - c; - mu_c=mu_c(+1); - d= rho*d(-1)+ mu_d*(1-rho) + e_d; - b=(1-rho_b)*mu_b+rho_b*b(-1)+e_b; - in = k - k(-1); - end; - -//With a unit root, there exists no steady state. Use the following trick. -//Supply ONE solution corresponding to the initial k that you named. - -initval; -d=mu_d; -k=100; -c = (R-1)*k +d; -mu_c=mu_b-c; -b=mu_b; -end; - -shocks; -var e_d; -stderr 1; -var e_b; -stderr 1; -end; - -steady; -check; - -stoch_simul(dr_algo=1, order=1, periods=500, irf=10); -save data_hall.mat c in; diff --git a/tests/practicing/hall1estimateBayes.mod b/tests/practicing/hall1estimateBayes.mod deleted file mode 100644 index e78ec113b..000000000 --- a/tests/practicing/hall1estimateBayes.mod +++ /dev/null @@ -1,54 +0,0 @@ -// Estimates the hall model using Bayesian method. -// hall1_estimate.mod estimates by maximum likelihood - -periods 5000; - -var c k mu_c b d in; -varexo e_d e_b; - -parameters R rho rho_b mu_b mu_d; -R=1.05; -rho=0.9; -mu_b=30; -mu_d=5; -rho_b = 0.5; - -model(linear); - - c+k = R*k(-1) + d; - mu_c = b - c; - mu_c=mu_c(+1); - d= rho*d(-1)+ mu_d*(1-rho) + e_d; - b=(1-rho_b)*mu_b+rho_b*b(-1)+e_b; -in = k - k(-1); - end; -// Michel says that in a stationary linear model, this junk is irrelevant. -// But with a unit root, there exists no steady state. Use the following trick. -// Supply ONE solution corresponding to the initial k that you named. (Michel is a gneius!! Or so he thinks -- let's see -// if this works.) - -initval; -d=mu_d; -k=100; -c = (R-1)*k +d; -mu_c=mu_b-c; -b=mu_b; -end; - -shocks; -var e_d; -stderr 0.05; -var e_b; -stderr 0.05; -end; - -estimated_params; -rho, beta_pdf, .1, 0.2; -R, normal_pdf, 1.02, 0.05; -end; - -varobs c in; -// declare the unit root variables for diffuse filter -unit_root_vars k; -//estimation(datafile=data_hall,first_obs=101,nobs=200,mh_replic=1000,mh_nblocks=2,mh_jscale=2,mode_compute=0,mode_file=hall1_estimate2_mode); -estimation(datafile=data_hall,first_obs=101,nobs=200,mh_replic=1000,mh_nblocks=2,mh_jscale=2); diff --git a/tests/practicing/hall1estimateML.mod b/tests/practicing/hall1estimateML.mod deleted file mode 100644 index 82eee5646..000000000 --- a/tests/practicing/hall1estimateML.mod +++ /dev/null @@ -1,56 +0,0 @@ -// Estimates the hall model using maximum likelihood. See hall1_estimateBayes.mod for Bayesian method - -periods 5000; - -var c k mu_c b d in; -varexo e_d e_b; - -parameters R rho rho_b mu_b mu_d; -R=1.05; -rho=0.9; -mu_b=30; -mu_d=5; -rho_b = 0.5; - -model(linear); - - c+k = R*k(-1) + d; - mu_c = b - c; - mu_c=mu_c(+1); - d= rho*d(-1)+ mu_d*(1-rho) + e_d; - b=(1-rho_b)*mu_b+rho_b*b(-1)+e_b; -in = k - k(-1); - end; -// Michel says that in a stationary linear model, this junk is irrelevant. -// But with a unit root, there exists no steady state. Use the following trick. -// Supply ONE solution corresponding to the initial k that you named. (Michel is a gneius!! Or so he thinks -- let's see -// if this works.) - -initval; -d=mu_d; -k=100; -c = (R-1)*k +d; -mu_c=mu_b-c; -b=mu_b; -end; - -shocks; -var e_d; -stderr 0.05; -var e_b; -stderr 0.05; -end; - -estimated_params; -// ML estimation setup -// parameter name, initial value, boundaries_low, ..._up; -// now we use the optimum results from csminwel for starting up Marco's -rho, -0.0159, -0.9, 0.9; -R, 1.0074, 0, 1.5; -end; - -varobs c in; -// declare the unit root variables for diffuse filter -unit_root_vars k; -estimation(datafile=data_hall,first_obs=101,nobs=200,mh_replic=0,mode_compute=4,mode_check); -// Note: there is a problem when you try to use method 5. Tom, Jan 13, 2006 \ No newline at end of file diff --git a/tests/practicing/rosen.mod b/tests/practicing/rosen.mod deleted file mode 100644 index 1f3798059..000000000 --- a/tests/practicing/rosen.mod +++ /dev/null @@ -1,55 +0,0 @@ -// Rosen schooling model -// -// The model is the one Sherwin Rosen showed Sargent in Sargent's Chicago office. -// The equations are -// -// s_t = a0 + a1*P_t + e_st ; flow supply of new engineers -// -// N_t = (1-delta)*N_{t-1} + s_{t-k} ; time to school engineers -// -// N_t = d0 - d1*W_t +e_dt ; demand for engineers -// -// P_t = (1-delta)*bet P_(t+1) + beta^k*W_(t+k); present value of wages of an engineer - - -periods 500; -var s N P W; -varexo e_s e_d; - - -parameters a0 a1 delta d0 d1 bet k; -a0=10; -a1=1; -d0=1000; -d1=1; -bet=.99; -delta=.02; - -model(linear); -s=a0+a1*P+e_s; // flow supply of new entrants -N=(1-delta)*N(-1) + s(-4); // evolution of the stock -N=d0-d1*W+e_d; // stock demand equation -P=bet*(1-delta)*P(+1) + bet^4*(1-delta)^4*W(+4); // present value of wages -end; - -initval; -s=0; -N=0; -P=0; -W=0; -end; - -shocks; -var e_d; -stderr 1; -var e_s; -stderr 1; -end; - -steady; -check; - -stoch_simul(dr_algo=1, order=1, periods=500, irf=10); -//datasaver('simudata',[]); -save data_rosen.mat s N P W; - diff --git a/tests/practicing/rosenestimateBayes.mod b/tests/practicing/rosenestimateBayes.mod deleted file mode 100644 index 64892b753..000000000 --- a/tests/practicing/rosenestimateBayes.mod +++ /dev/null @@ -1,63 +0,0 @@ -// Estimates the Rosen schooling model by maximum likelihood - -// Rosen schooling model -// -// The model is the one Sherwin Rosen showed Sargent in Sargent's Chicago office. -// The equations are -// -// s_t = a0 + a1*P_t + e_st ; flow supply of new engineers -// -// N_t = (1-delta)*N_{t-1} + s_{t-k} ; time to school engineers -// -// N_t = d0 - d1*W_t +e_dt ; demand for engineers -// -// P_t = (1-delta)*bet P_(t+1) + W_(t+k); present value of wages of an engineer - - -periods 500; -var s N P W; -varexo e_s e_d; - - - -parameters a0 a1 delta d0 d1 bet ; -a0=10; -a1=1; -d0=1000; -d1=1; -bet=.99; -delta=.02; - -model(linear); - -s=a0+a1*P+e_s; // flow supply of new entrants -N=(1-delta)*N(-1) + s(-4); // evolution of the stock -N=d0-d1*W+e_d; // stock demand equation -P=bet*(1-delta)*P(+1) + bet^4*(1-delta)^4*W(+4); // present value of wages -end; - -initval; -s=0; -N=0; -P=0; -W=0; -end; - -shocks; -var e_d; -stderr 1; -var e_s; -stderr 1; -end; - -steady; - -estimated_params; -a1, gamma_pdf, .5, .5; -d1, gamma_pdf, 2, .5; -end; - -varobs W N; -estimation(datafile=data_rosen,first_obs=101,nobs=200,mh_replic=5000,mh_nblocks=2,mh_jscale=2,mode_compute=0,mode_file=rosen_estimateML_mode); - - diff --git a/tests/practicing/rosenestimateML.mod b/tests/practicing/rosenestimateML.mod deleted file mode 100644 index 8321b5546..000000000 --- a/tests/practicing/rosenestimateML.mod +++ /dev/null @@ -1,65 +0,0 @@ -// Estimates the Rosen schooling model by maximum likelihood - -// Rosen schooling model -// -// The model is the one Sherwin Rosen showed Sargent in Sargent's Chicago office. -// The equations are -// -// s_t = a0 + a1*P_t + e_st ; flow supply of new engineers -// -// N_t = (1-delta)*N_{t-1} + s_{t-k} ; time to school engineers -// -// N_t = d0 - d1*W_t +e_dt ; demand for engineers -// -// P_t = (1-delta)*bet P_(t+1) + W_(t+k); present value of wages of an engineer - - -periods 500; -var s N P W; -varexo e_s e_d; - - - -parameters a0 a1 delta d0 d1 bet ; -a0=10; -a1=1; -d0=1000; -d1=1; -bet=.99; -delta=.02; - -model(linear); - -s=a0+a1*P+e_s; // flow supply of new entrants -N=(1-delta)*N(-1) + s(-4); // evolution of the stock -N=d0-d1*W+e_d; // stock demand equation -P=bet*(1-delta)*P(+1) + bet^4*(1-delta)^4*W(+4); // present value of wages -end; - -initval; -s=0; -N=0; -P=0; -W=0; -end; - -shocks; -var e_d; -stderr 1; -var e_s; -stderr 1; -end; - -steady; - -estimated_params; -a1, .5, -10, 10; -d1, .5, -20, 40; // these are the ranges for the parameters -end; - -varobs W N; - estimation(datafile=data_rosen,first_obs=101,nobs=200,mh_replic=0,mode_compute=4,mode_check); - - - - diff --git a/tests/practicing/sargent77.mod b/tests/practicing/sargent77.mod deleted file mode 100644 index eb7828a28..000000000 --- a/tests/practicing/sargent77.mod +++ /dev/null @@ -1,41 +0,0 @@ -// this program solves and simulates the model in -// "The Demand for Money during Hyperinflations under Rational Expectations: I" by T. Sargent, IER 1977 -// this program mainly serves as the data generating process for the estimation of the model in sargent77ML.mod and sargent77Bayes.mod -// variables are defined as follows: -// x=p_t-p_{t-1}, p being the log of the price level -// mu=m_t-m_{t-1}, m being the log of money supply -// note that in contrast to the paper eta and epsilon have variance 1 (they are multiplied by the standard deviations) - - - -var x mu a1 a2; -varexo epsilon eta; -parameters alpha lambda sig_eta sig_epsilon; -lambda=.5921; -alpha=-2.344; -sig_eta= .001; -sig_epsilon= .001; - - -// the model equations are taken from equation (27) on page 69 of the paper - -model; -x=x(-1)-lambda*a1(-1)+(1/(lambda+alpha*(1-lambda)))*sig_epsilon*epsilon-(1/(lambda+alpha*(1-lambda)))*sig_eta*eta; -mu=(1-lambda)*x(-1)+lambda*mu(-1)-lambda*a2(-1)+(1+alpha*(1-lambda))/(lambda+alpha*(1-lambda))*sig_epsilon*epsilon-(1-lambda)/(lambda+alpha*(1-lambda))*sig_eta*eta; -a1=(1/(lambda+alpha*(1-lambda)))*sig_epsilon*epsilon-(1/(lambda+alpha*(1-lambda)))*sig_eta*eta; -a2=(1+alpha*(1-lambda))/(lambda+alpha*(1-lambda))*sig_epsilon*epsilon-(1-lambda)/(lambda+alpha*(1-lambda))*sig_eta*eta; -end; - -steady; - -shocks; - -var eta; -stderr 1; -var epsilon; -stderr 1; -end; - -stoch_simul(dr_algo=1,drop=0, order=1, periods=33, irf=0); - -save data_hyperinfl.mat x mu; diff --git a/tests/practicing/sargent77Bayes.mod b/tests/practicing/sargent77Bayes.mod deleted file mode 100644 index 8895296e2..000000000 --- a/tests/practicing/sargent77Bayes.mod +++ /dev/null @@ -1,48 +0,0 @@ -// this program estimates the model in -// "The Demand for Money during Hyperinflations under Rational Expectations: I" by T. Sargent, IER 1977 using Bayesian techniques -// variables are defined as follows: -// x=p_t-p_{t-1}, p being the log of the price level -// mu=m_t-m_{t-1}, m being the log of money supply -// note that in contrast to the paper eta and epsilon have variance 1 (they are multiplied by the standard deviations) - - - -var x mu a1 a2; -varexo epsilon eta; -parameters alpha lambda sig_eta sig_epsilon; -lambda=.5921; -alpha=-2.344; -sig_eta=.001; -sig_epsilon=.001; - -model; -x=x(-1)-lambda*a1(-1)+(1/(lambda+alpha*(1-lambda)))*sig_epsilon*epsilon-(1/(lambda+alpha*(1-lambda)))*sig_eta*eta; -mu=(1-lambda)*x(-1)+lambda*mu(-1)-lambda*a2(-1)+(1+alpha*(1-lambda))/(lambda+alpha*(1-lambda))*sig_epsilon*epsilon-(1-lambda)/(lambda+alpha*(1-lambda))*sig_eta*eta; -a1=(1/(lambda+alpha*(1-lambda)))*sig_epsilon*epsilon-(1/(lambda+alpha*(1-lambda)))*sig_eta*eta; -a2=(1+alpha*(1-lambda))/(lambda+alpha*(1-lambda))*sig_epsilon*epsilon-(1-lambda)/(lambda+alpha*(1-lambda))*sig_eta*eta; -end; - -steady; - -shocks; - -var eta; -stderr 1; -var epsilon; -stderr 1; -end; - - - -estimated_params; -// Bayesian setup -lambda, uniform_pdf, 0.68, .5; -alpha, uniform_pdf, -5, 2; -sig_eta, uniform_pdf, .5, 0.25; -sig_epsilon, uniform_pdf, .5, 0.25; -end; - - -varobs mu x; -unit_root_vars x; -estimation(datafile=cagan_data,first_obs=1,nobs=34,mh_replic=25000,mh_nblocks=1,mh_jscale=1,mode_compute=4); diff --git a/tests/practicing/sargent77ML.mod b/tests/practicing/sargent77ML.mod deleted file mode 100644 index ced989947..000000000 --- a/tests/practicing/sargent77ML.mod +++ /dev/null @@ -1,52 +0,0 @@ -// this program estimates the model in -// "The Demand for Money during Hyperinflations under Rational Expectations: I" by T. Sargent, IER 1977 using maximum likelihood -// variables are defined as follows: -// x=p_t-p_{t-1}, p being the log of the price level -// mu=m_t-m_{t-1}, m being the log of money supply -// note that in contrast to the paper eta and epsilon have variance 1 (they are multiplied by the standard deviations) - - - -var x mu a1 a2; -varexo epsilon eta; -parameters alpha lambda sig_eta sig_epsilon; -lambda=.5921; -alpha=-2.344; -sig_eta=.001; -sig_epsilon=.001; - -model; -x=x(-1)-lambda*a1(-1)+(1/(lambda+alpha*(1-lambda)))*sig_epsilon*epsilon-(1/(lambda+alpha*(1-lambda)))*sig_eta*eta; -mu=(1-lambda)*x(-1)+lambda*mu(-1)-lambda*a2(-1)+(1+alpha*(1-lambda))/(lambda+alpha*(1-lambda))*sig_epsilon*epsilon-(1-lambda)/(lambda+alpha*(1-lambda))*sig_eta*eta; -a1=(1/(lambda+alpha*(1-lambda)))*sig_epsilon*epsilon-(1/(lambda+alpha*(1-lambda)))*sig_eta*eta; -a2=(1+alpha*(1-lambda))/(lambda+alpha*(1-lambda))*sig_epsilon*epsilon-(1-lambda)/(lambda+alpha*(1-lambda))*sig_eta*eta; -end; - -steady; - -shocks; - -var eta; -stderr 1; -var epsilon; -stderr 1; -end; - - - - - - - -estimated_params; -// ML estimation setup -// parameter name, initial value, boundaries_low, ..._up; -lambda, .5, 0.25, 0.75; -alpha, -2, -8, -0.1; -sig_eta, .0001, 0.0001, 0.3; -sig_epsilon, .0001, 0.0001, 0.3; -end; - -varobs mu x; -unit_root_vars x; -estimation(datafile=cagan_data,first_obs=1,nobs=34,mh_replic=0,mode_compute=4,mode_check); \ No newline at end of file