
%%test model Clara with ramsey policy
var lar c pi R  mc A n h  w mpl theta  u v q p m s  pr x1 x2 
 y  er X psi_n psi_sig sig ;

varexo mua mur;

parameters  beta xi khi b eta lamb zeta epsilon deltap 
gammap gamma phipi phiy rhor rhoa sua sur 
As ys Rs lars  pibar cs hs ns mcs mpls us vs qs pts ms ss ps x1s x2s 
 ws thetas rhoer hc Xs psi_ns psi_sigs sigs phi ppi  Hs
;
load parameter_main1;

set_param_value('Hs',Hs);
set_param_value('hc',hc);
set_param_value('ppi',ppi);

set_param_value('phi',phi);
set_param_value('Xs',Xs);
set_param_value('sigs',sigs);
set_param_value('psi_ns',psi_ns);
set_param_value('psi_sigs',psi_sigs);
set_param_value('beta',beta);
set_param_value('xi',xi);
set_param_value('khi',khi);
set_param_value('eta',eta);
set_param_value('b',b);
set_param_value('lamb',lamb);
set_param_value('zeta',zeta);
set_param_value('epsilon',epsilon);
set_param_value('deltap',deltap);
set_param_value('gammap',gammap);
set_param_value('rhoa',rhoa);
set_param_value('rhor',rhor);
set_param_value('phipi',phipi);
set_param_value('phiy',phiy);
set_param_value('gamma',gamma);
set_param_value('pibar',pibar);
set_param_value('sua',sua);
set_param_value('sur',sur);
set_param_value('ps',ps);
set_param_value('ss',ss);
set_param_value('Rs',Rs);
set_param_value('mcs',mcs);
set_param_value('As',As);
set_param_value('pts',pts);
set_param_value('ns',ns);
set_param_value('us',us);
set_param_value('ms',ms);
set_param_value('vs',vs);
set_param_value('thetas',thetas);
set_param_value('qs',qs);
set_param_value('hs',hs);
set_param_value('mpls',mpls);
set_param_value('ys',ys);
set_param_value('cs',cs);
set_param_value('lars',lars);
set_param_value('x1s',x1s);
set_param_value('x2s',x2s);
set_param_value('ws',ws);
set_param_value('rhoer',rhoer);
model;
 %(1) marginal utility of consumption:
exp(lar) =( 1/(exp(c)-hc*exp(c(-1))))-((beta*hc)/(exp(c(+1))-hc*exp(c)));   %%MODIFIEE
%(2) FOC Bonds:
exp(lar) = beta*(1+R)*(1/exp(pi(+1)))*exp(lar(+1));
% (3) REAL wage:
exp(w)*exp(psi_n)=xi*exp(psi_n)*(b*(1/(( 1/(exp(c)-hc*exp(c(-1))))-(beta*hc/(exp(c(+1))-hc*exp(c)))))+
(1/(1+eta))*(1/(( 1/(exp(c)-hc*exp(c(-1))))-(beta*hc/(exp(c(+1))-hc*exp(c)))))
*exp(h)^(1+eta))+(1-xi)*(exp(mc)*exp(mpl)*exp(h)+(exp(psi_n)/exp(psi_n(+1)))*khi*exp(theta)*
(1/(( 1/(exp(c)-hc*exp(c(-1))))-(beta*hc/(exp(c(+1))-hc*exp(c)))))
+(1-lamb)*khi*(1-(exp(psi_n)/exp(psi_n(+1))))*
(1/(( 1/(exp(c)-hc*exp(c(-1))))-(beta*hc/(exp(c(+1))-hc*exp(c)))))*(1/exp(q)));

% (4) unemployment rate:
exp(u)=1-exp(n);

%(5) tighness market:
exp(theta)=exp(v)/exp(u);
%(6) ressource constraint:
exp(y)= exp(c)+exp(v)*khi*(1/(( 1/(exp(c)-hc*exp(c(-1))))-
((beta*hc)/(exp(c(+1))-hc*exp(c)))));   %% MODIFIEE

%(7)decision post vacancy

