Error : Residuals of the static equations contains all NaN

I’ve been trying to do that but I seem to be running in a sort of issue.

I’ve tried 2 different things one of which is obviously wrong :

Finding the golden ratio k, as I don’t have any savings rate to compute the kss.

Using the world constraint Xt+Xt* = Ct+Ct* +It+It*
I isolate Ct and change Xt and It for their respective functions (Xt = ATtK^theta) and (iT = KTt+1 - (1-delta) * KT)

I take the derivate with respect to k yielding :

(ATt *theta )/k ^(1-theta) - (1-delta) = 0

I do the same symetrically with the foreign country :

(ATstar,t *theta )/kstar ^(1-theta) - (1-delta) = 0

Replacing At, Atstar for 1 and theta for 0.4 and delta for 0.1 we get :

0.4/k^0.6 - 0.1 = 0

Rearranging yields :

4 = k^0.6

Raising everything to the 10/6

kgr = 10.07936684

and since the values are the same for kstar we get the same.

The function for knt and kstarn are the same as the k,kstar one but with another good, but all equations are symmetric. so I would get that for each value of K ?

Again, why don’t you impose symmetry and solve for the whole system?

I did try that,

As far as the model is concerned, it didn’t change anything, I’m still getting those residuals.

I tried to write a solver to find the starting value of all k, I tried by hand and it ended up being too much RAM for my brain, as I have problems with the timing of the choices.

I then tried to write a solver and it doesn’t work because I end up having Ct* in Ct expression and I can’t seem to find a way to reduce the entire expression. I thought the solver would end up able to solve it, but I must have made a mistake.

Here’s the solver code, maybe thats where my mistake is.

"clear
clc
x0 = [0.1;0.1;0.1;0.1;0.1;0.1;0.1;0.1];

solution = fsolve(@sol,x0)

function f = sol(x)
kt1 = x(1);
kt1 = x(2);
knt1 = x(3);
knt1 = x(4);
kst1 = x(5);
kst1 = x(6);
ksnt = x(7);
knst = x(8);

kt0 = 1 ;
knt0 = 1;
kst0 = 1;
knst0 = 1;
delta = 0.1;
beta = 0.96;

