Mathematically equivalent equations yield different results


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)))

And in model version B, I use this equation

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

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
((cw@{j}^(1-1/sigma)-1)/(1-1/sigma) -tau@{j}@{i} + bet*V@{j}(+1)))

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


I see that it should be equivalent for one country, but how do you get the left-hand-side into the sum within the log for more than one country?

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?

Yes, that looks ok. Could you provide the different version?

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.

Yes, normalizations are often helpful. See e.g.