Golden Rule 1: Display and use your intuition

The first golden rule for modeling is: Always display the results of your calculations and check them with your expectations about the results.
Often you are working on a model doing a lot of preparing calculations (calibrating the model, preparing the data). Those calculations might be easy, for example calculating the shares for some parameter, but if you make an unnoticed error can cost you a lot of time and frustration.
Here is a simple example. I want to calculate the shares for the investment function
 
 
Calculating the share is not difficult thing, but you can make small mistakes. When I teach I often see people write things like
 
      shareinv(s) = inv(s)/sum(as, inv(as));

There is only a small mistake: instead of summing over inv(as,”inv”)  people sum inv(s,”inv”).
 
Gams in this case just multiplies the value three times instead of summing over all the elements
 
The best way to guard yourself against errors like this is by displaying the results of your calculations. Just add a display statement and a $exit  on the next line (the last command stops gams even if there is code after the $exit. Don”t forget to write the $ of $exit in the first column).
 
But not only should you display your results, you should before that ask yourself what the result of your calculations will be. In this case you expect values between 0 and 1. Thinking about the expected results before you see the results is perhaps one of the most important things in modeling.
Perhaps this sounds all a little bit exaggerated, but mistakes are easily made and if you don’t check your results, you can loose a lot of time.
I have seen models with negative values for output, shares bigger than 1 and so on. Displaying your results and checking them with your intuition doesn’t take much time and can help you find bugs in an early stage of modeling.