dynDate substitution.
Users should not use dynDate or dynDates objects in a mod file (at least for basic usage: extraction of sub-samples or observations). For instance, one should be able to define a range as follows:
r = 1990Q1:2012Q3 ;
in the mod file, and use r
to define a subsample from a dynSeries object. Obviously, such a statement, interpreted as a matlab command by the preprocessor, would produce an error message in matlab. We need to convert occurences of dates by explicit calls to the dynDate constructor. For instance the previous statement should be replaced by
r = dynDate('1990Q1'):dynDate('2012Q3') ;
It is easy to find all the dates in a mod file a using regular expression of the form
[1-9][0-9]+([YyAa]|[Qq][1-4]|[Mm]([1-9]|[1][1-2])|[Ww]([1-9]|[1-4][0-9]|[5][1-2]))
The tricky part is that we do not want to replace all the occurences of dates: we do not want to replace dates written in dynare commands (set_time
and data
), in commented lines or blocks, in strings.
The matlab routine available here does these substitutions (there is also an example here). It would be faster and more elegant if the translation was done in the preprocessor (after the macroprocessing because dates can be defined using the macro language).