f1 = ((((((((kt0)^(.4))+((kst0)^(.4)) - Cts - ((kt1 - (.9)(kt0))))^(1-2.5)) - ((kst1 - (.9)(kst0))^(1-(2.5)) + ((((knt0)^(.4))-(knt1 - (0.9)(knt0)))^(1-2.5)))))^(3.866666667))/((kt0)^(.4))+((kst0)^(.4)) - Cts - ((kt1 - (.9)(kt0))-((kst1 - (.9)kst0))^(2.5))) * 0.4/((kt0)^(0.6)) + (0.9);
f2 = 0.96
((((((((kt1)^(.4))+((kst1)^(.4)) - Cts - ((kt2 - (.9)kt1)))^(1-2.5)) - ((kst2 - (.9)(kst1))^(1-(2.5)) + ((((knt1)^(.4))-(knt2 - (0.9)(knt1)))^(1-2.5)))))^(3.866666667))/((kt1)^(.4))+((kst1)^(.4)) - Cts - ((kt2 - (.9)kt1)-((kst2 - (.9)kst1))^(1-2.5))) * 0.4/((kt1)^(0.6)) + (0.9) - 1;
f3 = ((((((((kt0)^(.4))+((kst0)^(.4)) - Cts - ((kt1 - (.9)
(kt0))))^(1-2.5)) - ((kst1 - (.9)
(kst0))^(1-(2.5)) + ((((knt0)^(.4))-(knt1 - (0.9)
(knt0)))^(1-2.5)))))^(3.866666667))/((((knt0)^(.4))-((knt1 - (0.9)(knt0)))^(2.5))) ((0.4)/((knt0)^(.6)))+(0.9));
f4 = 0.96*((((((((kt1)^(.4))+((kst1)^(.4)) - Cts - ((kt2 - (.9)(kt1))))^(1-2.5)) - ((kst2 - (.9)(kst1))^(1-(2.5)) + ((((knt1)^(.4))-(knt2 - (0.9)(knt1)))^(1-2.5)))))^(3.866666667))/((((knt1)^(.4))-((knt2 - (0.9)(knt1)))^(2.5)))* ((0.4)/((knt1)^(.6)))+(0.9)) -1 ;
f5 = ((((((((kt0)^(.4))+((kst0)^(.4)) - Ct - ((kt1 - (.9)(kt0))))^(1-2.5)) - ((kst1 - (.9)(kst0))^(1-(2.5)) + ((((ksnt0)^(.4))-(ksnt1 - (0.9)(ksnt0)))^(1-2.5)))))^(3.866666667))/((kt0)^(.4))+((kst0)^(.4)) - Ct - ((kt1 - (.9)(kt0))-((kst1 - (.9)kst0))^(2.5))) * 0.4/((kst0)^(0.6)) + (0.9);
f6 = 0.96
((((((((kt1)^(.4))+((kst1)^(.4)) - Ct - ((kt2 - (.9)(kt1))))^(1-2.5)) - ((kst2 - (.9)(kst1))^(1-(2.5)) + ((((ksnt1)^(.4))-(ksnt2 - (0.9)(ksnt1)))^(1-2.5)))))^(3.866666667))/((kt1)^(.4))+((kst1)^(.4)) - Ct - ((kt2 - (.9)(kt1))-((kst2 - (.9)kst1))^(2.5))) * 0.4/((kst1)^(0.6)) + (0.9) -1 ;
f7 = ((((((((kt0)^(.4))+((kst0)^(.4)) - Cts - ((kt1 - (.9)
(kt0))))^(1-2.5)) - ((kst1 - (.9)(kst0))^(1-(2.5)) + ((((ksnt0)^(.4))-(ksnt1 - (0.9)(ksnt0)))^(1-2.5)))))^(3.866666667))/((((ksnt0)^(.4))-((ksnt1 - (0.9)(ksnt0)))^(2.5))) ((0.4)/((ksnt0)^(.6)))+(0.9));
f8 = 0.96 * ((((((((kt1)^(.4))+((kst1)^(.4)) - Cts - ((kt2 - (.9)(kt1))))^(1-2.5)) - ((kst2 - (.9)(kst1))^(1-(2.5)) + ((((ksnt1)^(.4))-(ksnt2 - (0.9)(ksnt1)))^(1-2.5)))))^(3.866666667))/((((ksnt1)^(.4))-((ksnt2 - (0.9)(ksnt1)))^(2.5)))* ((0.4)/((ksnt1)^(.6)))+(0.9)) - 1; "

and the error codes :

end

Unrecognized function or variable ‘Cts’.

Error in solverIME>sol (line 27)
f1 = ((((((((kt0)^(.4))+((kst0)^(.4)) - Cts - ((kt1 - (.9)(kt0))))^(1-2.5)) - ((kst1 - (.9)(kst0))^(1-(2.5)) + ((((knt0)^(.4))-(knt1 -
(0.9)(knt0)))^(1-2.5)))))^(3.866666667))/((kt0)^(.4))+((kst0)^(.4)) - Cts - ((kt1 - (.9)(kt0))-((kst1 - (.9)*kst0))^(2.5))) * 0.4/((kt0)^(0.6)) + (0.9);

Error in fsolve (line 258)
fuser = feval(funfcn{3},x,varargin{:});

Error in solverIME (line 6)
solution = fsolve(@sol,x0)

Caused by:
Failure in initial objective function evaluation. FSOLVE cannot continue.

So I’m stuck at the fact that Ct is Xt + Xt* - Ct* - It - It* leading me to have a Ct* in my Ct equation and a Ct in my Ct* equation and I’m getting real stuck at that point.

Continuing on, trying by hand, always interested in your pointers.

I don’t understand. If the model is symmetric, shouldn’t C^*=C?

