Two sector dsge

I have developed a simple two sector dsge model, with sectoral output and inflation determined in two sectors and aggregated at the country level. There are two sectoral shocks for each sector and two aggregate output and inflation shocks.
However, I get the following error message:

There are 3 eigenvalue(s) larger than 1 in modulus
for 4 forward-looking variable(s)
The rank condition ISN’T verified!
error: Blanchard Kahn conditions are not satisfied: indeterminacy

twosector.mod (1.1 KB)

Why does your aggregation feature predetermined variables in

y=sector*yt(-1)+(1-sector)*yn(-1)+ey;
pi=sector*pit(-1)+(1-sector)*pin(-1)+epi;

?

This was just a test, it also does not work without this predetermined aggregation.

As mentioned in Small open economy in a currency union, you cannot simply fudge around with the timing. There is one and one correct timing structure.

Now I have solved the problem for the simple model, but I want a two sector dsge for a more complex model. The timing is 100% correct, but I think the links between the two sectors and the foreign economy are insufficiently specified. That is why I get a message that the BK conditions are not satisfied: (There are 16 eigenvalue(s) larger than 1 in modulus
for 16 forward-looking variable(s) The rank condition ISN’T verified!)

How can I close this model appropriately? Here are the model equations:

Blockquote

sector 1
cp=c1*cp(-1)+(1-c1)*cp(+1)+c2*(lp-lp(+1))-c3*(i-pip(+1)+ebp);
investp=i1*investp(-1)+(1-i1)*investp(+1)+i2*qp+einvp;
qp=q1*qp(+1)+(1-q1)*rp(+1)-(i-pip(+1)+ebp);
ksp=kp(-1)+up;
up=u1*rp;
kp=k1*kp(-1)+(1-k1)*investp+k2*einvp;
mupp=0;
pip=pi1*pip(-1)+pi2*pip(+1)-pi3*mupp+epp;
rp=-(kp-lp)+wp;
muwp=0;
wp=w1*wp(-1)+(1-w1)*(wp(+1)+pip(+1))-w2*pip+w3*pip(-1)-w4*muwp+ewp;
yp=phip*(alpha*kp+(1-alpha)*lp+eap);
yp=cy*cp+iy*investp+steady_state(rp)*k_y*up;

//sector2
cm=c1*cm(-1)+(1-c1)*cm(+1)+c2*(lm-lm(+1))-c3*(i-pim(+1)+ebm);
investm=i1*investm(-1)+(1-i1)*investm(+1)+i2*qm+einvm;
qm=q1*qm(+1)+(1-q1)*rm(+1)-(i-pim(+1)+ebm);
ksm=km(-1)+um;
um=u1*rm;
km=k1*km(-1)+(1-k1)*investm+k2*einvm;
mupm=alpha*(ksm-lm)+eam-wm;
pim=pi1*pim(-1)+pi2*pim(+1)-pi3*mupm+epm;
rm=-(ksm-lm)+wm;
muwm=wm-(sigmal*lm+(1/(1-h)*(cm-h*cm(-1))));
wm=w1*wm(-1)+(1-w1)*(wm(+1)+pim(+1))-w2*pim+w3*pim(-1)-w4*mupm+ewm;
ym=phip*(alpha*ksm+(1-alpha)*lm+eam);
ym=cy*cm+iy*investm+steady_state(rm)*k_y*um;

//Final goods sector
pi=sector*pip+(1-sector)*pim;
y=sector*yp+(1-sector)*ym+e_g;

//foreign economy
yf=yf(+1)-phi*(i-pif(+1))+eyf;                    
pif=lambda*yf+beta*pif(+1)+epif;           
i=rhoii*i(-1)+(1-rhoii)*(phi_pi*(pif-pi_target)+phi_y*(yf-y_target))+ei;

qq-qq(-1)=pif-pi+eqq-eqq(-1);

Please provide the full file

Here is the full file:
twosector.mod (3.7 KB)

That is very hard to debug. Please start from the working simple version and then add the features back. That is the only way to see where things go wrong.

The closed economy version works fine, this is the most simple version that works. In the model above the domestic output is simply the weighted sum of the sectoral output, but when I also add the imports as demand component, I get a slightly different error message:

Blanchard Kahn conditions are not satisfied: indeterminacy due to rank failure

So you have a two-sector closed economy version that works, but the open economy two-sector version does not work?

Yes, that’s right. It might have sth to do with the aggregate goods market equilibrium condition for the (domestic) two sector economy.

In principle, when I have indeterminacy due to rank failure, this means that there are eigenvalues that are zero and that the matrix does not have full rank, right? What does that mean in practical terms? Does it mean that an additional variable that is introduced must also influence those variables, where I have eigenvalues of zero?

Usually it means that one variable in your model cannot be determined, because in the linearized system, the matrix relating contemporaneous variables is not of full rank. This often happens because of Walras’s Law as one market clearing condition is redundant. If n-1 markets clear, the last one also clears. This in turn implies that a different equation is missing that would pin the one undetermined variable down. This is extremely hard to debug without knowing the model in detail. That’s why I told you to start with a working version and go from there. That limits the size of the code where the problem could have been introduced.

I have now found a solution for this. The redundant equation was a second Euler equation and the missing equation was the labor market clearing condition.
However, I get oscillatory irfs and the shock decomposition depends entirely on initial values. Do you know how to fix this?

Do you have a unit root in your model and is it desired? The IRFs seem not come back to the steady state. And what is the variable you are displaying? The scaling look huge.

The unit root is desired. I think it comes from the definition of the real exchange rate qq-qq(-1)=pif-pi+eqq-eqq(-1); However, in the one sector model this does not lead to such oscillatory irfs as in the two sector model.
The variable that was displayed is total outptut y, i.e. the sum of the sectoral outputs.

The nominal variables have a unit root. That is normal, but it seems output in your model has one as well, which is not normal. What happens if you set irf=1000? Does the IRF return?

If I set irf=1000, some variables return, but others never return:

Then there must be a mistake in your model. Your real variables should almost surely not feature a unit root.

So, could it be a timing mistake?