clear all
close all
clc

x = load('us2.txt');
time = x(:,1);
lgdp = log(x(:,2));
unr = x(:,end);

n = length(time);

[lgdp_trend, lgdp_gap] = hp(lgdp,1600);
lgdp_gap = lgdp_gap *100;

% 1. model   y_gap_t = - alpha  u_gap_t  
% alpha -- labor intensity of production function, alpha = (0,1)

[unr_trend,unr_gap] = hp(unr,1600);

figure
plot(time,[unr unr_trend])
legend('Unemployment','trend (HP filter)')
a = ols(lgdp_gap,unr_gap);

disp('1. model: y_gap_t = - alpha  u_gap_t')
alpha = -a(1,1)


% 2. model  y_gap_t = alpha*uu - alpha * u_t
% uu is natural rate of unempolyment (NAIRU) (unobservable variable, "hidden" in constant)

X = [ones(n,1) unr];
b = ols(lgdp_gap,X);                %regression  model  y_gap_t = b1 + b2 unr_t

alpha2 = -b(2,1);
nairu2 = b(1,1)/alpha2;

disp('2. model:  y_gap_t = alpha*uu - alpha * u_t')
alpha2
nairu2

% 3.model   inverse relationship
% u_t = uu - 1/alpha * y_gap_t 

X2 = [ones(n,1) lgdp_gap];
c = ols(unr,X2);                   % unr_t = c1 + c2 * y_gap_t

disp('3.model:  u_t = uu - 1/alpha * y_gap_')
nairu3 = c(1,1)
alpha3 = -1/c(2,1)

% 4. model   with rigidities on labor market
% u_t =  w * u_t-1 + (1 - w) [uu - 1/alpha y_t ], 
% w is weight to lagged value of unemployment, (1-w) is weight to previous model

X4 = [ones(n,1) lag(unr,1) lgdp_gap];
d = ols(unr,X4);  % unr_t = d1 + d2 unr_t-1 + d3 y_gap_t

disp('4. model: u_t =  w * u_t-1 + (1 - w) [uu - 1/alpha y_t ]')
w = d(2,1)
alpha4 = (w-1)/d(3,1)
nairu4 = d(1,1)/(1-w)


nairu_plot = nairu3*ones(n,1);

figure
plot(time,[unr nairu_plot])
legend('Unemployment','Nairu (constant in time)')


    






    