You are absolutely right, but doing that yielded a result where there is no relations between both countries. While I was trying to find the kss, I saw that I was missing a savings rate and the paper provided a savings function, so I wrote it in the model and set prices as parameters and that got me passed the first step of the dynare process. I’m getting this :

dynare bleh.mod
Using 64-bit preprocessor
Starting Dynare (version 4.6.2).
Calling Dynare with arguments: none
Starting preprocessing of the model file …
Found 18 equation(s).
Evaluating expressions…done
Computing static model derivatives (order 1).
Computing dynamic model derivatives (order 1).
Processing outputs …
done
Preprocessing completed.

STEADY-STATE RESULTS:

c 2.27972
cstar 0.587556
d 1.43364
dstar 1.43364
ktrade 5.64054
ktradeN 5.64054
ktradestar 5.64054
ktradestarN 5.64054
iT 0.564054
iTstar 0.564054
iNT 0.564054
iNTstar 0.564054
AT 1
ANT 1
ATstar 1
ANTstar 1
save 0
savestar 0.655713

EIGENVALUES:
Modulus Real Imaginary

   4.146e-16        4.146e-16                0
   6.361e-15       -6.361e-15                0
        0.23             0.23                0
        0.23             0.23                0
        0.32             0.32                0
        0.32             0.32                0
      0.9338           0.9338                0
      0.9517           0.9517                0
      0.9811           0.9811                0
           1                1                0
        1.07             1.07                0
       1.107            1.107                0
       1.133            1.133                0
   1.924e+16       -1.924e+16                0
   7.101e+16       -7.101e+16                0
   1.011e+17       -1.011e+17                0
   4.179e+17        4.179e+17                0
   4.179e+17        4.179e+17                0
   6.479e+17       -6.479e+17                0
         Inf              Inf                0

There are 10 eigenvalue(s) larger than 1 in modulus
for 12 forward-looking variable(s)

The rank condition ISN’T verified!

Error using check_model (line 36)
The specified covariances for the structural errors are not consistent with the variances as they imply a correlation larger than ±1

Error in stoch_simul (line 75)
check_model(M_);

Error in bleh.driver (line 338)
[info, oo_, options_, M_] = stoch_simul(M_, options_, oo_, var_list_);

Error in dynare (line 293)
evalin(‘base’,[fname ‘.driver’]) ;

I’m wondering if the missing eigenvalues are linked to the fact that I would be missing some equations and I should set my prices as variables ?

Here’s the full code.

bleh.mod (2.7 KB)

Ran Model diagnostics, as it was suggested on this forum and elsewhere and I got this and it got me thinking that my whole saving part was not entirely essential and that way I can remove prices from parameters, which is good.

Model diagnostics put me on the road to rechecking the code redoing every equation and finding a mistake made me realize it maybe could now run with that whole price in parameters situations.

Now I’m getting this in model diagnostics and im stumped.

dynare bleh.mod
Using 64-bit preprocessor
Starting Dynare (version 4.6.2).
Calling Dynare with arguments: none
Starting preprocessing of the model file …
Found 16 equation(s).
Evaluating expressions…done
Computing static model derivatives (order 1).
Computing dynamic model derivatives (order 1).
Processing outputs …
done
Preprocessing completed.

DYNARE_SOLVE (solve_algo=2|4): number of blocks = 6
DYNARE_SOLVE (solve_algo=2|4): solving block 5, of size 1
DYNARE_SOLVE (solve_algo=2|4): solving block 4, of size 1
DYNARE_SOLVE (solve_algo=2|4): solving block 3, of size 1
DYNARE_SOLVE (solve_algo=2|4): solving block 2, of size 1
DYNARE_SOLVE (solve_algo=2|4): solving block 1, of size 12
MODEL_DIAGNOSTICS: No obvious problems with this mod-file were detected.

STEADY-STATE RESULTS:

c 1.43364
cstar 1.43364
d 1.43364
dstar 1.43364
ktrade 5.64054
ktradeN 5.64054
ktradestar 5.64054
ktradestarN 5.64054
iT 0.564054
iTstar 0.564054
iNT 0.564054
iNTstar 0.564054
AT 1
ANT 1
ATstar 1
ANTstar 1

