|
<< Click to Display Table of Contents >> Missing values |
![]() ![]()
|
Missing values can be stated using the m() function in Gekko. For instance:
time 2021 2023; x = 1, m(), 3; prt x;
// x |
If, in the above example, you set x[2020] = m(); and write a databank, the databank will be exactly the same as if you had not set the missing value for 2020. This is because, for timeseries, 'real' data starts from the first non-missing value, and ends with the last non-missing value. This 'real' data period is 2021-2023 in the above example, and setting x[2020] to missing does not change that. After running the above example, before 2021 and after 2023, the x series can be thought of as containg an infinite number of missing values, and setting a missing value before 2021 or after 2023 does not change that. To get the 'real' start and end period for a timeseries, you may use the functions x.fromseries('datastart') and x.fromseries('dataend').
You may transform missing values and non-missing values into 1's and 0's using the isMiss() function.
time 2021 2026; |
Remember that in Gekko, a function f(a, b) can always be written a.f(b), so x.isMiss('all') is the same as isMiss(x, 'all'). Without 'all' argument, the isMiss() function only looks at the 'real' data period (2022-2026), whereas with 'all' option, the 2021 value is identified as missing, too. The last PRT statement prints the sum of the third column above, identifying 3 missing values (including the 2021 value). This can be used to check for the existence of missing values, for instance if (x.ismiss('all').sumt() > 0).
All this is relatively straightforward. Questions arise, however, when comparing missing values with other missing values.
reset; time 2001 2003; |
The first six IF statements are hardly surprising. However, regarding y1 and y2, it is seen that the == and <> operators treat the missing value in 2002 as if it was just some special number. However, this is only the case regarding == and <>, not the operators <, <=, >= or >. For these operators, comparing a missing value with a missing value always results in false (or 0). Note that for an IF involving two timeseries to be true, the IF must be true for all observations (cf. IF).
Compatibility issues
In Gekko versions < 3.1.8, the IF statement marked with (*) would have returned 0 instead of 1, because the two missing values in 2002 would have been considered non-equal. This has been changed in Gekko versions >= 3.1.8, and if Gekko detects that an IF contains a series comparison with missing values, a warning will be issued. The old behavior can be emulated by using IF_OLD instead of IF, but be warned that IF_OLD may not live on forever, and it is therefore better to think about the problem and adapt to the 'new' IF logic regarding missing values. If you have been using the idiom if(x == x); ... ; end; to check for the existence of missing values in the series x, this will no longer work in Gekko >= 3.1.8, and you should replace it with if(x.ismiss('all').sumt() > 0); ... ; end;, where the meaning is also much more clear. A radical solution to the compatibility issue would be to set option bugfix missing = no, which would emulate Gekko < 3.1.8 completely regarding IF and series with missing values. Setting this option generally is not recommended, however.
Perhaps the following three steps could be sensible, if a warning is encountered.
•If in a hurry, set option bugfix missing = no. Afterwards, the programs should run as before. However, this is not a good long-term solution, and doesn't really fix the issue.
•When more time is available, remove option bugfix missing = no and identify the IF statements where there is a difference (when Gekko warns about the problem, it shows a list with the problematic if statements). In these statements, replace if(...) with if_old(...), which should replicate the former results. This, too, is not a good long-term solution either.
•Finally, resolve the IF_OLD(...) statements one by one. This may imply using if(x.ismiss('all').sumt() > 0) instead of if(x == x) to test for missing values, or in other ways changing the program to handle the presence of missing values.
The compatibility issue does not affect scalar comparisons, so if(%x1 == %x2) or if(y1[2002] == y2[2002]) behave in exactly the same way in Gekko < 3.1.8 and Gekko >= 3.1.8 (the latter of these IF's is true in all Gekko 3.1.x versions).