Cash-in-advance in large economy model

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;

Hi swooneytoad,

the model does not run for me:

WARNING: A parameter was used with a lead or a lag in the model block
ERROR: There are 28 equations but 29 endogenous variables!

The first warning comes from your Local currency accumulation equation where you have gstar(+1), which you cannot do.

Best

Sorry, I mistakenly removed an exchange rate equation.

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
*/
e = p / p_star;

/*
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;

Hi swooneytoad,

you still have the same warning of using parameters with leads or lags in the model, I found at least one gstar(+1), which is not possible.

You also have a singularity problem

MODEL_DIAGNOSTICS: The Jacobian of the static model is singular
MODEL_DIAGNOSTICS: there is 1 colinear relationships between the variables and the equations
Colinear variables:
q
Colinear equations
1 4 5 6 8 9 14 17 18 19 21 22 27 28 29

MODEL_DIAGNOSTICS: The presence of a singularity problem typically indicates that there is one
MODEL_DIAGNOSTICS: redundant equation entered in the model block, while another non-redundant equation
MODEL_DIAGNOSTICS: is missing. The problem often derives from Walras Law.

and also use the incorrect timing for capital, it is end of period and thus k(-1). You should check if these things cause the problem by solving them. Hope this helps.

For the capital, I used k(+1) and it worked in a model I used previously. It worked because I specified it as part of the predetermined variables at the top.

I have no idea about the other errors - is there a better way to debug this? Which line and which equation are causing this problem?

Are you sure

m1_1(+1) + m1_2(+1) = m1_1 * g;
m2_2(+1) + m2_1(+1) = m2_2 * gstar;

is properly detrended? It seems to be growing so that no steady state exists.

Good catch. I saw it in the paper that it was based on but I didn’t include it in the Dynare implementation.

g can either be a parameter like in my setup or an exogenous variable - like if i want to test monetary policy.

Now, that I made g and gstar to be 1; the problem is now about collinearity.

MODEL_DIAGNOSTICS: The Jacobian of the static model is singular
MODEL_DIAGNOSTICS: there is 1 colinear relationships between the variables and the equations
Colinear variables:
q
Colinear equations
6 20 29 30 31

MODEL_DIAGNOSTICS: The presence of a singularity problem typically indicates that there is one
MODEL_DIAGNOSTICS: redundant equation entered in the model block, while another non-redundant equation
MODEL_DIAGNOSTICS: is missing. The problem often derives from Walras Law.
Total computing time : 0h00m00s

If you set them to 1, you will still have a unit root. That is (usually) not proper detrending.

I have fixed that problem by making money to have the same structure as TFP shock - so money will now have exogenous shocks.

In SS; money growth will be 1, because there is no shock, so exp(g) = 1.

I replaced all g and gstar with exp(g) or exp(gstar).

The collinearity problem still arose. Something wrong with q, but I can’t figure out what, considering that my previous model with q (but no money) runs properly.

Please provide the most recent version.

Here you go.

The money growth is now an exogenous process and initial money/ss money is normalized to 1.

I think there is something wrong here; the price level does not go back to steady state after a money growth shock, but other variables are doing what it is supposed to be doing.

var c cstar n nstar k kstar z zstar r rstar w wstar y ystar b bstar q sigma sigmastar m m_star p p_star e e_star g gstar rm rm_star;
predetermined_variables k kstar b bstar m m_star;
varexo e_z estar_z e_sigma estar_sigma e_g estar_g;
parameters beta theta delta rho rhostar rho_g rhostar_g a bbar pac omega omegastar;

beta = 0.9895;
delta = 0.0255;
theta = 0.36;
a = 2;
rho = 0.98;
rhostar = 0.98;
rho_g = 0.9;
rhostar_g = 0.9;
bbar = 0;
pac = 0.00074;
omega = 0.98;
omegastar = 0.98;

model;

/*
Exchange rate home economy
*/
e = p / p_star;
rm = m / p;

/*
Home economy
*/
y = exp(z) * k^theta * n^(1 - theta);

/*
Budget constraint for home economy
*/
k(+1) + ((e * q * b(+1)) / p) + ((0.5 * e * pac * (b(+1) - bbar)^2) / p) + (m(+1) / p) = w * n + r * k + (1 - delta) * k + ((e * b) / p);

/*
Cash-in-advance constraint
*/
c = ((m * exp(g)) / p);

/*
FOC - intra temporal, capital accumulation, and bond accumulation
*/
beta * ((1 / c(+1)) * (exp(g(+1)) / p(+1))) = (a / (w * (1 - n))) * (1 / p); // Local currency accumulation
beta * (a / (w(+1) * (1 - n(+1)))) * (r(+1) + 1 - delta) = (a / (w * (1 - n))); // Capital accumulation
beta * (a / (w(+1) * (1 - n(+1)))) * (e(+1) / p(+1)) = (a / (w * (1 - n))) * (e / p) * (q + pac * (b(+1) - bbar)); // Bond accumulation