EIGENVALUES:
Modulus Real Imaginary

   1.851e-16        1.851e-16                0
   3.113e-15        3.113e-15                0
        0.23             0.23                0
        0.23             0.23                0
        0.32             0.32                0
        0.32             0.32                0
      0.9297           0.9297                0
      0.9455           0.9455                0
      0.9667           0.9667                0
           1               -1                0
       1.088            1.088                0
       1.116            1.116                0
       1.139            1.139                0
         Inf              Inf                0
         Inf              Inf                0
         Inf              Inf                0
         Inf              Inf                0
         Inf              Inf                0
         Inf              Inf                0
         Inf              Inf                0

There are 10 eigenvalue(s) larger than 1 in modulus
for 12 forward-looking variable(s)

The rank condition ISN’T verified!

Error using check_model (line 36)
The specified covariances for the structural errors are not consistent with the variances as they imply a correlation larger than ±1

Error in stoch_simul (line 75)
check_model(M_);

Error in bleh.driver (line 307)
[info, oo_, options_, M_] = stoch_simul(M_, options_, oo_, var_list_);

Error in dynare (line 293)
evalin(‘base’,[fname ‘.driver’]) ;

It’s most probably a timing error. In

iT = ktrade(0) - (1-delt)*ktrade(-1);

you seem to be using the stock at the end end of period notation:

But then

AT*(ktrade^(theta)) + ATstar*(ktradestar^(theta)) = c + cstar + iT + iTstar;

does not.

1 Like

Thanks a lot !

I’m not completely sure to understand how to the timing for K works as I’ve been taught, that when writing kt+1 we use 0 and kt would then be k(-1).

All other variables are to be written as their timing seen in the equations ?

I’ve made a change and it reduced my eigenvalues with modulo above… to 4 values instead of 11, which is a good start.

I’d rather not have to declare the predetermined variables declaration as I am not familiar with it.

A : (((((c^(1-phi))+(d^(1-phi)))^(((-gamm)-phi)/(1-phi)))/ (c^(phi)))) = bet*((((c(1)^(1-phi))+(d(1)^(1-phi)))^(((-gamm)-phi)/(1-phi)))/ (c(1)^(phi))) * (((AT(1)*theta)/(ktrade(1)^(1-theta))) + (1-delt));

For exemple this equation gets me confused as it represents this :

B: U1(ct,dt) = U1(ct+1,dt+1)beta(At+1 * F1(Kt+1) + (1-delta))

So here, imagine I set iT as such :

C: iT = ktrade(+1) - (1-delt)*ktrade(0);

and

D: AT as such : log(AT(+1)) = cAT*log(AT)+epsilon;

How should I treat my capital in eq A and should the timing for ct+1 and dt+1 be c(1) and d(1) in this case ?

bleh.mod (2.5 KB)

I am not sure I understand your point. In your law of motion you replace k_{t+1} by k(0), which is correct Dynare notation. But in the production function, the ktrade(0) implies that production takes place with ktrade_{t+1}, which is strange. You need to be consistent.

So, I’ve changed that, but I still get an error because I’m not sure of the timing for my other variables around k.

so if in one euler I get U1(ct,dt) = U1(ct+1,d+t)*(F1(K)+(1-delta)) here my k is 0 to time it correctly, do I keep my c and d at 0 for U1(ct,dt) and 1 for U1 (ct+1,dt+1) or do I take the same timing convention as with k, which doesn’t seem to make sense to me.

Here’s the equation in question

(((((c^(1-phi))+(d^(1-phi)))^(((-gamm)-phi)/(1-phi)))/ (c^(phi)))) = bet*((((c(+1)^(1-phi))+(d(+1)^(1-phi)))^(((-gamm)-phi)/(1-phi)))/ (c(+1)^(phi))) * (((AT(+1)*theta)/(ktrade(0)^(1-theta))) + (1-delt));

Would that be ok ?

