
var c c_d c_f p_d p_f la w Q r_k i k re mc y h_y m p_m a x1 x2 pi p_dstar s m_d m_f p_md p_mf a_m h_m GDP cf laf wf kf i_f Qf rf_k pif cf_d pf_d cf_f pf_f mcf yf laf_y mf_d pf_m pf_dstar x1f x2f sf mf laf_m GDPf h d v GDP_obs h_m_obs m_f_obs GDPf_obs laf_obs log_m_f log_h_m log_GDP log_laf log_GDPf;

varexo e_v eps_GDPobs eps_h_mobs eps_m_fobs eps_lafobs;

parameters phi theta_c omega_c delta_k chi beta alpha nu theta_j psi omega_m theta_m alpha_m phif deltaf_k chif betaf omegaf_c thetaf_c alphaf nuf thetaf_j psif alphaf_m af af_m rho_v tau mu eta ass dss a_mss;

phi=1;
theta_c=2.545;
omega_c=0.83;
delta_k=0.03;
chi=2;
beta=0.95;
alpha=0.4056;
nu=0.5702;
theta_j=6;
psi=0.75;
omega_m=0.15;
theta_m=2.356;
alpha_m=0.3731;
phif=1.5;
deltaf_k=0.02;
chif=2;
betaf=0.99;
omegaf_c=0.6;
thetaf_c=2.25;
alphaf=0.4206;
nuf=0.5760;
thetaf_j=6;
psif=0.75;
alphaf_m=0.2078;
af=1;
af_m=1; 
rho_v=0.6;
tau=1.88;
mu=0.15;
eta=-0.0689;
ass=1;
dss=0.584;
a_mss=1;

model;
la^phi=w*(1-d-v)/c;
k=(1-delta_k)*k(-1)+(1-((chi/2)*(i/i(-1)-1)^2))*i;
Q+beta*(r_k(+1)/c(+1)-Q(+1)*(1-delta_k))=0;
1/c=Q*(chi*i*(i/(i(-1)^2)-1/i(-1))-(1-chi/2*(i/i(-1)-1)^2))-beta*(Q(+1)*chi*((i(+1)/i)^2)*(i(+1)/i-1));
c_d=omega_c*p_d^(-theta_c)*c;
c_f=(1-omega_c)*p_f^(-theta_c)*c;
omega_c*p_d^(1-theta_c)+(1-omega_c)*p_f^(1-theta_c)=1;
k(-1)=alpha*mc*(y/r_k);
h_y=nu*mc*(y/w);
m=(1-alpha-nu)*mc*(y/p_m);
mc=(1/a)*((r_k/alpha)^alpha)*((w/nu)^nu)*((p_m/(1-alpha-nu))^(1-alpha-nu));
(theta_j-1)*x1=theta_j*x2;
x1=y*p_dstar^(1-theta_j)*p_d^(theta_j-1)/c+x1(+1)*beta*psi*p_dstar^(1-theta_j)*p_dstar(+1)^(theta_j-1)*pi(+1)^(theta_j-1);%속흙c
x2=y*mc*p_dstar^(-theta_j)*p_d^theta_j/c+x2(+1)*beta*psi*p_dstar^(-theta_j)*p_dstar(+1)^theta_j*pi(+1)^theta_j;%속흙c
p_d=(psi*p_d(-1)^(1-theta_j)*pi^(theta_j-1)+(1-psi)*p_dstar^(1-theta_j))^(1/(1-theta_j));
s=(1-psi)*p_dstar^(-theta_j)*p_d^theta_j+psi*p_d(-1)^(-theta_j)*p_d^theta_j*pi^theta_j*s(-1);
y=a*(k(-1)^alpha)*((h_y)^nu)*((m)^(1-alpha-nu))*s^(-1);
m_d=omega_m*m*(p_md/p_m)^(-theta_m);
m_f=(1-omega_m)*m*(p_mf/p_m)^(-theta_m);
p_m=(omega_m*p_md^(1-theta_m)+(1-omega_m)*p_mf^(1-theta_m))^(1/(1-theta_m));
m_d=a_m*(h_m)^alpha_m;
h_m=alpha_m*m_d*p_md/w;
p_d=pf_f*re;
p_f=pf_d*re;
p_mf=pf_m*re;
laf^phif=wf/cf;
kf=(1-deltaf_k)*kf(-1)+(1-((chif/2)*(i_f/i_f(-1)-1)^2))*i_f;
Qf+betaf*(rf_k(+1)/cf(+1)-Qf(+1)*(1-deltaf_k))=0;
1/cf=Qf*(chif*i_f*(i_f/(i_f(-1)^2)-1/i_f(-1))-(1-chif/2*(i_f/i_f(-1)-1)^2))-betaf*(Qf(+1)*chif*((i_f(+1)/i_f)^2)*(i_f(+1)/i_f-1));
cf_d=omegaf_c*pf_d^(-thetaf_c)*cf;
cf_f=(1-omegaf_c)*pf_f^(-thetaf_c)*cf;
omegaf_c*pf_d^(1-thetaf_c)+(1-omegaf_c)*pf_f^(1-thetaf_c)=1;
kf(-1)=alphaf*mcf*(yf/rf_k);
laf_y=nuf*mcf*(yf/wf);
mf_d=(1-alphaf-nuf)*mcf*(yf/pf_m);
mcf=(1/af)*((rf_k/alphaf)^alphaf)*((wf/nuf)^nuf)*((pf_m/(1-alphaf-nuf))^(1-alphaf-nuf));
(thetaf_j-1)*x1f=thetaf_j*x2f;
x1f=yf*pf_dstar^(1-thetaf_j)*pf_d^(thetaf_j-1)/cf+x1f(+1)*betaf*psif*pf_dstar^(1-thetaf_j)*pf_dstar(+1)^(thetaf_j-1)*pif(+1)^(thetaf_j-1);%속흙c
x2f=yf*mcf*pf_dstar^(-thetaf_j)*pf_d^thetaf_j/cf+x2f(+1)*betaf*psif*pf_dstar^(-thetaf_j)*pf_dstar(+1)^thetaf_j*pif(+1)^thetaf_j;%속흙c
pf_d=(psif*pf_d(-1)^(1-thetaf_j)*pif^(thetaf_j-1)+(1-psif)*pf_dstar^(1-thetaf_j))^(1/(1-thetaf_j));
sf=(1-psif)*pf_dstar^(-thetaf_j)*pf_d^thetaf_j+psif*pf_d(-1)^(-thetaf_j)*pf_d^thetaf_j*pif^thetaf_j*sf(-1);
yf=af*(kf(-1)^alphaf)*(laf_y^nuf)*(mf_d^(1-alphaf-nuf))*sf^(-1);

