%  plot_ir_mxn_data.m  
% Plot impulse responses  to  terms-of-trade shocks predicted   by a 7-variable  SVAR and  the MXN model with spreads.  The plots also include 66-percent confidence bnads computed by bootstrapping implied by the SAVER model. 
% The SVAR and MXN models are  developed in  the paper  ``How Important Are Terms of Trade Shocks?,'' by Stephanie Schmitt-Grohé and Martín Uribe,  International Economic Review, 2017. 
% © Martín Uribe and Stephanie Schmitt-Grohé, May 2015.


clear all,clc, clf
orient tall

load sgu_tot_run_baaff.mat  hx  PI country_name  IR IRs ncou
%produced by running 
%sgu_tot_run_baaff.m 

load bootstrap_ir_baaff.mat IR1 IR2 IRs1 IRs2
%produced by running 
%bootstrap_ir_baaff.m 

%pick variables in IR's
vir =[3:7];


 


T = size(IR,1);
t = (0:T-1)';
nv = size(IR,2);
nrow = 4;
ncol = 2;
varname ={'Terms of Trade','Spread', 'Trade Balance', 'Output', 'Consumption', 'Investment', 'Real Exchange Rate'};


load mxn_var_ir.mat IR_mxn 
%produced by running mxn_var_ir.m 

median_IR_model = 10*median(IR_mxn,3); 
median_IR_data = 10*median(IR,3); 

%Plot median IR for model and median IR for data

for j=1:nv
subplot(nrow,ncol,j)
plot(t,median_IR_data(:,j),'-',t,median_IR_model(:,j),'-o')
title(varname{j})
end %for j=1:nv
shg 

disp('Pausing. Press any key to see country-specific impulse responses')

pause 





%Country by Country Plots
for i=1:ncou
mIR = 10*IR(:,:,i);
mIR1 = 10*IR1(:,:,i);
mIR2 = 10*IR2(:,:,i);
mIR_mxn = 10*IR_mxn(:,:,i);

for j=1:nv
subplot(nrow,ncol,j)
plot(t,mIR(:,j),'-', t,mIR1(:,j),'--', t,mIR2(:,j),'--',t,mIR_mxn(:,j),'-o')
title(varname{j})
end %for j=1:nv
shg

end