The timing only needs to be adjusted for the predetermined variables. Consumption is not predetermined. Given that you have more than 1 capital stock in the model, you need to check the timing for all of them. When doing so, keep Timing of capital in two sector model in mind.

1 Like

Thank you for the specification, but I’m not sure to understand what you mean, I’m getting confused with the authors question I think.

Do you mean that I might have the capital law of motion act differently for non-traded goods ? I’m not sure if its pertinent, but I have no function enabling me to bundle capitals together as per the exemple and I don’t think it is assumed by the author either .

If not, the paper tells us that we are looking for the kt+1 quantities across all 4 kt+1. So I imagine that the capital k is predetermined at time t.

I haven’t read the Tesar-paper in detail. All I am saying is that you need to be careful on whether all individual capital stocks are predetermined or just the total aggregate capital stock.

So that’s exactly my question :

How can I get an aggregate capital stock when I get 3 constraints :cry:

  1. AT*(ktrade(-1)^(theta)) + ATstar*(ktradestar(-1)^(theta)) = c + cstar + iT + iTstar;
  2. ANT*(ktradeN(-1)^(theta)) = d + iNT;
  3. ANTstar *(ktradestarN(-1)^(theta)) = dstar + iNTstar;

So we could posit a sort of KTworld taking in the LHS of 1)

where the iT, iTstar, iNT, iNTstar are the law of motion outlined above.

The model’s predictions for the pattern of consumption, production, and investment in each country can be derived from the social planner’s tirst- order conditions. After the realization of the state at time t, s,= {AT,ANT, AT*,ANT*), each country receives a consumption bundle which depends on each country’s utility share and the marginal utility of consumption of the traded good"

That’s the only place where there seems to be an idea of time period having been realized.

I can feel being close to the answer !

@jpfeifer I’ve toyed with timing with no success to change anything in the results, but I decided to try to give different values of gamma and phi to the home and foreign economies. Now I’m getting encouraging results as the economies seem to end up in a place where they aren’t identical in all points.

STEADY-STATE RESULTS:

c 1.57296
cstar 1.29431
d 1.43363
dstar 1.44772
ktrade 5.64053
ktradeN 5.64053
ktradestar 5.64054
ktradestarN 6.00127
iT 0.564053
iTstar 0.564054
iNT 0.564053
iNTstar 0.600127
AT 0.999999
ANT 0.999999
ATstar 1
ANTstar 1

EIGENVALUES:
Modulus Real Imaginary

   2.001e-15       -2.001e-15                0
        0.23             0.23                0
        0.23             0.23                0
        0.32             0.32                0
        0.32             0.32                0
      0.9232           0.9232                0
      0.9303           0.9303                0
      0.9618           0.9618                0
       1.063            1.063                0
       1.087            1.087                0
       1.115            1.115                0
         Inf              Inf                0

There are 4 eigenvalue(s) larger than 1 in modulus
for 8 forward-looking variable(s)

The rank condition ISN’T verified!

Error using print_info (line 32)
Blanchard & Kahn conditions are not satisfied: indeterminacy.

From my cursory research B&K seems to be still about the timing of shocks maybe but I’m stumped,

I’m attaching the file to give context :

bleh.mod (2.4 KB)

We are running in circles

Use bleh.mod (2.4 KB)

IT RUNS !!!

Oh my god, I thought it would never work, I was getting really scared it would never work.

I literally could never have found this without your precious help !!!

Thank you so so so so much for your patience.

Last question, how would I include a growth rate for the economy in my code ?

I would normally define a g parameter and do something like Y(1) = (1+g)*Y(0)

Since all my constraints are using the production function itself, I would have to define multiple variables and when I tried doing that, I ended up having too much or too many equations.

Is there a way to define growth in the model without timing the entire economy as I wrote as an exemple.

You are using perturbation techniques. That requires well-defined steady state. For that reason, you cannot add growth in the model. You need to enter the detrended model equations. An example is https://github.com/JohannesPfeifer/DSGE_mod/blob/master/RBC_baseline/RBC_baseline.mod where the gamma_x capture growth.

1 Like