Home > matlab > dynare_estimation.m

dynare_estimation

PURPOSE ^

function dynare_estimation(var_list)

SYNOPSIS ^

function dynare_estimation(var_list,dname)

DESCRIPTION ^

 function dynare_estimation(var_list)
 runs the estimation of the model

 INPUTS
   var_list:  selected endogenous variables vector

 OUTPUTS
   none

 SPECIAL REQUIREMENTS
   none

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function dynare_estimation(var_list,dname)
0002 % function dynare_estimation(var_list)
0003 % runs the estimation of the model
0004 %
0005 % INPUTS
0006 %   var_list:  selected endogenous variables vector
0007 %
0008 % OUTPUTS
0009 %   none
0010 %
0011 % SPECIAL REQUIREMENTS
0012 %   none
0013 
0014 % Copyright (C) 2003-2011 Dynare Team
0015 %
0016 % This file is part of Dynare.
0017 %
0018 % Dynare is free software: you can redistribute it and/or modify
0019 % it under the terms of the GNU General Public License as published by
0020 % the Free Software Foundation, either version 3 of the License, or
0021 % (at your option) any later version.
0022 %
0023 % Dynare is distributed in the hope that it will be useful,
0024 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0025 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0026 % GNU General Public License for more details.
0027 %
0028 % You should have received a copy of the GNU General Public License
0029 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0030 
0031 global options_ oo_ M_ oo_recursive_
0032 
0033 %% Decide if a DSGE or DSGE-VAR has to be estimated.
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     % Take the log of the variables if needed
0083     if options_.loglinear && ~options_.logdata   % and if the data are not in logs, then...
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         %    set(gca,'XTick',offsetx+[1 10 20 30 40 50 60 70 80 90]);
0190         %    set(gca,'XTickLabel',{'1';'10';'20';'30';'40';'50';'60';'70';'80';'90'});
0191         %   xlim([1 options_.forecast+10]);
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

Generated on Mon 21-May-2012 02:42:43 by m2html © 2005