Skip to content
Snippets Groups Projects
Select Git revision
2 results Searching

README.md

Blame
  • Forked from Dynare / preprocessor
    Source project has a limited visibility.
    time-series.rst 107.50 KiB

    Time Series

    Dynare provides a MATLAB/Octave class for handling time series data, which is based on a class for handling dates. Dynare also provides a new type for dates, so that the user does not have to worry about class and methods for dates. Below, you will first find the class and methods used for creating and dealing with dates and then the class used for using time series. Dynare also provides an interface to the X-13 ARIMA-SEATS seasonal adjustment program produced, distributed, and maintained by the U.S. Census Bureau (2020).

    Dates

    Dates in a mod file

    Dynare understands dates in a mod file. Users can declare annual, bi-annual, quarterly, or monthly dates using the following syntax:

    1990Y
    1990S2
    1990Q4
    1990M11

    Behind the scene, Dynare’s preprocessor translates these expressions into instantiations of the MATLAB/Octave’s class dates described below. Basic operations can be performed on dates:

    plus binary operator (+)

    An integer scalar, interpreted as a number of periods, can be added to a date. For instance, if a = 1950Q1 then b = 1951Q2 and b = a + 5 are identical.

    plus unary operator (+)

    Increments a date by one period. +1950Q1 is identical to 1950Q2, ++++1950Q1 is identical to 1951Q1.

    minus binary operator (-)

    Has two functions: difference and subtraction. If the second argument is a date, calculates the difference between the first date and the secmond date (e.g. 1951Q2-1950Q1 is equal to 5). If the second argument is an integer X, subtracts X periods from the date (e.g. 1951Q2-2 is equal to 1950Q4).

    minus unary operator (-)

    Subtracts one period to a date. -1950Q1 is identical to 1949Q4. The unary minus operator is the reciprocal of the unary plus operator, +-1950Q1 is identical to 1950Q1.

    colon operator (:)

    Can be used to create a range of dates. For instance, r = 1950Q1:1951Q1 creates a dates object with five elements: 1950Q1, 1950Q2, 1950Q3, 1950Q4 and 1951Q1. By default the increment between each element is one period. This default can be changed using, for instance, the following instruction: 1950Q1:2:1951Q1 which will instantiate a dates object with three elements: 1950Q1, 1950Q3 and 1951Q1.

    horzcat operator ([,])

    Concatenates dates objects without removing repetitions. For instance [1950Q1, 1950Q2] is a dates object with two elements (1950Q1 and 1950Q2).

    vertcat operator ([;])

    Same as horzcat operator.

    eq operator (equal, ==)

    Tests if two dates objects are equal. +1950Q1==1950Q2 returns true, 1950Q1==1950Q2 returns false. If the compared objects have both n>1 elements, the eq operator returns a column vector, n by 1, of logicals.

    ne operator (not equal, ~=)

    Tests if two dates objects are not equal. +1950Q1~= returns false while 1950Q1~=1950Q2 returns true. If the compared objects both have n>1 elements, the ne operator returns an n by 1 column vector of logicals.

    lt operator (less than, <)

    Tests if a dates object preceeds another dates object. For instance, 1950Q1<1950Q3 returns true. If the compared objects have both n>1 elements, the lt operator returns a column vector, n by 1, of logicals.

    gt operator (greater than, >)

    Tests if a dates object follows another dates object. For instance, 1950Q1>1950Q3 returns false. If the compared objects have both n>1 elements, the gt operator returns a column vector, n by 1, of logicals.

    le operator (less or equal, <=)

    Tests if a dates object preceeds another dates object or is equal to this object. For instance, 1950Q1<=1950Q3 returns true. If the compared objects have both n>1 elements, the le operator returns a column vector, n by 1, of logicals.

    ge operator (greater or equal, >=)

    Tests if a dates object follows another dates object or is equal to this object. For instance, 1950Q1>=1950Q3 returns false. If the compared objects have both n>1 elements, the ge operator returns a column vector, n by 1, of logicals.

    One can select an element, or some elements, in a dates object as he would extract some elements from a vector in MATLAB/Octave. Let a = 1950Q1:1951Q1 be a dates object, then a(1)==1950Q1 returns true, a(end)==1951Q1 returns true and a(end-1:end) selects the two last elements of a (by instantiating the dates object [1950Q4, 1951Q1]).

    Remark: Dynare substitutes any occurrence of dates in the .mod file into an instantiation of the dates class regardless of the context. For instance, d = 1950Q1 will be translated as d = dates('1950Q1');. This automatic substitution can lead to a crash if a date is defined in a string. Typically, if the user wants to display a date:

    disp('Initial period is 1950Q1');

    Dynare will translate this as:

    disp('Initial period is dates('1950Q1')');