/*
Prices
*/
r = theta * exp(z) * k^(theta - 1) * n^(1-theta);
w = (1 - theta) * exp(z) * k^(theta) * n^(-theta);

/*
Shocks
*/

// TFP
z = rho * z(-1) + exp(sigma) * e_z;
sigma = omega * sigma(-1) + e_sigma;

//Money shock
g = rho_g * g(-1) + e_g;

/*
Exchange rate foreign economy
*/
e_star = p_star / p;
rm_star = m_star / p_star;


/*
Foreign Economy
*/
ystar = exp(zstar) * kstar^theta * nstar^(1 - theta);

/*
Budget constraint for foreign economy
*/
kstar(+1) + ((e_star * q * bstar(+1)) /p_star) + ((0.5 * e_star * pac * (bstar(+1) - bbar)^2) / p_star) + (m_star(+1) / p_star) = wstar * nstar + rstar * kstar + (1 - delta) * kstar + ((e_star * bstar) / p_star);

/*
Cash-in-advance constraint
*/
cstar = ((m_star * exp(gstar)) / p_star);

/*
FOC - intra temporal, capital accumulation, and bond accumulation
*/
beta * ((1 / cstar(+1)) * (exp(gstar(+1)) / p_star(+1))) = (a / (wstar * (1 - nstar))) * (1 / p_star); // Local currency accumulation
beta * (a / (wstar(+1) * (1 - nstar(+1)))) * (rstar(+1) + 1 - delta) = (a / (wstar * (1 - nstar))); // Capital accumulation
beta * (a / (wstar(+1) * (1 - nstar(+1)))) * (e_star(+1) / p_star(+1)) = (a / (wstar * (1 - nstar))) * (e_star / p_star) * (q + pac * (bstar(+1) - bbar)); // Bond accumulation

/*
Prices
*/
rstar = theta * exp(zstar) * kstar^(theta - 1) * nstar^(1-theta);
wstar = (1 - theta) * exp(zstar) * kstar^(theta) * nstar^(-theta);

/*
Shocks
*/

// TFP
zstar = rhostar * zstar(-1) + exp(sigmastar) * estar_z;
sigmastar = omegastar * sigmastar(-1) + estar_sigma;

//Money shock
gstar = rhostar_g * gstar(-1) + estar_g;

/*
Bond market clearing conditions
*/
b(+1) + bstar(+1) = 0;


//y = c + k(+1) - (1 - delta) * k;
//ystar = cstar + kstar(+1) - (1 - delta) * kstar;

m(+1) = m * exp(g);

m_star(+1) = m_star * exp(gstar);

end;

steady_state_model;
g = 0;
gstar = 0;
z = 0;
zstar = 0;
sigma = 0;
sigmastar = 0;

b = 0;
bstar = 0;
m = 1;
m_star = 1;

q = beta - pac * (b - bbar);

r = (1/beta) + delta - 1;
n = 1 / (1 + (a / (beta * (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 = 1 / c;

rstar = (1/beta) + delta - 1;
nstar = 1 / (1 + (a / (beta * exp(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 = 1 / cstar;

e = p / p_star;
e_star = p_star / p;

rm = 1/p;
rm_star = 1/p_star;

end;

model_diagnostics;
resid;
steady;


model_diagnostics;
resid;
steady;



shocks;
var e_z = 0.01^2;
var estar_z = 0.01^2;

var e_sigma = 0.048^2;
var estar_sigma = 0.048^2;

var e_g = 0.001^2;
var estar_g = 0.001^2;

end;

stoch_simul(order=3, pruning, irf=300, periods=300);
m(+1) = m * exp(g);

m_star(+1) = m_star * exp(gstar);

both imply a unit root with permanent responses. Also, why do have these equations in expectations? The timing looks strange.

The households decide on how much money to bring into the next period in this period, that’s why m has (+1). And the supply of money is the money decided in the last period AND the growth shock.

  1. I missed that they are defined to be predetermined_variables.
  2. Exactly,

implies that any shock will be permanent.

To make sure that it is stationary is to divide price and money supply by price and make sure the inflation rate is constant right?

So, it will affect the exchange rate equation, the budget constraint, the first order condition, cash in advance and money market clearing condition

No, constant inflation rates do not imply a fixed price level.

I need to transform the nominal variables money balance and price. According to your guide this is done by dividing them by the current price level and if the price level is in the future, we need to use inflation.

Is this right?

I think you need to step back and consider whether your model implies a unit root in the level variables. Transforming unit roots into growth rates does not solve the underlying issue.

It definitely does, because of the shock that can happen to money supply. I think I will make money supply growth to be constant and it will not be stochastic.

If there is a shock in the equation, it’s obviously stochastic.