0001 function dynare_estimation(var_list,dname)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 global options_ oo_ M_ oo_recursive_
0032
0033
0034 if ~isempty(strmatch('dsge_prior_weight',M_.param_names))
0035 options_.dsge_var = 1;
0036 end
0037
0038 var_list = check_list_of_variables(options_, M_, var_list);
0039 options_.varlist = var_list;
0040
0041 if isfield(options_,'nobs')
0042 nobs = options_.nobs;
0043 else
0044 nobs = [];
0045 end
0046
0047 nnobs = length(nobs);
0048 horizon = options_.forecast;
0049
0050 if nargin<2 || ~exist(dname) || isempty(dname)
0051 dname = M_.fname;
0052 end
0053
0054 M_.dname = dname;
0055
0056 if options_.mode_compute && options_.analytic_derivation,
0057 analytic_derivation0=options_.analytic_derivation;
0058 options_.analytic_derivation=1;
0059 end
0060
0061
0062 if nnobs > 1
0063 for i=1:nnobs
0064 options_.nobs = nobs(i);
0065 M_.dname = [dname '_' int2str(nobs(i))];
0066 dynare_estimation_1(var_list,M_.dname);
0067 oo_recursive_{nobs(i)} = oo_;
0068 end
0069 else
0070 dynare_estimation_1(var_list,dname);
0071 end
0072
0073 if options_.mode_compute && options_.analytic_derivation,
0074 options_.analytic_derivation=analytic_derivation0;
0075 end
0076
0077 if nnobs > 1 && horizon > 0
0078 mh_replic = options_.mh_replic;
0079 rawdata = read_variables(options_.datafile,options_.varobs,[],options_.xls_sheet,options_.xls_range);
0080 gend = options_.nobs;
0081 rawdata = rawdata(options_.first_obs:options_.first_obs+gend-1,:);
0082
0083 if options_.loglinear && ~options_.logdata
0084 rawdata = log(rawdata);
0085 end
0086
0087 endo_names = M_.endo_names;
0088 n_varobs = size(options_.varobs,1);
0089
0090 if isempty(var_list)
0091 var_list = endo_names;
0092 nvar = size(endo_names,1);
0093 SelecVariables = transpose(1:nvar);
0094 else
0095 nvar = size(var_list,1);
0096 SelecVariables = [];
0097 for i=1:nvar
0098 if ~isempty(strmatch(var_list(i,:),endo_names,'exact'))
0099 SelecVariables = [SelecVariables;strmatch(var_list(i,:),endo_names, ...
0100 'exact')];
0101 else
0102 error(['Estimation: ' var_list(i,:) ' isn''t an endogenous' ...
0103 'variable'])
0104 end
0105 end
0106 end
0107
0108 IdObs = zeros(n_varobs,1);
0109 for j=1:n_varobs
0110 for i=1:nvar
0111 iobs = strmatch(options_.varobs(j,:),var_list,'exact');
0112 end
0113 if ~isempty(iobs)
0114 IdObs(j,1) = iobs;
0115 end
0116 end
0117
0118 k = 3+min(nobs(end)-nobs(1)+horizon, ...
0119 size(rawdata,1)-nobs(1));
0120 data2 = rawdata(end-k+1:end,:);
0121 [nbplt,nr,nc,lr,lc,nstar] = pltorg(nvar);
0122 m = 1;
0123 for i = 1:size(var_list,1)
0124 if mod(i,nstar) == 1
0125 hfig = dyn_figure(options_,'Name','Out of sample forecasts');
0126 m = 1;
0127 end
0128 subplot(nr,nc,m)
0129 hold on
0130 if any(i==IdObs)
0131 k2 = find(i==IdObs);
0132 if options_.loglinear == 1
0133 plot(1:k,exp(data2(end-k+1:end,k2))','-k','linewidth',2);
0134 else
0135 plot(1:k,data2(end-k+1:end,k2)','-k','linewidth',2);
0136 end
0137 offsetx = 3;
0138 else
0139 offsetx = 0;
0140 end
0141 vname = deblank(var_list(i,:));
0142 maxlag = M_.maximum_lag;
0143 for j=1:nnobs
0144 if mh_replic > 0
0145 eval(['oo_.RecursiveForecast.Mean.' vname '(j,:) =' ...
0146 'oo_recursive_{' int2str(nobs(j)) '}.MeanForecast.Mean.' ...
0147 vname '(maxlag+1:end);']);
0148 eval(['oo_.RecursiveForecast.HPDinf.' vname '(j,:) =' ...
0149 'oo_recursive_{' int2str(nobs(j)) '}.MeanForecast.HPDinf.' ...
0150 vname '(maxlag+1:end);']);
0151 eval(['oo_.RecursiveForecast.HPDsup.' vname '(j,:) =' ...
0152 'oo_recursive_{' int2str(nobs(j)) '}.MeanForecast.HPDsup.' ...
0153 vname '(maxlag+1:end);']);
0154 eval(['oo_.RecursiveForecast.HPDTotalinf.' vname '(j,:) =' ...
0155 'oo_recursive_{' int2str(nobs(j)) '}.PointForecast.HPDinf.' ...
0156 vname '(maxlag+1:end);']);
0157 eval(['oo_.RecursiveForecast.HPDTotalsup.' vname '(j,:) =' ...
0158 'oo_recursive_{' int2str(nobs(j)) '}.PointForecast.HPDsup.' ...
0159 vname '(maxlag+1:end);']);
0160 else
0161 eval(['oo_.RecursiveForecast.Mean.' vname '(j,:) =' ...
0162 'oo_recursive_{' int2str(nobs(j)) '}.forecast.Mean.' ...
0163 vname ';']);
0164 eval(['oo_.RecursiveForecast.HPDinf.' vname '(j,:) =' ...
0165 'oo_recursive_{' int2str(nobs(j)) '}.forecast.HPDinf.' ...
0166 vname ';']);
0167 eval(['oo_.RecursiveForecast.HPDsup.' vname '(j,:) =' ...
0168 'oo_recursive_{' int2str(nobs(j)) '}.forecast.HPDsup.' ...
0169 vname ';']);
0170 end
0171 x = offsetx+nobs(j)-nobs(1)+(1:horizon);
0172 y = eval(['oo_.RecursiveForecast.Mean.' vname '(j,:)']);
0173 y1 = eval(['oo_.RecursiveForecast.HPDinf.' vname '(j,:)']);
0174 y2 = eval(['oo_.RecursiveForecast.HPDsup.' vname '(j,:)']);
0175 plot(x,y,'-b','linewidth',2)
0176 plot(x,y1,'--g', ...
0177 'linewidth',1.5)
0178 plot(x,y2,'--g', ...
0179 'linewidth',1.5)
0180 if mh_replic
0181 y3 = eval(['oo_.RecursiveForecast.HPDTotalinf.' vname '(j,:)']);
0182 y4 = eval(['oo_.RecursiveForecast.HPDTotalsup.' vname ...
0183 '(j,:)']);
0184 plot(x,y3,'--r', ...
0185 'linewidth',1.5)
0186 plot(x,y4,'--r','linewidth',1.5)
0187 end
0188 end
0189
0190
0191
0192 if any(k==IdObs)
0193 plot([offsetx+1 offsetx+1],ylim,'-c')
0194 end
0195 box on
0196 title(vname,'Interpreter','none')
0197 hold off
0198 m = m + 1;
0199 end
0200 end