I made a model of cash-in-advance to buy international bonds. So, there are two cash-in-advance constraints - local money to buy consumption and foreign money to buy foreign bond.
There are some residuals and I am not sure why. Can someone help me troubleshoot or at least point to where the problem might be.
var c cstar n nstar k kstar z zstar r rstar w wstar y ystar b bstar q sigma sigmastar m1_1 m1_2 m2_2 m2_1 p p_star e e_star lambda lambda_star;
predetermined_variables k kstar b bstar m1_1 m1_2 m2_2 m2_1;
varexo e_z estar_z e_sigma estar_sigma;
parameters beta theta delta rho rhostar a bbar pac omega omegastar g gstar;beta = 0.9895;
delta = 0.0255;
theta = 0.36;
a = 2;
rho = 0.98;
rhostar = 0.98;
bbar = 0;
pac = 0.00074;
omega = 0.98;
omegastar = 0.98;
g = 1.02;
gstar = 1.02;model;
/*
Exchange rate home economy
*//*
Home economy
*/
y = exp(z) * k^theta * n^(1 - theta);/*
Budget constraint for home economy
m1_1 - holdings of country 1 money by country 1
m1_2 - holdings of country 2 money by country 1
*/
k(+1) + (m1_1(+1) / p) + ((e * m1_2(+1)) / p) = w * n + r * k + (1 - delta) * k + ((e * b) / p);/*
Cash-in-advance constraint
*/
c = ((m1_1 * g) / p);
q * b(+1) + 0.5 * pac * (b(+1) - bbar)^2 = m1_2;/*
FOC - intra temporal, capital accumulation, and bond accumulation
*/
beta * ((1 / c(+1)) * (g(+1) / p(+1))) = (a / (w * (1 - n))) * (1 / p); // Local currency accumulation
(a / (w * (1 - n))) = beta * (a / (w(+1) * (1 - n(+1)))) * (r(+1) + 1 - delta); // Capital accumulation
beta * (a / (w(+1) * (1 - n(+1)))) * (e(+1) / p(+1)) = lambda * (q + pac * (b(+1) - bbar)); // Bond accumulation
beta * lambda(+1) = (a / (w * (1 - n))) * (e / p); // Foreign currency accumulation/*
Prices
*/
r = theta * exp(z) * k^(theta - 1) * n^(1-theta);
w = (1 - theta) * exp(z) * k^(theta) * n^(-theta);/*
TFP
*/
z = rho * z(-1) + exp(sigma) * e_z;
sigma = omega * sigma(-1) + e_sigma;/*
Exchange rate foreign economy
*/
e_star = p_star / p;/*
Foreign Economy
*/
ystar = exp(zstar) * kstar^theta * nstar^(1 - theta);/*
Budget constraint for foreign economy
m2_1 - holdings of country 1 money by country 2
m2_2 - holdings of country 2 money by country 2
*/
kstar(+1) + (m2_2(+1) / p_star) + ((e_star * m2_1(+1)) / p_star) = wstar * nstar + rstar * kstar + (1 - delta) * kstar + ((e_star * bstar) / p_star);/*
Cash-in-advance constraint
*/
cstar = ((m2_2 * gstar) / p_star);
q * bstar(+1) + 0.5 * pac * (bstar(+1) - bbar)^2 = m2_1;/*
FOC - intra temporal, capital accumulation, and bond accumulation
*/
beta * ((1 / cstar(+1)) * (gstar(+1) / p_star(+1))) = (a / (wstar * (1 - nstar))) * (1 / p_star); // Local currency accumulation
(a / (wstar * (1 - nstar))) = beta * (a / (wstar(+1) * (1 - nstar(+1)))) * (rstar(+1) + 1 - delta); // Capital accumulation
beta * (a / (wstar(+1) * (1 - nstar(+1)))) * (e_star(+1) / p_star(+1)) = lambda_star * (q + pac * (bstar(+1) - bbar)); // Bond accumulation
beta * lambda_star(+1) = (a / (wstar * (1 - nstar))) * (e_star / p_star); // Foreign currency accumulation/*
Prices
*/
rstar = theta * exp(zstar) * kstar^(theta - 1) * nstar^(1-theta);
wstar = (1 - theta) * exp(zstar) * kstar^(theta) * nstar^(-theta);/*
TFP
*/
zstar = rhostar * zstar(-1) + exp(sigmastar) * estar_z;
sigmastar = omegastar * sigmastar(-1) + estar_sigma;/*
Bond market and currency clearing conditions
*/
b(+1) + bstar(+1) = 0;
m1_1(+1) + m1_2(+1) = m1_1 * g;
m2_2(+1) + m2_1(+1) = m2_2 * gstar;
end;steady_state_model;
z = 0;
zstar = 0;
sigma = 0;
sigmastar = 0;
b = 0;
bstar = 0;
m1_2 = 0;
m2_1 = 0;
m1_1 = 1;
m2_2 = 1;
lambda = 0;
lambda_star = 0;q = beta - pac * (b - bbar);
r = (1/beta) + delta - 1;
n = 1 / (1 + (a / (beta * g * (1 - theta))) * (1 - ((delta * theta) / r)));
k = (r / (theta * n^(1 - theta)))^(1/(theta-1));
y = k^theta * n^(1 - theta);
w = (1 - theta) * (y / n);
c = y - delta * k;
p = g / c;rstar = (1/beta) + delta - 1;
nstar = 1 / (1 + (a / (beta * gstar * (1 - theta))) * (1 - ((delta * theta) / rstar)));
kstar = (rstar / (theta * nstar^(1 - theta)))^(1/(theta-1));
ystar = kstar^theta * nstar^(1 - theta);
wstar = (1 - theta) * (ystar / nstar);
cstar = ystar - delta * kstar;
p_star = gstar / cstar;e = p / p_star;
e_star = p_star / p;end;
//model_diagnostics;
resid;
steady;