%%FINANCIAL INCLUSION WITHOUT DEFAULT%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


var 
c_p           //total consumption
c_i        //rural hhd consumption
%lambda
R_d    //shadow price rural
R_b
pi        //real balances rural
         //rural labor supply to firms
n_i
%m_h         //rural labor supply to BCA
m_e
d        //rural deposits
b
       //rural deposit interest rate
w_f
w_b       //wages paid by BCAs to rural labor
%w_bl
q_h
h
%D
L
%p_l
%p_d
y
%c
z_e
%z_d
z_l
z_b
eps_z
eps_l
%s_i
%t_p
;

predetermined_variables q_h;

//Exogenous Shocks
varexo e_z_e, e_z_l, e_z_b, e_eps_z, e_eps_l;

//Model Parameters (including Steady State)

parameters
h_bar
beta_p
beta_i
gamma
s_i
pi_s
z_e_bar  
z_l_bar
z_b_bar
eps_z_bar
eps_l_bar
rho_z_e 
%rho_z_d
rho_z_l
rho_z 
rho_l
rho_z_b 
;

//Value of Parameter
pi_s        =       1;
gamma       =       2; %(working value 0.00001)
beta_p      =     0.999;
beta_i      =    0.982;
theta       =      1;
%tau         =       0.5;
%eta1        =       0.75;  %share of rural households (as per NSS Emp-Unemp 2011-12)
%eta2        =       1;  %share of rural entrepreneurs in pop (as per NSS Emp-Unemp 2011-12)
%delta     =       0.75;  %share of banking correspondent agents (urban patients households)(as per NSS Emp-Unemp 2011-12)
%a_r         =       0.4;
%a_i         =       0.4;
z_e_bar      =      3;
z_d_bar     =       3;
z_l_bar     =       3;
z_b_bar     =       3;
eps_z_bar   =       3;
eps_l_bar   =       3;
s_i         =       0.8;  %LTV ratio urban impatient hhd (80%)
h_bar       =       1;
rho_z_e     =       0.99;
rho_z_d     =       0.99;
rho_z_l      =      0.99;
rho_z       =       0.99;
rho_l      =        0.99;
rho_z_b      =      0.99;
%R_d_s       =       1/beta_p;
%R_b_s       =       s_i*pi_s/(1-beta_i*(1-s_i));


model;
 %%Firms
%s_i         =   (1-rho_s_i)*s_i_bar+rho_s_i*(s_i(-1))+e_z_s;
z_e         =   (1-rho_z_e)*z_e_bar+rho_z_e*(z_e(-1))+e_z_e;                    %Eqn 63

%z_d         =   (1-rho_z_d)*z_d_bar+rho_z_d*(z_d(-1))+e_z_d;                 %Eqn 64

z_l         =   (1-rho_z_l)*z_l_bar+rho_z_l*(z_l(-1))+e_z_l;                %Eqn 65

z_b       =     (1-rho_z_b)*z_b_bar+rho_z_b*(z_b(-1))+e_z_b;             %66     
  
(eps_z)     =   (1-rho_z)*eps_z_bar+rho_z*(eps_z(-1))+e_eps_z;                %Eqn 67

(eps_l)     =   (1-rho_l)*eps_l_bar+rho_l*(eps_l(-1))+e_eps_l;           %Eqn 68
     
    
    1/c_p = beta_p*R_d/(pi(+1)*c_p(+1));
    R_b = s_i/(q_h/(q_h(+1)*pi(+1))- (beta_i*(1-s_i)*(c_i(+1))^(-1)*q_h(+1)/(c_i^(-1)*q_h(+1)*pi(+1))));
    w_f-z_e=0;
    z_e*n_i+R_b(-1)*z_b(-1)*z_l(-1)^(1+1/gamma)*m_e(-1)^(1+gamma)-z_e*n_i-z_b*z_l^(1+1/gamma)*m_e^(1+gamma)-gamma*z_l*m_e^(gamma-1)+q_h*(h-h(-1))=0;
    w_b-gamma*z_l*m_e^(gamma-1)=0;
    n_i-gamma*z_l*m_e^gamma/(eps_l*z_e)=0;
    c_i-z_e*n_i=0;
    y-z_e*n_i=0;
    L-z_l*m_e^gamma=0;
    d=z_b*L^(1+1/gamma);
    b=d;
    c_p=(R_d-1)*z_b*L/pi;
    h=h_bar;
    q_h(+1)= R_b*b/(s_i*h*pi_s);
    y=c_i;   
    
end;

shocks;
var e_z_e;
stderr 1;
%var e_z_d;
%stderr 1;
var e_z_l;
stderr 1;
var e_z_b;
stderr 1;
var e_eps_z;
stderr 1;
var e_eps_l;
stderr 1;

end;

initval;
z_e             =                   z_e_bar;
%z_d             =                   z_d_bar;
z_l             =                   z_l_bar;
z_b             =                   z_b_bar;
eps_z           =                   eps_z_bar;
eps_l           =                   eps_l_bar;
pi              =                     pi_s;
R_d             =                     1/beta_p;                  %Eqn 64
R_b             =                     s_i/(beta_i*(1+s_i)-1); 
w_f             =                     z_e_bar;                  %Eqn 65
m_e             =                     gamma/(z_b*(R_b-1)*z_l^(1/gamma));  
w_b             =                     gamma*z_l*m_e^(gamma-1);
n_i             =                     gamma*z_l_bar*m_e^gamma/(eps_l_bar*z_e_bar);  
c_i             =                     z_e_bar*n_i;
y               =                     z_e_bar*n_i;
L               =                     z_l_bar*m_e^gamma;     %Eqn 69
d               =                     z_b*L^(1+1/gamma);
b               =                     d;
c_p             =                    (R_d-1)*z_b*L/pi;
h               =                     1;          
q_h             =                     R_b*b/(s_i*h*pi_s);  

end;

steady;
%check;



%estimated_params_init;
%end;

stoch_simul (hp_filter=1600, order=1, irf=20, qz_zero_threshold=1e-14);
%estimation(datafile=fin_inclusion2,mh_replic=10000,mh_nblocks=2,mh_drop=0.45);
%options_.plot_priors=0;
%estimation(datafile=fin_inclusion2,mh_replic=20000,mh_nblocks=4,mh_drop=0.45,mh_jscale=0.8,bayesian_irf,irf=20,mode_compute=7) d_r d_u pi c b_e b_u r_ud k_b;



