
clear
close all
clc


%% Import data from spreadsheet
run importcolvar


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Generate the data following the instructions in the SW readme file%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%log is the natural log function in Matlab

%diff is the difference function in Matlab ie. diff(X), for a vector X, is [X(2)-X(1)  X(3)-X(2) ... X(n)-X(n-1)].

%Note that you need element by element multiplication and division!

% PCE=PCE*10^9;
% CNP16OV=CNP16OV*10^3;
% RGDP12=RGDP12*10^9;
% PRFI=PRFI*10^9;
% TNFAE=TNFAE*10^3;
% CAE=CAE*10^3;
% EFFR = EFFR/100;


c    	= log( ( PCE ./ GDPDEF ) ./ CNP16OV) .*100	;
hi    	= log( ( PRFI  ./ GDPDEF ) ./ CNP16OV ) .*100	;
y       = log( RGDP12 ./ CNP16OV ) .*100	;
hc       = log( ((TNFAE-CAE) .* TPAWH ) ./ CNP16OV ) .*100 ;	
hh      = log(CAE.*CAWH ./ CNP16OV ) .*100 ;
pinf	= diff( log(GDPDEF) )  .*100; 
wc  		= log( TPAHE ./ GDPDEF ).*100 ;	
wh  		= log( CAHE ./ GDPDEF ) .*100;	
rh    	= log( RHP ./ GDPDEF) * 100 ;
rsp     = log( SP ) * 100 ;
robs    = EFFR ./ 4 ;





%generate a time quarterly vector from 1947Q1 until 2004Q4
t=1965:0.25:2022.75;
t1=1965.25:0.25:2022.75;
%Save raw data in a m-file



dc=diff(c);
dy=diff(y);
dhi=diff(hi);
dwc=diff(wc);
dwh=diff(wh);
drhp=diff(rh);
drsp=diff(rsp);
dhh=diff(hh);
dhc=diff(hc);


%Eliminate the first data point from dc dy di dw and pinf and the first two
%from h and r

% dc=dc(2:end);
% dy=dy(2:end);
% dhi=dhi(2:end);
% %dw=dw(2:end);
% pinfobs=pinf(2:end);
% hc=hc(3:end);
robs=robs(2:end);

%Remove the mean from h
hcm=hc-mean(hc);
hhm=hh-mean(hh);

dcm=dc-mean(dc);
dym=dy-mean(dy);
dhim=dhi-mean(dhi);
dwcm=dwc-mean(dwc);
dwhm=dwh-mean(dwh);
pinfm=pinf-mean(pinf);
rm=robs-mean(robs);
drhpm=drhp-mean(drhp);
drspm=drsp-mean(drsp);
dhcm=dhc-mean(dhc);
dhhm=dhh-mean(dhh);


pinfobs=pinf;
%save the dataset in a file called usmodel_data.mat

%save hm dy dc dhi  pinfobs hc robs y c hi hc pinf 
save hm