%PLOTS    Plot labor productivity for the total economy and the business 
%         sector.

%         Ellen McGrattan


load aggprdq.dat
load busprdq.dat

ia     = find(~isnan(sum(aggprdq')'));
ib     = find(~isnan(sum(busprdq')'));
agg    = aggprdq(ia,:);
bus    = busprdq(ib,:);
ta     = ptime(agg(1,1)+agg(1,2)/10,length(agg),4);
tb     = ptime(bus(1,1)+bus(1,2)/10,length(bus),4);

aprd   = agg(:,5)./agg(:,3);
bprd   = bus(:,5)./bus(:,3);
aout   = agg(:,5);
bout   = bus(:,5);

daout  = log(aout)-hptrend(log(aout),1600);
dbout  = log(bout)-hptrend(log(bout),1600);
daprd  = log(aprd)-hptrend(log(aprd),1600);
dbprd  = log(bprd)-hptrend(log(bprd),1600);

ta60   = find(ta==1960.125);
tb60   = find(tb==1960.125);
ta85   = find(ta==1985.625);
tb85   = find(tb==1985.625);
ta11   = find(ta==2011.625);
tb11   = find(tb==2011.625);
ca1    = corrcoef([daout(ta60:ta85),daprd(ta60:ta85)]);
cb1    = corrcoef([dbout(tb60:tb85),dbprd(tb60:tb85)]);
ca2    = corrcoef([daout(ta85:ta11),daprd(ta85:ta11)]);
cb2    = corrcoef([dbout(tb85:tb11),dbprd(tb85:tb11)]);

figure(1)
plot(ta,daout,ta,daprd,[1985,1985],[-.05,.05],'k:')
axis([1960,2011,-.05,.05])
title('Output and Productivity, Total Economy','Fontsize',16)
legend('Output','Labor Productivity')
ylabel('HP-filtered Series')
text(1965,-.045,['correlation = ',int2str(ca1(1,2)*100),'%'])
text(1990,-.045,['correlation = ',int2str(ca2(1,2)*100),'%'])

figure(2)
plot(tb,dbout,tb,dbprd,[1985,1985],[-.06,.06],'k:')
axis([1960,2011,-.06,.06])
title('Output and Productivity, Business Sector','Fontsize',16)
legend('Output','Labor Productivity')
ylabel('HP-filtered Series')
text(1965,-.055,['correlation = ',int2str(cb1(1,2)*100),'%'])
text(1990,-.055,['correlation = ',int2str(cb2(1,2)*100),'%'])