(khi/exp(q))=beta*xi*(eta/(1+eta))*exp(psi_n(+1))*exp(h(+1))^(1+eta)-beta*xi*exp(psi_n(+1))*b
-beta*(1-xi)*(exp(psi_n(+1))/exp(psi_n(+2)))*khi*exp(theta(+1))
-(beta*(1-lamb)*(1-xi)*exp(psi_n(+1))*khi/(exp(q(+1))))*(1-(exp(psi_n(+1))/exp(psi_n(+2))))
+beta*(1-lamb)*khi/exp(q(+1));


% (8) labor marginal productivity:
exp(mpl)=(1-phi)*exp(A)*(exp(sig)^(phi))*(exp(n)*exp(h))^(-phi);%%RC

%(9) evolution stock employment:
exp(n)=(1-lamb)*exp(n(-1))+exp(p)*(1-exp(n(-1)));

%(10) matchning:
exp(m)=zeta*(exp(v)^epsilon)*(exp(u)^(1-epsilon));

% (11) probibility worker find a job:
exp(p)=exp(m)/exp(u);
%(12) 
exp(q)=exp(m)/exp(v);
% (13) price dispersion
exp(s)=(1-deltap)*exp(pr)^(-gamma)+deltap*(exp(pi(-1))^(gammap)/exp(pi))^(-gamma)*exp(s(-1));
%(14) production function

exp(X)=(1/exp(s))*(exp(A)*(exp(sig)^(phi))*((exp(n)*exp(h))^(1-phi))); %% RC
%(15) price evolution:
1 = deltap*(exp(pi(-1))^(gammap)/exp(pi))^(1-gamma) + (1-deltap)*exp(pr)^(1-gamma);


% (16) optimal price:
exp(pr)=(gamma/(gamma-1))*(exp(x1)/exp(x2));
%(17) auxiliary x1:
exp(x1)=exp(lar)*exp(mc)*exp(X)+
deltap*beta*(((exp(pi)^(gammap))/exp(pi(+1)))^(-gamma))*exp(x1(+1));

%(18) auxiliary x2:
exp(x2)=exp(lar)*exp(X)+
deltap*beta*(((exp(pi)^(gammap))/exp(pi(+1)))^(1-gamma))*exp(x2(+1));

%(19) Real marginal cost


exp(mc) = (((1-xi)*exp(psi_n)+xi+(exp(psi_n)-1)*xi)/((1-xi)*exp(psi_n)+xi+(1-exp(psi_n))*(1-xi)))

*(((exp(h)^eta)/(exp(mpl)))*(1/(( 1/(exp(c)-hc*exp(c(-1))))-
((beta*hc)/(exp(c(+1))-hc*exp(c))))));  %%RC MODIFIEE


% shocks
%(20) productivity shock:


exp(A)=exp(A(-1))^rhoa*exp(mua);

%(21) Taylor rule:
%(1+R)/(1+Rs)=((((exp(pi)/pibar)^(phipi))*(exp(y)/exp(y(-1)))^phiy)^(1-rhor))*
%(((1+R(-1))/(Rs+1))^(rhor))*exp(-er);

%(22)monetary shock
exp(er) = exp(er(-1))^(rhoer)*exp(mur);

%(24) input

exp(psi_sig)=phi*exp(mc)*exp(A)*(exp(sig)/(exp(n)*exp(h)))^(phi-1);
%(25)
exp(psi_sig)=1-ppi+ppi*(1+R);
%(26)
exp(psi_n)=1-ppi+ppi*(1+R);

%(27)
exp(y)=exp(X)-exp(sig);
end;



initval;

X=log(Xs);
sig=log(sigs);
psi_n=log(psi_ns);
psi_sig=log(psi_sigs);
A=log(As);
y=log(ys);
R=Rs;
lar=log(lars);
er=0;
pi=log(pibar);
c=log(cs);
h=log(hs);
n=log(ns);
mc=log(mcs);
mpl=log(mpls);
u=log(us);
v=log(vs);
q=log(qs);
p=log(pts);
m=log(ms);
s=log(ss);
pr=log(ps);
x1=log(x1s);
x2=log(x2s);
w=log(ws);
theta=log(thetas);

end;


shocks;

var mua= sua^2;
var mur= sur^2;

end;
planner_objective((ln(c))-n*((h^(1+eta))/(1+eta)));
ramsey_policy(planner_discount=0.99,order=1,instruments=(R));
oo_ramsey_policy_steady_state_file=oo_;
stoch_simul(periods=0, order=1, irf=25, nograph);


