clear all
close all

x = load('cz3.txt');
t = x(:,1);
y = x(:,2);
w = x(:,3);
ir = x(:,4)/100;
cpi = x(:,5);
sl = x(:,6)/100;   % labor share

n = length(t);

% transformace velicin
lcpi = log(cpi);
ly = log(y);
rw = w./cpi;
lrw = log(rw);

pie = (lcpi - lag(lcpi,1))*4; % mezictvrtletni inflace (anualizovana)

rir = ir(1:end-1) - pie(2:end); % realna urokova mira  
rir = [rir;nan];              

% tempa rustu
ygr = ly - lag(ly,1);
rirgr = rir - lag(rir,1);
rwgr = lrw - lag(lrw,1);

% vypocet tfp 
tfpgr = (1-sl).*rirgr + sl.*rwgr;

% prumery
sample = (2:n-1);

ygr_avg = mean(ygr(sample));
rirgr_avg = mean(rirgr(sample));
rwgr_avg = mean(rwgr(sample));
tfpgr_avg = mean(tfpgr(sample));

SL = mean(sl);
SK = 1-SL;

disp('tempa rustu v % p.a.')
disp('       vystup          rw           rir           tfp ')
disp([ygr_avg   rwgr_avg   rirgr_avg   tfpgr_avg]*400)

disp('vazena tempa rustu v % p.a.')
disp('       vystup          rw           rir           tfp ')
disp([ygr_avg  SL*rwgr_avg  SK*rirgr_avg   tfpgr_avg]*400)

disp('podil tfp na vystupu')
disp([tfpgr_avg/ygr_avg])
% srovnej s tfp vypocitanym pomoci primarniho pristupu (xls file)


figure
set(gcf,'Name','Puvodni data');
subplot(221)
plot(t,ly)
title('log vystupu')
subplot(222)
plot(t,lrw)
title('log realne mzdy')
subplot(223)
plot(t,rir)
title('realna ur. mira')

figure
set(gcf,'Name','Tempa rustu');
subplot(221)
plot(t,ygr)
title('Vystup')
subplot(222)
plot(t,rwgr)
title('Realna mzda')
subplot(223)
plot(t,rirgr)
title('Realna ur. mira')
subplot(224)
plot(t,tfpgr)
title('TFP')

































