%SETUPDATA    Set up data file for maximum likelihood estimation
%             Store matrix `mled' in uszvarq_ur.dat called by the
%             mle routine.

%             Ellen McGrattan, 3-15-04
%             Revised, 9-13-04

load ../../data/BEA/NIPA/nipa115.csv
load ../../data/BEA/NIPA/nipa116.csv
load ../../data/BEA/NIPA/nipa119.csv
load ../../data/BEA/NIPA/nipa302.csv
load ../../data/BEA/NIPA/nipa303.csv
load ../../data/BEA/NIPA/nipa394.csv
load ../../data/BEA/NIPA/nipa395.csv
load ../../data/prescott/prescott.csv
load ../../data/literature/fr/ramey.dat
load ../../data/literature/cev/cev.dat
load ../../data/literature/gr/gali.csv

T     = 49:228;          % 1959:1-2003:4
rGDP  = nipa116(3,T)';
nSTX  = nipa302(6,T)'+nipa303(9,T)';    
rSTX  = nSTX./nipa119(4,T)'*100;
tauc  = nSTX./nipa115(4,T)';
rCD   = (1-tauc).*nipa115(5,T)'./nipa119(5,T)'*100;
rGPDI = nipa116(5,T)';
rEX   = nipa116(6,T)';
rIM   = nipa116(7,T)';
rGC   = nipa395(4,T)'./nipa394(4,T)'*100;
rGI   = nipa395(5,T)'./nipa394(5,T)'*100;

Y0    = rGDP;
Y     = rGDP-rSTX;       % Y excludes consumption taxes
X     = rCD+rGPDI+rGI;   % X includes durables and government spending
G     = rGC+rEX-rIM;     % G ``wedge'' includes foreign factor
Pop   = prescott(:,4);
H     = prescott(:,8);

t     = ptime(1959.1,length(H),4);
hpc   = H./Pop;
prd   = Y./H*10^9;
ypc   = Y./Pop*10^9;
xpc   = X./Pop*10^9;
gpc   = G./Pop*10^9;

nt    = length(t);
mledur= [t(2:nt),ypc(2:nt)./ypc(1:nt-1),xpc(2:nt)./xpc(1:nt-1), ...
         hpc(2:nt)/1300,gpc(2:nt)./gpc(1:nt-1)];

%
Pop2  = ramey(:,2);
hpc2  = hpc.*Pop ./[Pop2(45:220);NaN*ones(4,1)];
mledur2= mledur(1:length(mledur)-4,:);
mledur2(:,4)=hpc2(2:176)*mean(hpc)/mean(hpc2(1:176))/1300;

%
hpc3  = [ramey(45:220,3)./ramey(45:220,2);NaN*ones(4,1)];
mledur3= mledur(1:length(mledur)-4,:);
mledur3(:,4)=hpc3(2:176)*mean(hpc)/mean(hpc3(1:176))/1300;

%
hpc4  = cev(45:216,3)./cev(45:216,4);
mledur4= mledur(1:length(mledur)-8,:);
mledur4(:,4)=hpc4(2:172)*mean(hpc)/mean(hpc4(1:172))/1300;

%
hpc5  = gali(:,3)./gali(:,4);
mledur5= mledur(1:length(mledur)-4,:);
mledur5(:,4)=hpc5(2:176)*mean(hpc)/mean(hpc5(1:176))/1300;
