%% dynare file to generate transition path from tau_p=0.4 to tau_p=0.7

var ch h i d lambda_h m R ks ls qk w hs ys ps div_s  bg Rg  %18
kp lp_bar lp hp yp pp div_p y Rs Rp b Xb Rp_bar rb lambda_c div_cb  %35
div_sb k dwl utility totutility lls yys pw gdp rs rp l;   %56


varexo  tau_p;
parameters BETA DELTA THETA_S THETA_P ALPHA As Ap ETA GAMMA TAU_S SIGMA OMEGAI A ZETAL TAU_P F_xi int_xi pi pr omegas 
         MU ZETA EPSILON PI RL KM OMEGAM BETA_B BETA_E PHI ALPHA_S ALPHA_P OMEGA_P KAPPA XI KAPPA_M BETA_SB ALPHA_SB CHANGE1;

parameter=calibration;
BETA=parameter(1); DELTA=parameter(2); THETA_S=parameter(3); THETA_P=parameter(4);
ALPHA=parameter(5); As=parameter(6); Ap=parameter(7); ETA=parameter(8); 
TAU_S=parameter(10);  SIGMA=parameter(12); OMEGAI=parameter(13); MU=parameter(14);
EPSILON=parameter(16);PI=parameter(17); RL=parameter(18); OMEGAM=parameter(32);
KM=parameter(19); BETA_B=parameter(20); BETA_E=parameter(21);PHI=parameter(22); 
ALPHA_S=parameter(23);ALPHA_P =parameter(24);OMEGA_P=parameter(25); 
KAPPA=parameter(26); XI=parameter(27);KAPPA_M=parameter(28);A=1;BETA_SB=parameter(29);
ALPHA_SB=parameter(30);ZETAL=parameter(31);ZETA=parameter(15);TAU_P=parameter(11);

load INITIAL_INFO
F_xi=pr_IN1; int_xi=int_xi_IN1;pi=PI;omegas=omegas_IN1;pr=F_xi;
load PARAMETER_CHOICE
CHANGE1=CHANGE;GAMMA=GAMMA_P;

model ;

%%%%%%%%%%%%%% Household sector Equation %%%%%%%%%%%%%%%

lambda_h=1/ch;

KAPPA*h^ETA=lambda_h*w;

BETA*R/ch(+1)=pi(+1)/ch;

BETA*Rg/ch(+1)=lambda_h*pi(+1);

KAPPA_M/m+BETA/ch(+1)/pi(+1)=1/ch;

utility=log(ch)-KAPPA*h^(1+ETA)/(1+ETA)+KAPPA_M*log(m);

totutility = utility + BETA*totutility(+1);

%%%%%%%%%%%%%%%%% SOE Equation %%%%%%%%%%%%%%%%%%%%%%%%%

Rs*ls=THETA_S*qk(+1)*ks*pi(+1);

(1-ALPHA)*ps*ys/hs=w;

ys=A*As*ks(-1)^ALPHA*hs^(1-ALPHA);  

BETA_E*((1-DELTA)*qk(+1)+ALPHA*ps(+1)*ys(+1)/ks-THETA_S*qk(+1))+THETA_S*qk(+1)*pi(+1)/Rs-qk=0;

div_s=(1-DELTA)*qk*ks(-1)+ps*ys-Rs(-1)*ls(-1)/pi-w*hs+ls-qk*ks;

ys=(ps/pw)^(-SIGMA)*(PHI)^(SIGMA)*y;

%%%%%%%%%%%%%%%%% POE Equation %%%%%%%%%%%%%%%%%%%%%%%%%

BETA_E*((1-DELTA)*qk(+1)+ALPHA*pp(+1)*yp(+1)/kp-THETA_P*qk(+1)-XI*qk(+1)*Rp_bar/pi(+1))+XI*qk+THETA_P*qk(+1)*pi(+1)/Rp-qk=0;

Rp*lp=THETA_P*qk(+1)*kp*pi(+1);

(1-ALPHA)*pp*yp/hp=w;

lp_bar=XI*qk*kp;

yp=A*Ap*kp(-1)^ALPHA*hp^(1-ALPHA);  

div_p=(1-DELTA)*qk*kp(-1)+lp+lp_bar+pp*yp-Rp(-1)*lp(-1)/pi-w*hp-Rp_bar*lp_bar(-1)/pi-qk*kp;

