clc;
clear;

% old file name calib_germany_taxesA
% ASSUMPTIONS for GERMANY only


%labor market; 
%------------------------------------------------------- 
 ny=0.99;                   % employment rate of young workers
 % values affected by the choice of "ny",
    uy=1-ny;
    p=ny;                   % p=m/omega;
    qyv=ny;
 
 chi=0.9;                   % job destruction rate
 io=0.125;                 % inactivity rate of old workers
 % values affected by the choice of "omega" (through io and chi)
    omega=1+(1-io)*(1-(1-chi)*ny);
    qov=(omega-1)*ny;                      % qov=qo*v;
    no=qov+(1-io)*(1-chi)*ny;              % qov=(omega-1)*ny;
    uo=1-no-io;
    uor=(1-no-io)/(1-io);
    n=ny+no;
    m=ny*omega;
     
 alpha=0.5;                             % coeff. on vacancies in matching
 tens=1;                                    % tensions (tens=v/omega) 
 % values affected by the choice of "tens"
    v=tens*omega;                           % tens=v/omega
    mb=ny/tens^(alpha);
    q=ny/tens;                              % q=p/tens;
    qo=(omega-1)/omega*q;
    qy=qyv/v;   
     
 
% production function
% ------------------------------------
beta=0.99^80;
%ky=0.13;
prod=1.1;
eps=20;

muu=0.295;
mu=1-muu;

% values affected
  R=1/beta;
  %mu=1-ky*R;
  %muu=1-mu;
  ky=(1-mu)/R;
  kn=(eps*ky)^(1/mu);
  fn=mu*eps*kn^(1-mu);
  fny=fn;
  fno=prod*fn;
  k=kn*(ny+prod*no);
  y=eps*k^(1-mu)*(ny+prod*no)^mu;  
     
% tax rate, transfers, wages
% ------------------------------------
tau=0.155;  
rho=0;     % replacement rate, early retirement
cq=0.6;       % replacement rate, retirement     

sigma=0.6;   % survival rate

theta=0.91;    % relative wy/wo wage (ideally 0.91)
eta=0.75;      % workers' bargaining power (try to obtain desired lsw)

% values affected by above
    sj=(1-tau)/(1+tau)*fny;
    temp_1=(1-eta)/eta*(theta+eta*(1-chi)*(1-io)*p/R);
    temp_2=sj+(1-tau)/(1+tau)*fno*((1-eta)*(1-chi)*(1-io)*p/R-theta); %by 38 or relative wages
    Dnu_star=temp_2/temp_1;
    wo=(1-eta)*Dnu_star/(1-tau)+eta*fno/(1+tau); %by 33 and 34
    wy=theta*wo;
    bp=rho*wo;
    br=cq*wo;
    bud=sigma*br+io*bp; %outlay on benefits
    T=bud-2*tau*(wy*ny+wo*no);


 % consumption and savings
 %----------------------------------
       
  ibc=(1-tau)*wy*ny-T/(2+sigma)+((1-tau)*wo*no+io*bp-T/(2+sigma))/R+(sigma*br-sigma*T/(2+sigma))/R^2;
  
  vb=.2724;       % weight of bequest motive in utility function
  
 % values affected by the choice of "beta" and "vb"
    c=ibc/(1+beta+sigma*beta^2*(1+vb-vb*R^3));
    d=beta*R*c;
    e=beta*R*d;
    b=vb*e;
    s=sigma*R*b+(1-tau)*wy*ny-c-T/(2+sigma);
    z=R*s+(1-tau)*wo*no+io*bp-d-T/(2+sigma);

% value of the firm and profits
% ------------------------------------
  qs=s+z+sigma*b-k;
  npi=R*qs-qs;
  
% Vacancy costs
% ------------------------------------
  av=qov*(fno-(1+tau)*wo)+qyv*((fny-(1+tau)*wy)+(1-io)*(1-chi)*(fno-(1+tau)*wo)/R);
  a=av/v;
  svy=av/y;
  cb=y-(1+tau)*(wy*ny+wo*no)-R*k-a*v-npi;
  
% compute the disutility terms
% ------------------------------------
sig=0;

  Dnu=Dnu_star/d;
% Dnu=Dn-Du*u^sig;  
  Du=(((1-tau)*wo/d-Dnu)*(p+(1-p)*(1-chi)*ny)-bp/d)/uo^sig;
  Dn=Dnu+Du*uo^sig;

% check values
% ------------------------------------

dfny=fny-(1+tau)*wy+(1-chi)*(1-io)*(fno-(1+tau)*wo)/R;
dfno=fno-(1+tau)*wo;
dhny=(1-tau)*wy/c+(1-p)*(1-chi)*(1-io)/(R*c)*((1-tau)*wo-Dnu_star);
dhno=((1-tau)*wo-Dnu_star)/d;

gdp1=y-a*v-cb;
gdp2=k+c+d+sigma*e;
gdp3=(1-tau)*(ny*wy+no*wo)+bp*io+sigma*br+npi+R*k-T;

gdpc=gdp1/(2+sigma);
sz=s+z+sigma*b;
ls=(1+tau)*(wy*ny+wo*no)/y;
ls1=(1+tau)*(wy*ny+wo*no)/gdp1;
lsw=0.641;                           %ideally we want 0.68 for germany

prem1=(Dn-Du)/log(c); 
prem2=Dn-Du;
prem3=prem2/Dn;
muu=1-mu;

AUR=(uo+uy)/(2-io);

%%%%%%%%%
beta, alpha, chi, mu, muu, a, vb, prod, mb, uor, 
gdp1, gdp2, gdp3, fno, fny, wo, wy, qo, qy, Dn, Du, Dnu, tau, ls, ls1, lsw, cb, 
T, rho, cq, sigma, eta, qs, AUR, Dnu_star
