close all
clear all
clc                      % clear screen

x = load('us2.txt');
time = x(:,1);
lgdp = log(x(:,2));
lcpi = log(x(:,3));   % log of cpi   
lm1  = log(x(:,4));   % monetary aggregate M1
lm2  = log(x(:,5));   % monetary aggregate M2
ir1m  = x(:,6)/100;   % short-term deposit  interest rate (1 month)
ir3y  = x(:,7)/100;   % long-term deposit interest rate (3 years)

n=length(lgdp);
cost =(n:-1:1)';      % decreasing time series -> decreasing transaction cost in time
                      % approximation of technologies in payment system  

X = [ones(n,1) lgdp lcpi ir1m cost];
b1 = ols(lm1,X);           
b2 = ols(lm2,X);           


y3 = lm1 - lcpi;         %real money balances
X3 = [ones(n,1) lgdp ir1m  cost];
b3 = ols(y3,X3);           

y4 = lm2-lm1;              %ratio M2/M1
X4 = [ones(n,1) ir3y cost];
X5 = [ones(n,1) ir1m cost];
b4 = ols(y4, X4);          
b5 = ols(y4, X5);          


disp('   Monetary aggregate M1:  const     lgdp      lcpi      ir1m       cost'); 
b1
disp('   Monetary aggregate M2:  const     lgdp      lcpi      ir1m       cost'); 
b2
disp('   Real money balances M/P:  const     lgdp      ir1m       cost'); 
b3
disp('   Ratio M2/M1: 3 years ir, cost'); 
b4
disp('   Ratio M2/M1: 1 month ir, cost'); 
b5

yy = X*b1(:,1); %% fitted values (first model)
figure(1)
plot([lm1,yy])
legend('actual value','fitted value')