yp=(pp/pw)^(-SIGMA)*(1-PHI)^(SIGMA)*y;

pw=(EPSILON-1)/EPSILON+OMEGA_P/y/EPSILON*((pi/PI-1)*pi/PI*ch-BETA*lambda_h(+1)/lambda_h*(pi(+1)/PI-1)*pi(+1)/PI*ch);

%%%%%%%%%%%%%%%%% Commercial bank Equation %%%%%%%%%%%%%%%%%

BETA_B*(Rs-RL*TAU_S)/pi(+1)-(1-TAU_S)-ALPHA_S*ls+lambda_c*(1-GAMMA)=0;

BETA_B*(Rp-RL*tau_p)/pi(+1)-(1-tau_p)-ALPHA_P*lp+lambda_c*(1-GAMMA*ZETAL)=0;

BETA_B*rb*Xb(+1)/pi(+1)-1+lambda_c*(1-GAMMA*ZETA)=0;

1-BETA_B*R/pi(+1)-lambda_c=0;

div_cb=(Rp(-1)*lp(-1)+Rs(-1)*ls(-1)+rb*b(-1)*Xb-R(-1)*d(-1)-RL*(tau_p(-1)*lp(-1)+TAU_S*ls(-1)))/pi+d-(1-TAU_S)*ls-(1-tau_p)*lp-b-ALPHA_P/2*lp^2-ALPHA_S/2*ls^2;

b+lp+ls-d=GAMMA*(ls+lp*ZETAL+ZETA*b);

%%%%%%%%%%%%%%%%% Shadow bank Equation %%%%%%%%%%%%%%%

omegas*Rp_bar*lp_bar(-1)=rb*b(-1);

Xb=1-F_xi+(1-MU)*int_xi/omegas;

BETA_SB*Rp_bar(+1)*(1-int_xi)/pi(+1)=1+ALPHA_SB*lp_bar;

div_sb=((1-int_xi)*lp_bar(-1)*Rp_bar-(1-F_xi)*rb(-1)*b(-1))/pi+b-lp_bar-ALPHA_SB/2*lp_bar^2;

%%%%%%%%%%%%%%%%% Market clearing %%%%%%%%%%%%%%%%%

PHI^(SIGMA)*ps^(1-SIGMA)+(1-PHI)^(SIGMA)*pp^(1-SIGMA)=pw^(1-SIGMA);

k=(1-DELTA)*k(-1)+(1-OMEGAI*((i/(i(-1))-1)^2)/2)*i;

((1-OMEGAI/2*((i/(i(-1))-1)^2)-OMEGAI*(i/(i(-1))-1)*(i/(i(-1))))*qk-1)+BETA*OMEGAI*((i(+1))/i-1)*(((i(+1))/i)^2)*(qk(+1))*ch/(ch(+1))=0;

m-m(-1)/pi=tau_p*lp+TAU_S*ls-(tau_p(-1)*lp(-1)+TAU_S*ls(-1))*RL/pi+bg-Rg(-1)*bg(-1)/pi;

k=kp+ks;

h=hp+hs;

y=ch+i+dwl+OMEGA_P/2*(pi/PI-1)^2*ch;

gdp=ch+i;

dwl=(MU)*int_xi*Rp_bar*lp_bar(-1);

lls=lp/ls;

yys=yp/ys;

rs=Rs/pi(+1);

rp=Rp/pi(+1);

l=lp+ls+lp_bar;
end;

steady_state_model ;
[ch,h,i,d,lambda_h,m,R,pi,ks,ls,qk,w,hs,ys,ps,div_s,kp,lp_bar,lp,hp,yp,pp,div_p,y,Rs,Rp,rb,b,Xb,Rp_bar,omegas,lambda_c,div_cb,div_sb,k,pr,dwl,utility,totutility, F_xi,int_xi,lls,yys,pw,bg,Rg]=solve_total(tau_p,GAMMA);
gdp=ch+i;rs=Rs/pi;rp=Rp/pi;l=lp+ls+lp_bar;
end;

initval;
tau_p=0.4;
end;
steady;
resid;

endval;
tau_p=CHANGE1;
end;
steady;
resid;

shocks;
var tau_p;
periods 1;
values 0.4;
end;


model_diagnostics;
perfect_foresight_setup(periods = 1002);
perfect_foresight_solver(maxit = 500);
