%
% Load in raw data from Bureau of Economic Analysis (BEA) and
% the Bureau of Labor Statistics (BLS) and plot time series in
% Figure 1 of "A Reassessment of Real Business Cycle Theory,"
% by Ellen McGrattan and Ed Prescott
%

load aearaw.dat
dgdp         = aearaw(:,1);  % BEA, NIPA Table 1.1.9 
pop          = aearaw(:,2);  % BLS, Civilian noninstitutional population,
                             %      16-64 +Military personnel worldwide
xpfixe334    = aearaw(:,3);  % BEA, Fixed asset tables 3.7
xpfixs334    = aearaw(:,4);
xpfixi334    = aearaw(:,5);
xpfixesi334  = aearaw(:,6);
xpfixe51     = aearaw(:,7);
xpfixs51     = aearaw(:,8);
xpfixi51     = aearaw(:,9);
xpfixesi51   = aearaw(:,10);

t            = [1972:2012]';
t07          = find(t==2007);
gz           = 0.019;
grate        = (1+gz).^[0:t(length(t))-t(1)]';
trend        = (dgdp.*grate.*pop);

x334e        = xpfixe334./trend * trend(t07)/xpfixesi334(t07) *100;
x334s        = xpfixs334./trend * trend(t07)/xpfixesi334(t07) *100;
x334i        = xpfixi334./trend * trend(t07)/xpfixesi334(t07) *100;
x51e         = xpfixe51 ./trend * trend(t07)/xpfixesi51(t07)  *100;
x51s         = xpfixs51 ./trend * trend(t07)/xpfixesi51(t07)  *100;
x51i         = xpfixi51 ./trend * trend(t07)/xpfixesi51(t07)  *100;

figure(1)
plot(t,[x334i,x334e,x334s])
title('Figure 1A. Private Fixed Investments, NAICS 334')
legend('Intellectual Property','Equipment','Structures', ...
       'Location','NorthWest')

figure(2)
plot(t,[x51i,x51e,x51s])
title('Figure 1B. Private Fixed Investments, NAICS 51')
legend('Intellectual Property','Equipment','Structures', ...
       'Location','NorthWest')
