Home > matlab > name2index.m

name2index

PURPOSE ^

Returns the index associated to an estimated object (deep parameter,

SYNOPSIS ^

function i = name2index(options_, M_, estim_params_, type, name1, name2 )

DESCRIPTION ^

 Returns the index associated to an estimated object (deep parameter,
 variance of a structural shock or measurement error, covariance between
 two structural shocks, covariance between two measurement errors).
  
 INPUTS:
   options_        [structure]    Dynare structure.
   M_              [structure]    Dynare structure (related to model definition).
   estim_params_   [structure]    Dynare structure (related to estimation).
   type            [string]       'DeepParameter', 'MeasurementError' (for measurement equation error) or 'StructuralShock' (for structural shock).
   name1           [string]       
   name2           [string]    
 OUTPUTS
   i               [integer]      column index (in x2, an array of mh draws) associated to name1[,name2].

 SPECIAL REQUIREMENTS
   none

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function i = name2index(options_, M_, estim_params_, type, name1, name2 )
0002 % Returns the index associated to an estimated object (deep parameter,
0003 % variance of a structural shock or measurement error, covariance between
0004 % two structural shocks, covariance between two measurement errors).
0005 %
0006 % INPUTS:
0007 %   options_        [structure]    Dynare structure.
0008 %   M_              [structure]    Dynare structure (related to model definition).
0009 %   estim_params_   [structure]    Dynare structure (related to estimation).
0010 %   type            [string]       'DeepParameter', 'MeasurementError' (for measurement equation error) or 'StructuralShock' (for structural shock).
0011 %   name1           [string]
0012 %   name2           [string]
0013 % OUTPUTS
0014 %   i               [integer]      column index (in x2, an array of mh draws) associated to name1[,name2].
0015 %
0016 % SPECIAL REQUIREMENTS
0017 %   none
0018 
0019 % Copyright (C) 2008-2010 Dynare Team
0020 %
0021 % This file is part of Dynare.
0022 %
0023 % Dynare is free software: you can redistribute it and/or modify
0024 % it under the terms of the GNU General Public License as published by
0025 % the Free Software Foundation, either version 3 of the License, or
0026 % (at your option) any later version.
0027 %
0028 % Dynare is distributed in the hope that it will be useful,
0029 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0030 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0031 % GNU General Public License for more details.
0032 %
0033 % You should have received a copy of the GNU General Public License
0034 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0035 
0036 nvx     = estim_params_.nvx;
0037 nvn     = estim_params_.nvn;
0038 ncx     = estim_params_.ncx;
0039 ncn     = estim_params_.ncn;
0040 npa     = estim_params_.np ;
0041 nnn = nvx+nvn+ncx+ncn+npa;
0042 
0043 i = [];
0044 
0045 if strcmpi(type,'DeepParameter')
0046     i = nvx + nvn + ncx + ncn + ...
0047         strmatch(name1,M_.param_names(estim_params_.param_vals(:,1),:),'exact');
0048     if nargin>5
0049         disp('The last input argument is useless!')
0050     end
0051     if isempty(i)
0052         disp([name1 ' is not an estimated deep parameter!'])
0053     end
0054     return
0055 end
0056 
0057 if strcmpi(type,'StructuralShock')
0058     if nargin<6% Covariance matrix diagonal term.
0059         i = strmatch(name1,M_.exo_names(estim_params_.var_exo(:,1),:),'exact');
0060         if isempty(i)
0061             disp(['The standard deviation of ' name1  ' is not an estimated parameter!'])
0062             return
0063         end
0064     else% Covariance matrix off-diagonal term
0065         offset = nvx+nvn;
0066         try 
0067             list_of_structural_shocks = [ M_.exo_names(estim_params_.corrx(:,1),:) , M_.exo_names(estim_params_.corrx(:,2),:) ];
0068             k1 = strmatch(name1,list_of_structural_shocks(:,1),'exact');
0069             k2 = strmatch(name2,list_of_structural_shocks(:,2),'exact');
0070             i = offset+intersect(k1,k2);
0071             if isempty(i)
0072                 k1 = strmatch(name1,list_of_structural_shocks(:,2),'exact');
0073                 k2 = strmatch(name2,list_of_structural_shocks(:,1),'exact');
0074                 i = offset+intersect(k1,k2);
0075             end
0076             if isempty(i)
0077                 if isempty(i)
0078                     disp(['The correlation between' name1 ' and ' name2 ' is not an estimated parameter!'])
0079                     return
0080                 end
0081             end
0082         catch
0083             disp(['Off diagonal terms of the covariance matrix are not estimated (state equation)'])
0084         end
0085     end
0086 end
0087 
0088 if strcmpi(type,'MeasurementError')
0089     if nargin<6% Covariance matrix diagonal term
0090         i = nvx + strmatch(name1,M_.endo_names(estim_params_.var_endo(:,1),:),'exact');
0091         if isempty(i)
0092             disp(['The standard deviation of the measurement error on ' name1  ' is not an estimated parameter!'])
0093             return
0094         end
0095     else% Covariance matrix off-diagonal term
0096         offset = nvx+nvn+ncx;
0097         try
0098             list_of_measurement_errors = [ M_.endo_names(estim_params_.corrn(:,1),:) , M_.endo_names(estim_params_.corrn(:,2),:) ];
0099             k1 = strmatch(name1,list_of_measurement_errors(:,1),'exact');
0100             k2 = strmatch(name2,list_of_measurement_errors(:,2),'exact');
0101             i = offset+intersect(k1,k2);
0102             if isempty(i)
0103                 k1 = strmatch(name1,list_of_measurement_errors(:,2),'exact');
0104                 k2 = strmatch(name2,list_of_measurement_errors(:,1),'exact');
0105                 i = offset+intersect(k1,k2);
0106             end
0107             if isempty(i)
0108                 if isempty(i)
0109                     disp(['The correlation between the measurement errors on ' name1 ' and ' name2 ' is not an estimated parameter!'])
0110                     return
0111                 end
0112             end
0113         catch
0114             disp('Off diagonal terms of the covariance matrix are not estimated (measurement equation)')
0115         end
0116     end
0117 end

Generated on Tue 22-May-2012 02:40:23 by m2html © 2005