mf=af_m*(laf_m)^alphaf_m;
laf_m=alphaf_m*mf*pf_m/wf;

h=h_y+h_m;
h=la*(1-d-v);
d=tau*v^mu/(1+v^mu);
laf=laf_y+laf_m;
p_mf*m_f+p_f*c_f=p_d*cf_f;
mf=mf_d+m_f;
y=c_d+i/p_d+cf_f;
GDP=c+i;
yf=cf_d+i_f/pf_d+c_f;
GDPf=cf+i_f;
log(a/ass)=eta*log(d/dss);
log(a_m/a_mss)=eta*log(d/dss);
log(v)=(1-rho_v)*log(0.00006)+rho_v*log(v(-1))+e_v;
log_m_f=log(m_f);
log_h_m=log(h_m);
log_GDP=log(GDP);
log_laf=log(laf);
log_GDPf=log(GDPf);
m_f_obs=log(m_f)-steady_state(log_m_f)+eps_m_fobs;
h_m_obs=log(h_m)-steady_state(log_h_m)+eps_h_mobs;
GDP_obs=log(GDP)-steady_state(log_GDP)+eps_GDPobs;
laf_obs=log(laf)-steady_state(log_laf)+eps_lafobs;
GDPf_obs=log(GDPf)-steady_state(log_GDPf);
end;

initval;
c=1.97208;
c_d=1.3223;
c_f=0.663488;
p_d=1.04583;
p_f=0.888;
la=0.843811;
w=2.18778;
Q=-0.507078;
r_k=0.035101;
i=0.600974;
k=24.0389;
re=0.92174;
mc=0.833327;
y=2.49644;
h_y=0.542201;
m=0.344631;
p_m=0.146082;
a=1;
x1=4.91627;
x2=4.09689;
pi=0.999935;
p_dstar=1.04563;
s=1;
m_d=0.100887;
m_f=0.247013;
p_md=0.124272;
p_mf=0.153057;
a_m=1;
h_m=0.0021381;
GDP=2.57306;
cf=3.28844;
laf=0.872765;
wf=2.51511;
kf=45.4317;
i_f=1.13579;
Qf=-0.304096;
rf_k=0.035101;
pif=1.00005;
cf_d=2.70732;
pf_d=0.963395;
cf_f=0.599507;
pf_f=1.13463;
mcf=0.833338;
yf=4.54976;
laf_y=0.868311;
mf_d=0.0776323;
pf_m=0.166053;
pf_dstar=0.963546;
x1f=5.37289;
x2f=4.47741;
sf=1;
mf=0.324645;
laf_m=0.00445393;
GDPf=4.42423;
h=0.544339;
d=0.584;
v=6e-05;
h_m_obs=0;
GDP_obs=0;
laf_obs=0;
m_f_obs=0;
GDPf_obs=0;
log_m_f=log(m_f);
log_h_m=log(h_m);
log_GDP=log(GDP);
log_laf=log(laf);
log_GDPf=log(GDPf);
end;

resid;
steady;
check;
model_diagnostics;
resid;

shocks;
var e_v;stderr 1;
var eps_GDPobs;stderr 1;
var eps_m_fobs;stderr 1;
var eps_h_mobs;stderr 1;
var eps_lafobs;stderr 1;
end;

estimated_params; 
rho_v,beta_pdf,0.6,0.1;
end;

varobs GDP_obs h_m_obs m_f_obs GDPf_obs laf_obs; 
identification(advanced=1,graph_format=fig);
% estimation(datafile=obdata,xls_sheet=sheet1,xls_range=B1:F86,conf_sig=.95,mh_replic=50000,mh_jscale=3.05,mh_nblocks=3,mode_check,mode_compute=6,bayesian_irf,irf=40,graph_format=fig,nodisplay) c c_d c_f p_d p_f la w Q r_k i k re mc y h_y m p_m a x1 x2 pi p_dstar s m_d m_f p_md p_mf a_m h_m GDP cf laf wf kf i_f Qf rf_k pif cf_d pf_d cf_f pf_f mcf yf laf_y mf_d pf_m pf_dstar x1f x2f sf mf laf_m GDPf h d v GDP_obs h_m_obs m_f_obs GDPf_obs laf_obs;
% stoch_simul(order=1,periods=0,irf=40,graph_format=fig,nodisplay) c c_d c_f p_d p_f la w Q r_k i k re mc y h_y m p_m a x1 x2 pi p_dstar s m_d m_f p_md p_mf a_m h_m GDP cf laf wf kf i_f Qf rf_k pif cf_d pf_d cf_f pf_f mcf yf laf_y mf_d pf_m pf_dstar x1f x2f sf mf laf_m GDPf h d v GDP_obs h_m_obs m_f_obs GDPf_obs laf_obs;
