%*********************************************************************
%  Program        : IP_UNC.m
%  Description    : Plot the time series of total uncertainty (UNC),
%                   macro uncertainty (UNCma), and micro uncertainty
%                   (UNCmi) against the annual log industrial
%                   production (IP) growth (Figure 1 of the paper).
%                   The series are computed from the Christiano and
%                   Fitzgerald (2003) band-pass filter (see
%                   Table1\1.Timeseriescorrelation.do) and
%                   standardized. The shaded areas are NBER recession
%                   periods.
%
%  Input : Figure1\ ip_z.csv (standardized filtered series,
%          1972-2016: tfp_cf = UNC, hat_cf = UNCma, res_cf = UNCmi,
%          ipgrowth_ma12 = IP growth, recession = NBER indicator)
%  Output: IP.eps (Figure 1)
%*********************************************************************
diary F1.IP_UNC.txt
%%1.Import data
clear;
projpath = 'D:\SAS\TFP\Dispersion_replication';
data = csvread(fullfile(projpath,'Figure1','ip_z.csv'),1,0);
%
year = data(1:end,1);
tfpd = data(1:end,2);
hatd = data(1:end,3);
resd = data(1:end,4);
IP   = data(1:end,5);
rec  = data(1:end,6);
%%2. Set recession from NBER recession.
rec1=1973;
rec2=1974;
rec3=1975;
rec4=1980;
rec5=1981;
rec6=1982;
rec7=1990;
rec8=1991;
rec9=2001;
rec12=2007;
rec10=2008;
rec11=2009;
% 3.Uncertainty measures against IP growth
figure;
left_color = [0 0 0];
right_color = [0 0 0];
set(figure,'defaultAxesColorOrder',[left_color; right_color]);
p1=patch([2000.5 2001.5 2001.5 2000.5], [-3.5 -3.5 3.5 3.5],[0.75,0.75,0.75]);
set(p1,'edgecolor','none');
p2=patch([1972.5 1975.5 1975.5 1972.5],[-3.5 -3.5 3.5 3.5],[0.75,0.75,0.75]);
set(p2,'edgecolor','none');
p3=patch([1979.5 1982.5 1982.5 1979.5],[-3.5 -3.5 3.5 3.5],[0.75,0.75,0.75]);
set(p3,'edgecolor','none');
p4=patch([1989.5 1991.5 1991.5 1989.5],[-3.5 -3.5 3.5 3.5],[0.75,0.75,0.75]);
set(p4,'edgecolor','none');
p5=patch([2006.5 2009.5 2009.5 2006.5],[-3.5 -3.5 3.5 3.5],[0.75,0.75,0.75]);
set(p5,'edgecolor','none');
hold on;
yyaxis left
p1=plot(year,tfpd,'b','LineWidth',2);
hold on;
yyaxis left
p2=plot(year,hatd,'r--','LineWidth',2);
hold on;
yyaxis left
p3=plot(year,resd,'g:','LineWidth',2);
hold on;
yyaxis left
p4=plot(year,IP,'k-.','LineWidth',2);
hold on;
legend([p1 p2 p3 p4],{'UNC','UNC^{ma}','UNC^{mi}','IP'},'location','southoutside','NumColumns',4)
xlabel('Year');
axis tight;

print -depsc IP.eps
diary off