M = csvread('data.csv',1,0);
dateQ 		= M(:,1);
Y_obs_val 		= M(:,2);	% yearly basis, current USD billions
C_obs_val 		= M(:,3);	% yearly basis, current USD billions
I_obs_val 		= M(:,4);	% yearly basis, current USD billions
GDP_defl 		= M(:,5);	% basis 100 in 2000.
CUR 			= M(:,6);	% basis 1
Emp_level 		= M(:,7); 	% in thousands
Hours_worked 	= M(:,8);	% yearly basis, per worker
FF 			= M(:,9);	% yearly basis, in %
Wage			= M(:,10); 	% in USD billions
...
% 1- compute total hours worked and hourly wage, quarterly
Tot_hours = Emp_level.*Hours_worked/4;
Hourly_wage = Wage*1e9./(Hours_worked.*Emp_level*1e3) ;
...
% 2- compute trend in labour
Trend_labour = hpfilter(Tot_hours,1600);
...
% 3- deflate Y, C, I, and L by Trend_labour (quarterly, in USD millions)
Y_val_detrend = Y_obs_val./Trend_labour/4*1000;
C_val_detrend = C_obs_val./Trend_labour/4*1000;
I_val_detrend = I_obs_val./Trend_labour/4*1000;
Hourly_wage_detrend = Hourly_wage./Trend_labour*1e6 ;
L_detrend = Tot_hours./Trend_labour;
...
% 4- deflate Y,C,I by GDP deflator
Y_vol_detrend = Y_val_detrend./GDP_defl*100;
C_vol_detrend = C_val_detrend./GDP_defl*100;
I_vol_detrend = I_val_detrend./GDP_defl*100;
Real_wage_det = Hourly_wage_detrend./GDP_defl*100;
...
% 5- compute inflation factor on a quarterly basis
pie = GDP_defl(2:end)./GDP_defl(1:end-1);
...
% 6- compute nominal interest factor on a quarterly basis
NominalFactor = (1+FF/100).^(1/4) ;
...
% 7- compute long run average growth of productivity and trend
average_growth = mean(Y_vol_detrend(2:end)./Y_vol_detrend(1:end-1)-1);
t = [1:length(dateQ)]';
trend = (1+average_growth).^t;
...
% 8- compute y, c, i
y = Y_vol_detrend./trend;
c = C_vol_detrend./trend;
i = I_vol_detrend./trend;
w = Real_wage_det./trend;
y = y(2:end);
c = c(2:end);
i = i(2:end);
w = w(2:end);
ymean = mean(y);
y = y/ymean;
c = c/ymean;
i = i/ymean;
R = NominalFactor(2:end);
z = CUR(2:end);
pi = pie;
L = L_detrend(2:end);