0001 function model_diagnostics(M_,options_,oo_)
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
0032
0033
0034
0035
0036 global jacob
0037
0038 endo_nbr = M_.endo_nbr;
0039 endo_names = M_.endo_names;
0040 lead_lag_incidence = M_.lead_lag_incidence;
0041 maximum_lag = M_.maximum_lag;
0042 maximum_lead = M_.maximum_lead;
0043
0044
0045
0046
0047 k = find(lead_lag_incidence(maximum_lag+1,:)==0);
0048 if ~isempty(k)
0049 disp(['The following endogenous variables aren''t present at ' ...
0050 'the current period in the model:'])
0051 for i=1:length(k)
0052 disp(endo_names(k(i),:))
0053 end
0054 end
0055
0056
0057
0058
0059 info = 0;
0060
0061 it_ = M_.maximum_lag + 1 ;
0062
0063 if M_.exo_nbr == 0
0064 oo_.exo_steady_state = [] ;
0065 end
0066
0067
0068 tempex = oo_.exo_simul;
0069 oo_.exo_simul = repmat(oo_.exo_steady_state',M_.maximum_lag+M_.maximum_lead+1,1);
0070 if M_.exo_det_nbr > 0
0071 tempexdet = oo_.exo_det_simul;
0072 oo_.exo_det_simul = repmat(oo_.exo_det_steady_state',M_.maximum_lag+M_.maximum_lead+1,1);
0073 end
0074 dr.ys = oo_.steady_state;
0075 check1 = 0;
0076
0077 fh = str2func([M_.fname '_static']);
0078 if options_.steadystate_flag
0079 [ys,check1] = feval([M_.fname '_steadystate'],dr.ys,...
0080 [oo_.exo_steady_state; oo_.exo_det_steady_state]);
0081 M_.params = evalin('base','M_.params;');
0082 if size(ys,1) < M_.endo_nbr
0083 if length(M_.aux_vars) > 0
0084 ys = add_auxiliary_variables_to_steadystate(ys,M_.aux_vars,...
0085 M_.fname,...
0086 oo_.exo_steady_state,...
0087 oo_.exo_det_steady_state,...
0088 M_.params,...
0089 options_.bytecode);
0090 else
0091 error([M_.fname '_steadystate.m doesn''t match the model']);
0092 end
0093 end
0094 dr.ys = ys;
0095 else
0096
0097 if options_.ramsey_policy == 0
0098 if options_.linear == 0
0099
0100 if max(abs(feval(fh,dr.ys,[oo_.exo_steady_state; ...
0101 oo_.exo_det_steady_state], M_.params))) > options_.dynatol.f
0102 [ys,check1] = dynare_solve(fh,dr.ys,1,...
0103 [oo_.exo_steady_state; ...
0104 oo_.exo_det_steady_state], ...
0105 M_.params);
0106 if ~check1
0107 dr.ys = ys;
0108 end
0109 end
0110 else
0111
0112 [fvec,jacob] = feval(fh,dr.ys,[oo_.exo_steady_state;...
0113 oo_.exo_det_steady_state], M_.params);
0114 if max(abs(fvec)) > 1e-12
0115 dr.ys = dr.ys-jacob\fvec;
0116 end
0117 end
0118 end
0119 end
0120
0121 if check1
0122 disp('model diagnostic can''t obtain the steady state')
0123 end
0124
0125 if ~isreal(dr.ys)
0126 disp(['model diagnostic obtains a steady state with complex ' ...
0127 'numbers'])
0128 return
0129 end
0130
0131
0132
0133
0134
0135 [res,jacob]=feval(fh,dr.ys,[oo_.exo_steady_state; oo_.exo_det_steady_state], ...
0136 M_.params);
0137 rank_jacob = rank(jacob);
0138 if rank_jacob < endo_nbr
0139 disp(['model_diagnostic: the Jacobian of the static model is ' ...
0140 'singular'])
0141 disp(['there is ' num2str(endo_nbr-rank_jacob) ...
0142 ' colinear relationships between the variables and the equations'])
0143 ncol = null(jacob);
0144 n_rel = size(ncol,2);
0145 for i = 1:n_rel
0146 if n_rel > 1
0147 disp(['Relation ' int2str(i)])
0148 end
0149 disp('Colinear variables:')
0150 for j=1:10
0151 k = find(abs(ncol(:,i)) > 10^-j);
0152 if max(abs(jacob(:,k)*ncol(k,i))) < 1e-6
0153 break
0154 end
0155 end
0156 disp(endo_names(k,:))
0157 end
0158 neq = null(jacob');
0159 n_rel = size(neq,2);
0160 for i = 1:n_rel
0161 if n_rel > 1
0162 disp(['Relation ' int2str(i)])
0163 end
0164 disp('Colinear equations')
0165 for j=1:10
0166 k = find(abs(neq(:,i)) > 10^-j);
0167 if max(abs(jacob(k,:)'*neq(k,i))) < 1e-6
0168 break
0169 end
0170 end
0171 disp(k')
0172 end
0173 end
0174