# Two-country and two-sector model is failed to find a solution to the linear system

Hello, everyone！
I built a two-country and two-sector model of an open economy. One sector’s products are produced independently at home, while the other requires foreign intermediates. I introduce a permanent productivity shock in a country to study the dynamics of the current account. But because I’m a novice, I don’t know why it failed. Please help me, thank you.
Rsimul21.mod (6.9 KB)

Here are all the documents，jpfeifer。It works well under temporary shocks。
end1.mat (500 Bytes)
end2.mat (581 Bytes)
param_r2.mat (233 Bytes)
Rsimul21.mod (7.0 KB)

I am at a loss what is going on here. There is some singularity in the stacked Jacobian, but I don’t have an idea where it is coming from. Maybe @MichelJuillard knows more.

Hi, jpfeifer. I kept trying to change my model until I added capital adjustment costs to it. Strangely, it suddenly worked. Nonetheless I still don’t know why it did.
end1.mat (500 Bytes)
end2.mat (581 Bytes)
param_r2.mat (233 Bytes)
Rsimul21.mod (7.4 KB)

In the initial model, equations 5 and 6 are collinear when evaluated at the steady state because uf1 = um1 = 0.04.
What is the meaning of these two equations? Do you have a written derivation of the equations of this model?
Maybe more equations are involved but it will be easier to see when the first problem has been corrected
I used DynareJulia (GitHub - DynareJulia/Dynare.jl: A Julia rewrite of Dynare: solving, simulating and estimating DSGE models.) to analyze the problem for no special reason except that nowadays I more comfortable with DynareJulia than DynareMatlab.
I attach the relevant files:
`test1a.mod` computes the initval end endval values
`test1.jl` runs the above Dynare file, computes the stacked Jacobian for 3 periods. It is enough to study colinearities. Then it computes the null space of the transposed Jacobian to show which equations are involved in the colinearities. On can see that equations 5 and 6 have some weight in the null space

In the version with adjustment cost, if1, im1 enters now the equations but they don’ t have the same value at the steady state. Same for kf1 and km1

I believe that the problem in the original model indicates an error in the derivations of the equations and the addition of adjustment costs may hide the problem rather than solving it. So you need to go to the bottom of it
test.zip (2.7 KB)

Thanks, jpfeifer.

Thank you for your patience,@MichelJuillard. uf1 and um1 are return to capital kf1 and km1 of different sectors. These two equations are first-order condition on kf1 and km1. This is a simple derivation.
Derivation.pdf (144.7 KB)

Thanks for the derivation, it seems that you have two times two problems of multiple agents/sectors: you have two countries and two sectors in each country.
You need to have mechanisms that determine the steady state level of net foreign assets in each country and the steady state of the stock of capital in each sector.

The penalty linked to foreign bonds B via parameter psik determines a steady state of zero for foreign bonds, but I don’t see a similar mechanism for the stock of capital in each of the two sectors. I don’t know how you determine the steady state outside of the *.mod file, but I suspect that the steady state of capital is set arbitrarily and not via an equilibrium condition.
That is one of the reasons why including the computation of the steady state inside the *.mod file makes things clearer than computing it via some external procedure

My above characterization of the collinearity in equation 5 and 6 wasn’t exact:
the problem appears in the last period of the simulation where lam(+1), uf1(+1) and um1(+1) are set by the terminal conditions and the only unknown variable in both equation is lam. There are three other collinear relationships between the equations of the model

@MichelJuillard I tried to follow the logic of `model_diagnostics` with `periods=1` and, using

``````check_Jacobian_for_singularity(full(A),M_.endo_names,options_)
``````

I get

``````Relation 1
Colinear variables:
if2
im2
kf2
km2
Relation 2
Colinear variables:
if1
im1
kf1
km1
Relation 1
Colinear equations
Equation     5, period     1
Equation     6, period     1
Equation    13, period     1
Equation    14, period     1
Relation 2
Colinear equations
Equation     5, period     1
Equation     6, period     1
Equation    13, period     1
Equation    14, period     1
``````

So it identifies the same equations as you did but the associated variables are not even appearing in the equations but are related to investment. What am I missing?

check_Jacobian_for_singularity.m (2.3 KB)
sim1_workspace.mat (19.5 KB)

Which model did you run? I think that I ran the first one and I found 4 different collinear relationships

The one from your zip file:
test1a.mod (4.8 KB)
I evaluated the Jacobian in line 69 of `sim1`. The rank deficiency is 2.

Thank you for your interest in my code, jpfeifer and @MichelJuillard. I think it will take me time to understand your responses. Once again, thank you very much.

Correlated variables don’t necessarily appear in the correlated equations. Consider the following system:

``````x  = 0
y = 0
u + v + w +  x + y + z = 0
u - v + w + x + y - z = 0
x + y = 0
x + y = 0
``````

there are two collinear relationships between equations 1, 2, 5, 6 and 2 collinear relations between variables u v w z

@jpfeifer if I understand correctly you show above that the Jacobian of the static model is rank deficient by 2. How come that `model_diagnostics in Rsimul21.mod isn’t picking it?

No, I am using the logic that `model_diagnostics` applies to the static Jacobian to the dynamic stacked Jacobian. sim1.m: add debugging information to diagnose singular Jacobians (!2222) · Merge requests · Dynare / dynare · GitLab contains the change.

The two sets of collinear equations in Rsimul21.mod come from the fact that the steady state of the stock of capital in each sector is undetermined once in country 1 and once in country 2.