Dynare Time Series & Reporting: Houtan Bastani
Dynare Time Series & Reporting: Houtan Bastani
Houtan Bastani
houtan@dynare.org
CEPREMAP
11 June 2015
Houtan Bastani (CEPREMAP) Dynare Time Series & Reporting 11 June 2015 1 / 38
Outline
1 Time Series
Overview
A Programming Note
Syntax
dates Syntax
dseries Syntax
2 Reporting
Overview
Syntax
Houtan Bastani (CEPREMAP) Dynare Time Series & Reporting 11 June 2015 2 / 38
Time Series
Outline
1 Time Series
Overview
A Programming Note
Syntax
2 Reporting
Houtan Bastani (CEPREMAP) Dynare Time Series & Reporting 11 June 2015 3 / 38
Time Series Overview
Overview
Houtan Bastani (CEPREMAP) Dynare Time Series & Reporting 11 June 2015 4 / 38
Time Series A Programming Note
X =
1
• You can call any method defined for the integer class on integer object X.
Imagine such a method is called multiplyByTwo().
• In most object-oriented languages, writing X.multiplyByTwo(); will change
the value contained in X to 2
Houtan Bastani (CEPREMAP) Dynare Time Series & Reporting 11 June 2015 5 / 38
Time Series A Programming Note
ans =
>> X
X =
Houtan Bastani (CEPREMAP) Dynare Time Series & Reporting 11 June 2015 6 / 38
Time Series A Programming Note
X =
2
• Keep this in mind when using Dynare dates, time series, and reporting
Houtan Bastani (CEPREMAP) Dynare Time Series & Reporting 11 June 2015 7 / 38
Time Series Syntax
Syntax
Houtan Bastani (CEPREMAP) Dynare Time Series & Reporting 11 June 2015 8 / 38
Time Series Syntax
dates Syntax
• The dates command creates an object that represents zero or more dates at
a given frequency
• A dates object contains 3 members (fields):
• freq: 1, ‘y’ (Annual); 4, ‘q’ (Quarterly); 12, ‘m’ (Monthly); 52, ‘w’ (Weekly)
• time: A <<No of dates>>×2 matrix; the 1st col is the year and the 2nd col is
the period
• dates members cannot be modified. Thus, this is not allowed
>> dd.freq = 12;
Houtan Bastani (CEPREMAP) Dynare Time Series & Reporting 11 June 2015 9 / 38
Time Series Syntax
• A single date
>> t = dates(‘1999y’);
• Multiple dates
>> t = dates(‘1999q1’, ‘2020q2’, ‘-190q3’);
Notice that noncontiguous and negative dates are possible
• Can also create dates programatically
>> t = dates(4, [1990; 1990; 1978], [1; 2; 3])
t = <dates: 1990Q1, 1990Q2, 1978Q3>
• Can specify an empty dates. . .
>> qq = dates(‘Q’);
>> qq = dates(4);
• . . . and use it to instantiate new dates
>> t = qq(1990, 1);
t = <dates: 1990Q1>
>> t = qq([1990; 1990; 1978], [1; 2; 3])
t = <dates: 1990Q1, 1990Q2, 1978Q3>
Houtan Bastani (CEPREMAP) Dynare Time Series & Reporting 11 June 2015 10 / 38
Time Series Syntax
• The preprocessor allows for syntax simplification when dates are in .mod files
• A single date t = 1999y;
⇒ t = dates(‘1999y’);
• Multiple dates t = [1999q1 2020q2 1960q3];
⇒ t = [dates(‘1999q1’) dates(‘2020q2’) dates(‘1960q3’)];
• NB: This can cause problems when dates are included in strings. e.g.,
disp(‘In 1999q1, ...’)
would be transformed into
disp(‘In dates(‘1999q1’), ...’)
• To fix this, simply prefix any date that you don’t want transformed by the
preprocessor with a ‘$’: disp(‘In $1999q1, ...’)
⇒ disp(‘In 1999q1, ...’)
Houtan Bastani (CEPREMAP) Dynare Time Series & Reporting 11 June 2015 11 / 38
Time Series Syntax
• A collection of dates
a = 1990Q1; b = 1957Q1; c = -52Q1;
d = [a b c];
⇒ d = <dates: 1990Q1, 1957Q1, -52Q1>
• A Range of dates
a = 1990Q3:1991Q2
⇒ a = <dates: 1990Q3, 1990Q4, 1991Q1, 1991Q2>
Houtan Bastani (CEPREMAP) Dynare Time Series & Reporting 11 June 2015 12 / 38
Time Series Syntax
Comparing dates
• The following comparison operators are supported: ==, v=, <, ≤, >, and ≥
• Compared objects must have the same frequency
• Compared objects must have the same number of elements (except for
singletons)
• Returns the result of an element-wise comparison
• Let a=[1999W1 2020W3], b=1999W1, and c=[1888w1 2020w3]. Then
>> a == b >> a > b >> c < a
1 0 1
0 1 0
Houtan Bastani (CEPREMAP) Dynare Time Series & Reporting 11 June 2015 13 / 38
Time Series Syntax
Houtan Bastani (CEPREMAP) Dynare Time Series & Reporting 11 June 2015 14 / 38
Time Series Syntax
Houtan Bastani (CEPREMAP) Dynare Time Series & Reporting 11 June 2015 15 / 38
Time Series Syntax
dseries Syntax
Houtan Bastani (CEPREMAP) Dynare Time Series & Reporting 11 June 2015 17 / 38
Time Series Syntax
ts is a dseries object:
| MyVar1 | MyVar2
1999Y | 1 | 2
2000Y | 3 | 4
2001Y | 5 | 6
Houtan Bastani (CEPREMAP) Dynare Time Series & Reporting 11 June 2015 18 / 38
Time Series Syntax
Load series from CSV/spreadsheet (.csv, .xls) or Matlab file (.m, .mat)
• Syntax:
>> ts = dseries(FILENAME);
• File format (.csv, .xls): dates (optional) in first column (using the
standard format: 1990Q1 for quarterly data, 1990Y for annual data, . . . ) and
variable names (optional) in the first row
• File format (.m, .mat): variables INIT , NAMES , and TEX are optional.
More info in the manual. Data are vectors.
INIT__ = ‘1999q1’;
NAMES__ = {‘cons’};
cons = randn(100,1);
Houtan Bastani (CEPREMAP) Dynare Time Series & Reporting 11 June 2015 20 / 38
Time Series Syntax
• Let
>> ts = dseries(randn(5,6), ‘2000q1’, ...
{‘GDP_US’, ‘GDP_FR’, ‘GDP_JA’, ...
‘CPI_US’, ‘CPI_FR’, ‘CPI_JA’});
Houtan Bastani (CEPREMAP) Dynare Time Series & Reporting 11 June 2015 21 / 38
Time Series Syntax
Houtan Bastani (CEPREMAP) Dynare Time Series & Reporting 11 June 2015 22 / 38
Time Series Syntax
Merging dseries
• Suppose that ts and ds are two dseries objects with the same variables
observed on different time ranges. These dseries objects can be merged
using the following syntax:
vs = [ts; ds];
• Suppose that ts and ds are two dseries objects with different variables
observed on the same or different time ranges. These dseries objects can
be merged using the following syntax:
vs = [ts, ds];
If ts and ds are not defined over the same time range, the time range of vs
will be the union of ts.dates and ds.dates, NaNs will be added for the
missing observations.
Houtan Bastani (CEPREMAP) Dynare Time Series & Reporting 11 June 2015 23 / 38
Time Series Syntax
• Let
>> ts = dseries([1:4]’);
• Then
>> ts.lead() >> ts.lag()
| lead(Variable_1,1) | lag(Variable_1,1)
1Y | 2 1Y | NaN
2Y | 3 2Y | 1
3Y | 4 3Y | 2
4Y | NaN 4Y | 3
Houtan Bastani (CEPREMAP) Dynare Time Series & Reporting 11 June 2015 25 / 38
Time Series Syntax
Houtan Bastani (CEPREMAP) Dynare Time Series & Reporting 11 June 2015 26 / 38
Reporting
Outline
1 Time Series
2 Reporting
Overview
Syntax
Houtan Bastani (CEPREMAP) Dynare Time Series & Reporting 11 June 2015 27 / 38
Reporting Overview
Overview
Houtan Bastani (CEPREMAP) Dynare Time Series & Reporting 11 June 2015 29 / 38
Reporting Overview
• Class names on the top half of the box, constructor names on the bottom
• Arrows represent what the new object can be added to; objects in green are
treated a bit differently (explained below)
Report
report(...);
Page
addPage(...);
Section
addSection(...);
Series
addSeries(...);
Houtan Bastani (CEPREMAP) Dynare Time Series & Reporting 11 June 2015 30 / 38
Reporting Syntax
Houtan Bastani (CEPREMAP) Dynare Time Series & Reporting 11 June 2015 31 / 38
Reporting Syntax
Houtan Bastani (CEPREMAP) Dynare Time Series & Reporting 11 June 2015 32 / 38
Reporting Syntax
Houtan Bastani (CEPREMAP) Dynare Time Series & Reporting 11 June 2015 33 / 38
Reporting Syntax
Output
To create a report:
• write(): Writes the report to a LATEX file
• compile(...): Compiles the report, creating a .pdf file
• Options: compiler
Report Output
• Unless you pass the fileName option to report(...), the report will be
located in your working directory with the name report.tex. The compiled
version will be called report.pdf.
• Unless you pass the graphDirName or graphName options to
addGraph(...), your graphs will be in a subdirectory of your working
directory called tmpRepDir. The default name will take the form
graph pg9 sec1 row1 col5.tex
• The same holds for the tables (substituting ‘table’ for ‘graph’ above).
• Thus you can easily modify these files and include them in another report.
Houtan Bastani (CEPREMAP) Dynare Time Series & Reporting 11 June 2015 34 / 38
Putting it All Together
Outline
1 Time Series
2 Reporting
Houtan Bastani (CEPREMAP) Dynare Time Series & Reporting 11 June 2015 35 / 38
Putting it All Together
Houtan Bastani (CEPREMAP) Dynare Time Series & Reporting 11 June 2015 36 / 38
Putting it All Together
Populate Report
r = report();
@#for shock in ["e", "u"]
r = r.addPage(‘title’,{‘Dseries/Report Example’,‘Shock @{shock}’},...
‘titleFormat’, {‘\Large\bfseries’, ‘\large\bfseries’});
r = r.addSection(‘cols’, 2);
@# for var in endovars
r = r.addGraph(‘data’, shock@{shock}.@{var}, ‘title’, ‘@{var}’, ...
‘showGrid’, false, ‘yTickLabelPrecision’, 2, ...
‘yTickLabelZeroFill’, false, ...
‘showZeroLine’, true, ‘zeroLineColor’, ’red’);
@# endfor
r = r.addVspace(‘number’, 2);
r = r.addSection(‘cols’, 1);
r = r.addTable(‘range’, 2022q1:2024q1, ‘precision’, 5);
@# for var in endovars
r = r.addSeries(‘data’, shock@{shock}.@{var});
@# endfor
@#endfor
Houtan Bastani (CEPREMAP) Dynare Time Series & Reporting 11 June 2015 37 / 38
Putting it All Together
Compile Report
r.write();
r.compile();
Output Files
>> ls report.*
report.aux report.log report.pdf report.synctex.gz report.tex
>> ls tmpRepDir/
graph_pg1_sec1_row1_col1.tex graph_pg2_sec1_row1_col1.tex
graph_pg1_sec1_row1_col2.tex graph_pg2_sec1_row1_col2.tex
graph_pg1_sec1_row2_col1.tex graph_pg2_sec1_row2_col1.tex
graph_pg1_sec1_row2_col2.tex graph_pg2_sec1_row2_col2.tex
graph_pg1_sec1_row3_col1.tex graph_pg2_sec1_row3_col1.tex
graph_pg1_sec1_row3_col2.tex graph_pg2_sec1_row3_col2.tex
table_pg1_sec2_row1_col1.tex table_pg2_sec2_row1_col1.tex
Houtan Bastani (CEPREMAP) Dynare Time Series & Reporting 11 June 2015 38 / 38