Commit a2cef700 authored by sebastien's avatar sebastien
Browse files

Fixes for ticket #57

preprocessor:
* add a field "M_.orig_endo_nbr" containing the nbr of endogenous before adding aux vars
* always provide "M_.aux_vars" (define it to "[]" when there is no aux var)
* rename "M_.aux_vars().orig_endo_index" to "M_.aux_vars().orig_index"

M-files:
* for commands which accept a list of variables (stoch_simul, osr, estimation, dynasave, dynatype, datatomfile), when no variable is given, use only the set of original endogenous (without aux vars) as the default
* when displaying the decision rule, when there is aux vars in the state variables, replace them by their original name (with the right lag)
* in "steady", don't display aux vars
* special exception for ramsey policy: all vars (including aux vars) are displayed, because the system of aux vars from ramsey policy is not compatible with the aux vars from the preprocessor


git-svn-id: https://www.dynare.org/svn/dynare/trunk@3166 ac1d8469-bf42-47a9-8791-bf33cf982152
parent 6e8cc2e8
......@@ -5,7 +5,7 @@ function [omega,f] = UnivariateSpectralDensity(dr,var_list)
%
% Adapted from th_autocovariances.m.
% Copyright (C) 2006-2008 Dynare Team
% Copyright (C) 2006-2009 Dynare Team
%
% This file is part of Dynare.
%
......@@ -48,11 +48,10 @@ end
if nargin<2
var_list = [];
end
if size(var_list,1) == 0
var_list = M_.endo_names(1:M_.orig_endo_nbr, :);
end
nvar = size(var_list,1);
if nvar == 0
nvar = length(dr.order_var);
ivar = [1:nvar]';
else
ivar=zeros(nvar,1);
for i=1:nvar
i_tmp = strmatch(var_list(i,:),M_.endo_names,'exact');
......@@ -62,7 +61,6 @@ else
ivar(i) = i_tmp;
end
end
end
f = zeros(nvar,GridSize);
ghx = dr.ghx;
ghu = dr.ghu;
......
......@@ -25,7 +25,7 @@ function ys1 = add_auxiliary_variables_to_steadystate(ys,aux_vars,fname, ...
aux_lead_nbr = 0;
for i=1:n
if aux_vars(i).type == 1
ys1(k) = ys(aux_vars(i).orig_endo_index);
ys1(k) = ys(aux_vars(i).orig_index);
elseif aux_vars(i).type == 0
aux_lead_nbr = aux_lead_nbr + 1;
end
......
......@@ -115,7 +115,7 @@ function varlist = check_list_of_variables(options_, M_, varlist)
choice=1;
end
if choice==1
varlist = M_.endo_names;
varlist = M_.endo_names(1:M_.orig_endo_nbr, :);
elseif choice==2
varlist = options_.varobs;
elseif choice==3
......
function datatomfile (s,var_list)
% function datatomfile (s,var_list)
% This optional command saves the simulation results in a text file. The name of each
% variable preceeds the corresponding results. This command must follow SIMUL.
......@@ -14,7 +13,7 @@ function datatomfile (s,var_list)
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2001-2007 Dynare Team
% Copyright (C) 2001-2009 Dynare Team
%
% This file is part of Dynare.
%
......@@ -33,16 +32,13 @@ function datatomfile (s,var_list)
global M_ oo_
%fid=fopen([s,'.m'],'w') ;
sm=[s,'.m'];
fid=fopen(sm,'w') ;
if size(var_list,1) == 0
var_list = M_.endo_names(1:M_.orig_endo_nbr,:);
end
n = size(var_list,1);
if n == 0
n = M_.endo_nbr;
ivar = [1:n]';
var_list = M_.endo_names;
else
ivar=zeros(n,1);
for i=1:n
i_tmp = strmatch(var_list(i,:),M_.endo_names,'exact');
......@@ -52,7 +48,7 @@ else
ivar(i) = i_tmp;
end
end
end
for i = 1:n
......
function disp_dr(dr,order,var_list)
% Copyright (C) 2001 Dynare Team
% Display the decision rules
%
% INPUTS
% dr [struct]: decision rules
% order [int]: order of approximation
% var_list [char array]: list of endogenous variables for which the
% decision rules should be printed
% Copyright (C) 2001-2009 Dynare Team
%
% This file is part of Dynare.
%
......@@ -26,11 +33,12 @@ function disp_dr(dr,order,var_list)
k1 = dr.order_var;
if size(var_list,1) == 0
var_list = M_.endo_names(1:M_.orig_endo_nbr, :);
end
nvar = size(var_list,1);
if nvar == 0
nvar = length(k1);
ivar = [1:nvar];
else
ivar=zeros(nvar,1);
for i=1:nvar
i_tmp = strmatch(var_list(i,:),M_.endo_names(k1,:),'exact');
......@@ -41,7 +49,7 @@ function disp_dr(dr,order,var_list)
ivar(i) = i_tmp;
end
end
end
disp('POLICY AND TRANSITION FUNCTIONS')
% variable names
str = ' ';
......@@ -90,7 +98,7 @@ function disp_dr(dr,order,var_list)
%
for k=1:nx
flag = 0;
str1 = sprintf('%s(%d)',M_.endo_names(k1(klag(k,1)),:),klag(k,2)-M_.maximum_lag-2);
str1 = subst_auxvar(k1(klag(k,1)),klag(k,2)-M_.maximum_lag-2);
str = sprintf('%-20s',str1);
for i=1:nvar
x = dr.ghx(ivar(i),k);
......@@ -130,8 +138,8 @@ function disp_dr(dr,order,var_list)
for k = 1:nx
for j = 1:k
flag = 0;
str1 = sprintf('%s(%d),%s(%d)',M_.endo_names(k1(klag(k,1)),:),klag(k,2)-M_.maximum_lag-2, ...
M_.endo_names(k1(klag(j,1)),:),klag(j,2)-M_.maximum_lag-2);
str1 = sprintf('%s,%s',subst_auxvar(k1(klag(k,1)),klag(k,2)-M_.maximum_lag-2), ...
subst_auxvar(k1(klag(j,1)),klag(j,2)-M_.maximum_lag-2));
str = sprintf('%-20s',str1);
for i=1:nvar
if k == j
......@@ -182,7 +190,7 @@ function disp_dr(dr,order,var_list)
for k = 1:nx
for j = 1:nu
flag = 0;
str1 = sprintf('%s(%d),%s',M_.endo_names(k1(klag(k,1)),:),klag(k,2)-M_.maximum_lag-2, ...
str1 = sprintf('%s,%s',subst_auxvar(k1(klag(k,1)),klag(k,2)-M_.maximum_lag-2), ...
M_.exo_names(j,:));
str = sprintf('%-20s',str1);
for i=1:nvar
......@@ -200,17 +208,32 @@ function disp_dr(dr,order,var_list)
end
end
end
end
% $$$ dr.ghx
% $$$ dr.ghu
% $$$ dr.ghxx
% $$$ dr.ghuu
% $$$ dr.ghxu
% 01/08/2001 MJ added test for order in printing quadratic terms
% 02/21/2001 MJ pass all variable names through deblank()
% 02/21/2001 MJ changed from f to g format to write numbers
% 10/09/2002 MJ corrected error on constant whith subset of variables
% Given the index of an endogenous (possibly an auxiliary var), and a
% lead/lag, creates a string of the form "x(lag)".
% In the case of auxiliary vars for lags, replace by the original variable
% name, and compute the lead/lag accordingly.
function str = subst_auxvar(aux_index, aux_lead_lag)
global M_
if aux_index <= M_.orig_endo_nbr
str = sprintf('%s(%d)', deblank(M_.endo_names(aux_index,:)), aux_lead_lag);
return
end
for i = 1:length(M_.aux_vars)
if M_.aux_vars(i).endo_index == aux_index
switch M_.aux_vars(i).type
case 1
orig_name = deblank(M_.endo_names(M_.aux_vars(i).orig_index, :));
case 3
orig_name = deblank(M_.exo_names(M_.aux_vars(i).orig_index, :));
otherwise
error(sprintf('Invalid auxiliary type: %s', M_.endo_names(aux_index, :)))
end
str = sprintf('%s(%d)', orig_name, M_.aux_vars(i).orig_lead_lag+aux_lead_lag);
return
end
end
error(sprintf('Could not find aux var: %s', M_.endo_names(aux_index, :)))
end
function disp_dr_sparse(dr,order,var_list)
% Display the decision rules in sparse mode
% This file is a modified version of disp_dr.m: the common parts should be factorized!
%
% INPUTS
% dr [struct]: decision rules
% order [int]: order of approximation
% var_list [char array]: list of endogenous variables for which the
% decision rules should be printed
% Copyright (C) 2001 Dynare Team
% Copyright (C) 2001-2009 Dynare Team
%
% This file is part of Dynare.
%
......@@ -44,11 +52,13 @@ function disp_dr_sparse(dr,order,var_list)
klag = [klag ; M_.block_structure.block(i).dr.kstate(k_tmp,[1 2])];
k1 = [k1 ; M_.block_structure.block(i).variable(M_.block_structure.block(i).dr.order_var)'];
end
if size(var_list,1) == 0
var_list = M_.endo_names(1:M_.orig_endo_nbr, :);
end
nvar = size(var_list,1);
if nvar == 0
nvar = length(k1);
ivar = [1:nvar];
else
ivar=zeros(nvar,1);
for i=1:nvar
i_tmp = strmatch(var_list(i,:),M_.endo_names(k1,:),'exact');
......@@ -59,7 +69,7 @@ function disp_dr_sparse(dr,order,var_list)
ivar(i) = i_tmp;
end
end
end
disp('POLICY AND TRANSITION FUNCTIONS')
% variable names
str = ' ';
......@@ -108,7 +118,7 @@ function disp_dr_sparse(dr,order,var_list)
%
for k=1:nx
flag = 0;
str1 = sprintf('%s(%d)',M_.endo_names(k1(klag(k,1)),:),klag(k,2)-M_.maximum_lag-2);
str1 = subst_auxvar(k1(klag(k,1)),klag(k,2)-M_.maximum_lag-2);
str = sprintf('%-20s',str1);
for i=1:nvar
x = ghx(ivar(i),k);
......@@ -148,8 +158,8 @@ function disp_dr_sparse(dr,order,var_list)
for k = 1:nx
for j = 1:k
flag = 0;
str1 = sprintf('%s(%d),%s(%d)',M_.endo_names(k1(klag(k,1)),:),klag(k,2)-M_.maximum_lag-2, ...
M_.endo_names(k1(klag(j,1)),:),klag(j,2)-M_.maximum_lag-2);
str1 = sprintf('%s,%s',subst_auxvar(k1(klag(k,1)),klag(k,2)-M_.maximum_lag-2), ...
subst_auxvar(k1(klag(j,1)),klag(j,2)-M_.maximum_lag-2));
str = sprintf('%-20s',str1);
for i=1:nvar
if k == j
......@@ -200,7 +210,7 @@ function disp_dr_sparse(dr,order,var_list)
for k = 1:nx
for j = 1:nu
flag = 0;
str1 = sprintf('%s(%d),%s',M_.endo_names(k1(klag(k,1)),:),klag(k,2)-M_.maximum_lag-2, ...
str1 = sprintf('%s,%s',subst_auxvar(k1(klag(k,1)),klag(k,2)-M_.maximum_lag-2), ...
M_.exo_names(j,:));
str = sprintf('%-20s',str1);
for i=1:nvar
......@@ -218,17 +228,32 @@ function disp_dr_sparse(dr,order,var_list)
end
end
end
end
% $$$ dr.ghx
% $$$ dr.ghu
% $$$ dr.ghxx
% $$$ dr.ghuu
% $$$ dr.ghxu
% 01/08/2001 MJ added test for order in printing quadratic terms
% 02/21/2001 MJ pass all variable names through deblank()
% 02/21/2001 MJ changed from f to g format to write numbers
% 10/09/2002 MJ corrected error on constant whith subset of variables
% Given the index of an endogenous (possibly an auxiliary var), and a
% lead/lag, creates a string of the form "x(lag)".
% In the case of auxiliary vars for lags, replace by the original variable
% name, and compute the lead/lag accordingly.
function str = subst_auxvar(aux_index, aux_lead_lag)
global M_
if aux_index <= M_.orig_endo_nbr
str = sprintf('%s(%d)', deblank(M_.endo_names(aux_index,:)), aux_lead_lag);
return
end
for i = 1:length(M_.aux_vars)
if M_.aux_vars(i).endo_index == aux_index
switch M_.aux_vars(i).type
case 1
orig_name = deblank(M_.endo_names(M_.aux_vars(i).orig_index, :));
case 3
orig_name = deblank(M_.exo_names(M_.aux_vars(i).orig_index, :));
otherwise
error(sprintf('Invalid auxiliary type: %s', M_.endo_names(aux_index, :)))
end
str = sprintf('%s(%d)', orig_name, M_.aux_vars(i).orig_lead_lag+aux_lead_lag);
return
end
end
error(sprintf('Could not find aux var: %s', M_.endo_names(aux_index, :)))
end
function disp_moments(y,var_list)
% Displays moments of simulated variables
% Copyright (C) 2001-2008 Dynare Team
% Copyright (C) 2001-2009 Dynare Team
%
% This file is part of Dynare.
%
......@@ -21,11 +22,12 @@ function disp_moments(y,var_list)
warning_old_state = warning;
warning off
nvar = size(var_list,1);
if nvar == 0
nvar = M_.endo_nbr;
ivar = [1:nvar]';
else
if size(var_list,1) == 0
var_list = M_.endo_names(1:M_.orig_endo_nbr, :);
end
nvar = size(var_list,1);
ivar=zeros(nvar,1);
for i=1:nvar
i_tmp = strmatch(var_list(i,:),M_.endo_names,'exact');
......@@ -35,7 +37,7 @@ function disp_moments(y,var_list)
ivar(i) = i_tmp;
end
end
end
y = y(ivar,options_.drop+M_.maximum_lag+1:end)';
m = mean(y);
......@@ -90,10 +92,3 @@ function disp_moments(y,var_list)
end
warning(warning_old_state);
% 10/03/02 MJ corrected order std. dev var in printed report.
% 01/02/03 MJ added correlation and autocorrelation
% 01/19/03 MJ corrected variable name truncation
% 02/18/03 MJ added subtitle for HP filter
% 03/02/03 MJ added M_.maximum_lag to the number of entries of y
% 04/28/03 MJ modified handling of options_
% 06/23/03 MJ added warning off
function disp_th_moments(dr,var_list)
% Copyright (C) 2001-2008 Dynare Team
% Display theoretical moments of variables
% Copyright (C) 2001-2009 Dynare Team
%
% This file is part of Dynare.
%
......@@ -19,11 +20,10 @@ function disp_th_moments(dr,var_list)
global M_ oo_ options_
if size(var_list,1) == 0
var_list = M_.endo_names(1:M_.orig_endo_nbr, :);
end
nvar = size(var_list,1);
if nvar == 0
nvar = length(dr.order_var);
ivar = [1:nvar]';
else
ivar=zeros(nvar,1);
for i=1:nvar
i_tmp = strmatch(var_list(i,:),M_.endo_names,'exact');
......@@ -33,7 +33,6 @@ function disp_th_moments(dr,var_list)
ivar(i) = i_tmp;
end
end
end
[oo_.gamma_y,stationary_vars] = th_autocovariances(dr,ivar,M_,options_);
m = dr.ys(ivar);
......@@ -114,13 +113,3 @@ function disp_th_moments(dr,var_list)
lh = size(labels,2)+2;
dyntable(title,headers,labels,z,lh,8,4);
end
% 10/09/02 MJ
% 10/18/02 MJ added th_autocovariances() and provided for lags on several
% periods
% 10/30/02 MJ added correlations and autocorrelations, uses table()
% oo_.gamma_y is now a cell array.
% 02/18/03 MJ added subtitles for HP filter
% 05/01/03 MJ corrected options_.hp_filter
% 05/21/03 MJ variance decomposition: test M_.exo_nbr > 1
% 05/21/03 MJ displays only variables with positive variance
......@@ -67,6 +67,8 @@ function [dr,info,M_,options_,oo_] = dr1(dr,task,M_,options_,oo_)
if isfield(M_,'orig_model')
orig_model = M_.orig_model;
M_.endo_nbr = orig_model.endo_nbr;
M_.orig_endo_nbr = orig_model.orig_endo_nbr;
M_.aux_vars = orig_model.aux_vars;
M_.endo_names = orig_model.endo_names;
M_.lead_lag_incidence = orig_model.lead_lag_incidence;
M_.maximum_lead = orig_model.maximum_lead;
......
......@@ -71,6 +71,8 @@ function [dr,info,M_,options_,oo_] = dr1_sparse(dr,task,M_,options_,oo_)
if isfield(M_,'orig_model')
orig_model = M_.orig_model;
M_.endo_nbr = orig_model.endo_nbr;
M_.orig_endo_nbr = orig_model.orig_endo_nbr;
M_.aux_vars = orig_model.aux_vars;
M_.endo_names = orig_model.endo_names;
M_.lead_lag_incidence = orig_model.lead_lag_incidence;
M_.maximum_lead = orig_model.maximum_lead;
......
function [J,M_] = dyn_ramsey_dynamic_(ys,lbar,M_,options_,oo_,it_)
% function J = dyn_ramsey_dynamic_(ys,lbar)
% dyn_ramsey_dynamic_ sets up the Jacobian of the expanded model for optimal
% policies. It modifies several fields of M_
......@@ -14,7 +13,7 @@ function [J,M_] = dyn_ramsey_dynamic_(ys,lbar,M_,options_,oo_,it_)
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2003-2008 Dynare Team
% Copyright (C) 2003-2009 Dynare Team
%
% This file is part of Dynare.
%
......@@ -54,6 +53,8 @@ function [J,M_] = dyn_ramsey_dynamic_(ys,lbar,M_,options_,oo_,it_)
% storing original values
orig_model.endo_nbr = endo_nbr;
orig_model.orig_endo_nbr = M_.orig_endo_nbr;
orig_model.aux_vars = M_.aux_vars;
orig_model.endo_names = endo_names;
orig_model.lead_lag_incidence = i_leadlag;
orig_model.maximum_lead = max_lead;
......@@ -225,6 +226,10 @@ function [J,M_] = dyn_ramsey_dynamic_(ys,lbar,M_,options_,oo_,it_)
% setting expanded model parameters
% storing original values
M_.endo_nbr = endo_nbr1;
% Consider that there is no auxiliary variable, because otherwise it
% interacts badly with the auxiliary variables from the preprocessor.
M_.orig_endo_nbr = endo_nbr1;
M_.aux_vars = [];
M_.endo_names = endo_names1;
M_.lead_lag_incidence = i_leadlag1;
M_.maximum_lead = max_lead1;
......
......@@ -287,7 +287,7 @@ if options_.steadystate_flag% if the *_steadystate.m file is provided.
[zeros(M_.exo_nbr,1);...
oo_.exo_det_steady_state]);
if size(ys,1) < M_.endo_nbr
if isfield(M_,'aux_vars')
if length(M_.aux_vars) > 0
ys = add_auxiliary_variables_to_steadystate(ys,M_.aux_vars,...
M_.fname,...
zeros(M_.exo_nbr,1),...
......
function dynasave(s,var_list)
% function dynasave(s,var_list)
% This optional command saves the simulation results in a .MAT file.
%
......@@ -14,7 +12,7 @@ function dynasave(s,var_list)
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2001-2008 Dynare Team
% Copyright (C) 2001-2009 Dynare Team
%
% This file is part of Dynare.
%
......@@ -33,12 +31,11 @@ function dynasave(s,var_list)
global M_ oo_
if size(var_list,1) == 0
var_list = M_.endo_names(1:M_.orig_endo_nbr, :);
end
n = size(var_list,1);
if n == 0
n = M_.endo_nbr;
ivar = [1:n]';
var_list = M_.endo_names;
else
ivar=zeros(n,1);
for i=1:n
i_tmp = strmatch(var_list(i,:),M_.endo_names,'exact');
......@@ -48,8 +45,6 @@ function dynasave(s,var_list)
ivar(i) = i_tmp;
end
end
end
% dyn2vec(var_list(1),var_list(1));
eval([var_list(1) '=oo_.endo_simul(ivar(1),:)'';'])
......
......@@ -13,7 +13,7 @@ function dynatype (s,var_list)
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2001-2008 Dynare Team
% Copyright (C) 2001-2009 Dynare Team
%
% This file is part of Dynare.
%
......@@ -34,12 +34,11 @@ global M_ oo_
fid=fopen(s,'w') ;
if size(var_list,1) == 0
var_list = M_.endo_names(1:M_.orig_endo_nbr,:);
end
n = size(var_list,1);
if n == 0
n = M_.endo_nbr;
ivar = [1:n]';
var_list = M_.endo_names;
else
ivar=zeros(n,1);
for i=1:n
i_tmp = strmatch(var_list(i,:),M_.endo_names,'exact');
......@@ -49,8 +48,6 @@ else
ivar(i) = i_tmp;
end
end
end
for i = 1:n
fprintf(fid,M_.endo_names(ivar(i),:),'\n') ;
......
......@@ -110,7 +110,7 @@ function [llik,parameters] = evaluate_likelihood(parameters)
[zeros(M_.exo_nbr,1);...
oo_.exo_det_steady_state]);
if size(ys,1) < M_.endo_nbr
if isfield(M_,'aux_vars')
if length(M_.aux_vars) > 0
ys = add_auxiliary_variables_to_steadystate(ys,M_.aux_vars,...
M_.fname,...
zeros(M_.exo_nbr,1),...
......
function [yf,int_width]=forcst(dr,y0,horizon,var_list)
% function [yf,int_width]=forecst(dr,y0,horizon,var_list)
% computes mean forecast for a given value of the parameters
% computes also confidence band for the forecast
......@@ -18,7 +17,7 @@ function [yf,int_width]=forcst(dr,y0,horizon,var_list)
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2003-2008 Dynare Team
% Copyright (C) 2003-2009 Dynare Team
%
% This file is part of Dynare.
%
......@@ -46,11 +45,10 @@ function [yf,int_width]=forcst(dr,y0,horizon,var_list)
inv_order_var = dr.inv_order_var;
[A,B] = kalman_transition_matrix(dr,nstatic+(1:npred),1:nc,dr.transition_auxiliary_variables,M_.exo_nbr);
if size(var_list,1) == 0
var_list = M_.endo_names(1:M_.orig_endo_nbr,:);
end
nvar = size(var_list,1);
if nvar == 0
nvar = M_.endo_nbr;
ivar = [1:nvar];
else
ivar=zeros(nvar,1);
for i=1:nvar
i_tmp = strmatch(var_list(i,:),M_.endo_names,'exact');
......@@ -61,7 +59,6 @@ function [yf,int_width]=forcst(dr,y0,horizon,var_list)
ivar(i) = i_tmp;
end
end
end
ghx1 = dr.ghx(inv_order_var(ivar),:);
ghu1 = dr.ghu(inv_order_var(ivar),:);
......
......@@ -15,7 +15,7 @@ function forcst_unc(y0,var_list)
% SPECIAL REQUIREMENTS
% None.
% Copyright (C) 2006-2008 Dynare Team
% Copyright (C) 2006-2009 Dynare Team
%
% This file is part of Dynare.
%
......@@ -43,11 +43,10 @@ function forcst_unc(y0,var_list)
% workspace initialization
if isempty(var_list)
var_list = M_.endo_names;
n = M_.endo_nbr;
else