Home > documentation > solmat.m

solmat

PURPOSE ^

SOLMAT.m

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

 SOLMAT.m

 Computes the RE solution of the model written in Dynare in CLOSED.MOD and
 checks that estimated shocks and parameters recover the data. This is a
 handy diagnostic.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % SOLMAT.m
0002 %
0003 % Computes the RE solution of the model written in Dynare in CLOSED.MOD and
0004 % checks that estimated shocks and parameters recover the data. This is a
0005 % handy diagnostic.
0006 
0007 %% Load Results from estimation
0008 load closed_results_01022011
0009 %load closed_results_03022011HighPsi
0010 usdata
0011 
0012 %% Options
0013 checkplots = 1; % Check solution through Smats.m
0014 dodecomposition = 1; % Decompose movement in observed series due to shocks
0015 checksum = 1; % Check that the decomposed movements add up to the observed series
0016 calibrated = 0; % If the model was calibrated, rather than estimated results loaded
0017 %% Load parameters at posterior mean and calibrated parameters
0018 beta = 0.99;
0019 psi = 0.1; % Change this for high psi
0020 omega = 0.0617;
0021 if calibrated % Ireland's calibration
0022 rho_a = 0.9470;
0023 rho_e = 0.9625;
0024 omega = 0.0617;
0025 rho_pi = 0.3597;
0026 rho_g = 0.2536;
0027 rho_x = 0.0347;
0028 ppi_ss=0.0086;
0029 g_ss=0.0048;
0030 else   
0031 rho_a = oo_.mle_mode.parameters.rho_a;%posterior_mode.parameters.rho_a;
0032 rho_e = oo_.mle_mode.parameters.rho_e;%oo_.posterior_mode.parameters.rho_e;
0033 %omega = oo_.posterior_mode.parameters.omega;
0034 rho_pi = oo_.mle_mode.parameters.rho_pi;%oo_.posterior_mode.parameters.rho_pi;
0035 rho_g = oo_.mle_mode.parameters.rho_g;%oo_.posterior_mode.parameters.rho_g;
0036 rho_x = oo_.mle_mode.parameters.rho_x;%oo_.posterior_mode.parameters.rho_x;
0037 ppi_ss=ppiss;
0038 g_ss=gss;
0039 end
0040 
0041 % Compute slope parameters
0042 ad_slope = -(1+rho_g+rho_x)/rho_pi;
0043 as_slope = psi;
0044 % Compute constants
0045 ad_constant = ppi_ss - ad_slope*g_ss;
0046 as_constant = ppi_ss - as_slope*g_ss;
0047 
0048 % Load Matrices in SMATS.m form
0049 % System given as
0050 %          GAM0*y(t)=GAM1*y(t-1)+C+PSI*e(t)+PPI*eta(t),
0051 %   with e(t) an exogenous variable process and eta(t) being endogenously determined
0052 %   one-step-ahead expectational errors.  Returned system is
0053 %         y(t)=S0 + S1*y(t-1)+S2*e(t)+S3*sunspot(t)  .
0054 %
0055 % variables are ordered as follows:
0056 %         1   2   3   4   5      6    7     8    9    10
0057 % y(t) = [a   e   z   x ppihat ghat  yhat  rhat  Etx  Etppi]'
0058 %
0059 %          1     2     3     4
0060 % e(t) = [eps_a eps_e eps_z eps_r]
0061 %
0062 % eta(t) [etax etappi]
0063 
0064 if checkplots
0065 nvars = 10;
0066 nshocks = 4;
0067 
0068 g0 = zeros(10);
0069 g0(1,1) = 1;
0070 g0(2,2) = 1;
0071 g0(3,3) = 1;
0072 g0(4,1) = -(1-omega)*(1-rho_a);
0073 g0(4,4) = 1;
0074 g0(4,8) = 1;
0075 g0(4,9) = -1;
0076 g0(4,10) = -1;
0077 g0(5,2) = 1;
0078 g0(5,4) = -psi;
0079 g0(5,5) = 1;
0080 g0(5,10) = -beta;
0081 g0(6,1) = omega;
0082 g0(6,4) = 1;
0083 g0(6,7) = -1;
0084 g0(7,3) = -1;
0085 g0(7,6) = 1;
0086 g0(7,7) = -1;
0087 g0(8,4) = -rho_x;
0088 g0(8,5) = -rho_pi;
0089 g0(8,6) = -rho_g;
0090 g0(8,8) = 1;
0091 g0(9,4) = 1;
0092 g0(10,5) = 1;
0093 
0094 g1 = zeros(nvars);
0095 g1(1,1) = rho_a;
0096 g1(2,2) = rho_e;
0097 g1(7,7) = -1;
0098 g1(8,8) = 1;
0099 g1(9,9) = 1;
0100 g1(10,10) = 1;
0101 
0102 PSI = zeros(nvars,nshocks);
0103 PSI(1,1) = 1;
0104 PSI(2,2) = 1;
0105 PSI(3,3) = 1;
0106 PSI(8,4) = 1;
0107 
0108 PPI = zeros(nvars,2);
0109 PPI(9,1) = 1;
0110 PPI(10,2) = 1;
0111 
0112 C0 = zeros(nvars,1);
0113 
0114 % Compute solution
0115 
0116 [S0, S1, S2, S3, unique] = Smats(C0, g0, g1, PSI, PPI);
0117 end
0118 %% Put estimated shocks trough solution
0119 % See Larry Christiano's comment on Smoothed Shocks
0120 % http://www.cepremap.cnrs.fr/juillard/mambo/index.php?option=com_forum&Itemid=95&page=viewtopic&t=1381
0121 T = max(size(ghat));
0122 
0123 if calibrated == 0
0124 eps_a = oo_.SmoothedShocks.eps_a;
0125 eps_e = oo_.SmoothedShocks.eps_e;
0126 eps_z = oo_.SmoothedShocks.eps_z;
0127 eps_r = oo_.SmoothedShocks.eps_r;
0128 
0129 eps_vec = [eps_a(1:end) eps_e(1:end) eps_z(1:end) eps_r(1:end)]';  
0130 CC=corrcoef(eps_vec');
0131 
0132 y_smats = zeros(nvars,T);
0133 y_smats(:,1) = [oo_.SmoothedVariables.a(1);
0134                 oo_.SmoothedVariables.e(1);
0135                 oo_.SmoothedVariables.z(1);
0136                 oo_.SmoothedVariables.x(1);
0137                 oo_.SmoothedVariables.ppihat(1);
0138                 oo_.SmoothedVariables.ghat(1);
0139                 oo_.SmoothedVariables.yhat(1);
0140                 oo_.SmoothedVariables.rhat(1);
0141                 oo_.SmoothedVariables.Ex(1);
0142                 oo_.SmoothedVariables.Eppihat(1)];
0143             
0144 % Extract demand and supply shifters
0145 ast = oo_.SmoothedVariables.ast + as_constant;
0146 adt = oo_.SmoothedVariables.adt + ad_constant;
0147 
0148 for t = 2:T;
0149     y_smats(:,t) = S1*y_smats(:,t-1)+S2*eps_vec(:,t);
0150 end
0151 end
0152 %% Compute AS and AD curves
0153 samplesize = max(size(ghat));
0154 gmin = -.02;
0155 gmax = .02;
0156 step = .0005;
0157 gvec = gmin:step:gmax;
0158 [rows cols] = size(gvec); 
0159 % Create tensors to store demand and supply curves
0160 ppi_ad = zeros(rows,cols,samplesize);
0161 ppi_as = zeros(rows,cols,samplesize);
0162 
0163 % for t = 1:samplesize
0164 %     ppi_ad(:,:,t) = ad(gvec,ad_slope,adt(t));
0165 %     ppi_as(:,:,t) = as(gvec,as_slope,ast(t));
0166 % end
0167 
0168 %% Compute steady state vectors (for ASADPLOT.M)
0169 g_ssvec = g_ss*ones(rows,cols);
0170 ppi_ssvec = ppi_ss*ones(rows,cols);
0171 
0172 %% The following plots check that the estimated shocks and parameters
0173 %  recover the data. Set checkplots = 0 to avoid them.
0174 time = 1:T;
0175 
0176 if checkplots
0177 figure(1)
0178 plot(time,y_smats(5,:),'b',time,ppihat,'r'), title('Inflation')
0179 figure(2)
0180 plot(time,y_smats(6,:),'b',time,ghat,'r'), title('Growth')
0181 figure(3)
0182 plot(time,y_smats(8,:),'b',time,rhat,'r'), title('Interest Rate')
0183 end
0184 
0185 if dodecomposition
0186 % Only demand shocks
0187 y_eps_a = zeros(nvars,T);
0188 y_eps_a(:,1) = y_smats(:,1)/4;
0189 eps_a_vec = [eps_a(1:end) 0*eps_e(1:end) 0*eps_z(1:end) 0*eps_r(1:end)]';  
0190 for t = 2:T;
0191     y_eps_a(:,t) = S1*y_eps_a(:,t-1)+S2*eps_a_vec(:,t);
0192 end
0193 % Only cost-push shocks
0194 y_eps_e = zeros(nvars,T);
0195 y_eps_e(:,1) = y_smats(:,1)/4;
0196 eps_e_vec = [0*eps_a(1:end) eps_e(1:end) 0*eps_z(1:end) 0*eps_r(1:end)]';  
0197 for t = 2:T;
0198     y_eps_e(:,t) = S1*y_eps_e(:,t-1)+S2*eps_e_vec(:,t);
0199 end
0200 % Only tech shocks
0201 y_eps_z = zeros(nvars,T);
0202 y_eps_z(:,1) = y_smats(:,1)/4;
0203 eps_z_vec = [0*eps_a(1:end) 0*eps_e(1:end) eps_z(1:end) 0*eps_r(1:end)]';  
0204 for t = 2:T;
0205     y_eps_z(:,t) = S1*y_eps_z(:,t-1)+S2*eps_z_vec(:,t);
0206 end
0207 % Only policy shocks
0208 y_eps_r = zeros(nvars,T);
0209 y_eps_r(:,1) = y_smats(:,1)/4;
0210 eps_r_vec = [0*eps_a(1:end) 0*eps_e(1:end) 0*eps_z(1:end) eps_r(1:end)]';  
0211 for t = 2:T;
0212     y_eps_r(:,t) = S1*y_eps_r(:,t-1)+S2*eps_r_vec(:,t);
0213 end
0214 figure(1)
0215 subplot(3,1,1),plot(time,y_eps_a(5,:),'b',time,ppihat,'r'), legend('\epsilon_a only','data'), title('Inflation')
0216 subplot(3,1,2),plot(time,y_eps_a(6,:),'b',time,ghat,'r'), legend('\epsilon_a only','data'), title('Growth')
0217 subplot(3,1,3),plot(time,y_eps_a(8,:),'b',time,rhat,'r'), legend('\epsilon_a only','data'), title('Interest Rate')
0218 figure(2)
0219 subplot(3,1,1),plot(time,y_eps_e(5,:),'b',time,ppihat,'r'), legend('\epsilon_e only','data'), title('Inflation')
0220 subplot(3,1,2),plot(time,y_eps_e(6,:),'b',time,ghat,'r'), legend('\epsilon_e only','data'), title('Growth')
0221 subplot(3,1,3),plot(time,y_eps_e(8,:),'b',time,rhat,'r'), legend('\epsilon_e only','data'), title('Interest Rate')
0222 figure(3)
0223 subplot(3,1,1),plot(time,y_eps_z(5,:),'b',time,ppihat,'r'), legend('\epsilon_z only','data'), title('Inflation')
0224 subplot(3,1,2),plot(time,y_eps_z(6,:),'b',time,ghat,'r'), legend('\epsilon_z only','data'), title('Growth')
0225 subplot(3,1,3),plot(time,y_eps_z(8,:),'b',time,rhat,'r'), legend('\epsilon_z only','data'), title('Interest Rate')
0226 figure(4)
0227 subplot(3,1,1),plot(time,y_eps_r(5,:),'b',time,ppihat,'r'), legend('\epsilon_r only','data'), title('Inflation')
0228 subplot(3,1,2),plot(time,y_eps_r(6,:),'b',time,ghat,'r'), legend('\epsilon_r only','data'), title('Growth')
0229 subplot(3,1,3),plot(time,y_eps_r(8,:),'b',time,rhat,'r'), legend('\epsilon_r only','data'), title('Interest Rate')
0230 end
0231 
0232 %% Check decompositions add to data
0233 if checksum
0234 ysum = y_eps_a + y_eps_e + y_eps_r + y_eps_z;
0235 figure(5)
0236 plot(time,ysum(5,:),'b',time,ppihat,'r'), title('Inflation')
0237 figure(6)
0238 plot(time,ysum(6,:),'b',time,ghat,'r'), title('Growth')
0239 figure(7)
0240 plot(time,ysum(8,:),'b',time,rhat,'r'), title('Interest Rate')
0241 end
0242 
0243 
0244 
0245 
0246 
0247 
0248

Generated on Mon 07-Feb-2011 12:06:56 by m2html © 2005