I find it worrisome that I obtain different stochastic means (2nd order approximation) for two versions of the model with mathematically the same expressions:

In model version A, I use this equation

gam*V@{i} = log(
@#for j in countries
+exp(gam*((cw@{j}^(1-1/sigma)-1)/(1-1/sigma) -tau@{j}@{i} + bet*V@{j}(+1)))
@#endfor
);

And in model version B, I use this equation

1=
@#for j in countries
+exp(gam*((cw@{j}^(1-1/sigma)-1)/(1-1/sigma) -tau@{j}@{i} + bet*V@{j}(+1) - V@{i}))
@#endfor
;

The stochastic means that I get are very different. For instance, for consumption I get 1.015 times the non-stochastic mean in version A, and 0.998 in version B. My first guess was that maybe the version A is prone to numerical errors if the term in exp() is large, and I thought B is better. But intuitively, the A result makes more sense. I could also get a version C that uses the following equation:

exp(gamV@{i}) =
@#for j in countries
+exp(gam((cw@{j}^(1-1/sigma)-1)/(1-1/sigma) -tau@{j}@{i} + bet*V@{j}(+1)))
@#endfor
;

Again, with very different results. Why is that and which formulation is “correct”?

You exponentiate both sides to remove the log (as I do for version C) and then divide by the LHS. And then you notice that exp(x)/exp(y) = exp(x - y). Does that make sense?

Ok, it seems to be the numerical issue that I mentioned. Since the term gam*V can be quite large (e.g. 50), exponentiating it results in extremely large numbers. I think one has to be a bit careful when entering these equations to make sure that they are somewhat “balanced”, e.g. by dividing both sides through steady state values. This makes the code more stable. I also noticed this issue when implementing the Calvo sticky price block where some of the values might be taken to the power of the elasticity of substitution of the varieties, resulting in some big numbers. If one has one country that is e.g. 1000 times larger than the other country, then these equations can throw you off.