close all 
clear all

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Mortensen (1998) avec productivités homogènes 
%
%  François Langot -- 08/2002
%
%   simplification r = 0
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clear all

% paramétrisation Mortensen
s     = 0.287;  % sorties (e->u) + (e->e) mortensen p.54
lamb  = 0.142;  % mortensen p.54
psi   = 0.5;

b     = 0.8;
y     = 2;

%%%%%%%%%%%%%%%%%%%
%
%  équilibre
%
%%%%%%%%%%%%%%%%%%%

v = lamb^(1/psi);

gamma1 = (lamb/v)*(s/(s+lamb))*((y-b)/(s+lamb));

wmax  = b + (1 - ((s/(s+lamb))^2 ))*(y-b);

incw   = (wmax-b)/500;                 
gridw  = b:incw:wmax;	    
nw     = length(gridw); 

Fw = zeros(1,nw);
fw = zeros(1,nw);
Gw = zeros(1,nw);
gw = zeros(1,nw);

for i=1:nw
    Fw(i) = ((s+lamb)/s)*(1-sqrt((y-gridw(i))/(y-b)));
end

Fw = Fw./Fw(end);

for i=1:nw
    Gw(i) = (s*Fw(i))/(s + lamb*(1-Fw(i)));
end

fw(1) = Fw(1);
gw(1) = Gw(1);
for j=2:nw
    fw(j)  = Fw(j)-Fw(j-1);
    gw(j)  = Gw(j)-Gw(j-1);    
end

%%%%%%%%%%%%%%%%%%%
%
%  équilibre avec taxes
%
%%%%%%%%%%%%%%%%%%%

tf = .2;
v = lamb^(1/psi);

gamma2 = (lamb/v)*(s/(s+lamb))*((y-(1+tf)*b)/(s+lamb));

wmaxt  = b + (1 - ((s/(s+lamb))^2 ))*(y-(1+tf)*b)/(1+tf);

incwt   = (wmaxt-b)/500;                 
gridwt  = b:incwt:wmaxt;	    
nwt     = length(gridwt); 

Fwt = zeros(1,nwt);
fwt = zeros(1,nwt);
Gwt = zeros(1,nwt);
gwt = zeros(1,nwt);

for i=1:nwt
    Fwt(i) = ((s+lamb)/s)*(1-sqrt((y-(1+tf)*gridwt(i))/(y-(1+tf)*b)));
end

Fwt = Fwt./Fwt(end);

for i=1:nw
    Gwt(i) = (s*Fwt(i))/(s + lamb*(1-Fwt(i)));
end

fwt(1) = Fwt(1);
gwt(1) = Gwt(1);
for j=2:nw
    fwt(j)  = Fwt(j)-Fwt(j-1);
    gwt(j)  = Gwt(j)-Gwt(j-1);    
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

w = gridw;
wt = gridwt;

debg = 1;

figure
plot(w(debg+1:end),fw(debg+1:end),'-',wt(debg+1:end),fwt(debg+1:end),'-')
grid on;
title('DISTRIBUTIONS : DENSITES');
ylabel('offres, salaires');
xlabel('w');
legend('f(w)','f(w) with t',2)


figure
plot(w(debg:end),gw(debg:end),'-',wt(debg:end),gwt(debg:end),'-')
grid on;
title('DISTRIBUTIONS : DENSITES');
ylabel('offres, salaires');
xlabel('w');
legend('g(w)','g(w) with t',2)


figure
plot(gridw(debg:end),Fw(debg:end),gridwt(debg:end),Fwt(debg:end))
grid on;
title('DISTRIBUTIONS : REPARTITIONS');
ylabel('offres, salaires');
xlabel('w');
legend('F(w)','F(w) with t',2)

figure
plot(gridw(debg:end),Gw(debg:end),gridwt(debg:end),Gwt(debg:end))
grid on;
title('DISTRIBUTIONS : REPARTITIONS');
ylabel('offres, salaires');
xlabel('w');
legend('G(w)','G(w) with t',2)

