Debian Codegraph @

tests/ecb/contribution-plots/contrib2.mod

raw
1 // --+ options: json=compute nostrict +--
2
3 /* REMARKS
4 ** -------
5 **
6 ** Please, firt read the content of contrib1.mod.
7 **
8 ** I consider the same model as in contrib1.mod, but here we want to obtain the contributions of
9 ** the variables to `ffr` at all lags (individually). To do this we need to add variables for all
10 ** the lags, add corresponding equations (defining the new variables) and add the new variables
11 ** in the dseries objects.
12 */
13
14 // Declaration of the endogenous variables
15 var ffr, unrate, cpi;
16
17 // Define additional variables
18 var ffr_lag_1, ffr_lag_2, ffr_lag_3, unrate_lag_1, cpi_lag_4;
19
20 // Declaration of the exogenous variables
21 varexo e_ffr, e_unrate, e_cpi;
22
23
24 // Declare the parameters appearing in the equation to be decomposed.
25 parameters p_ffr_ffr_lag_1 p_ffr_ffr_lag_2 p_ffr_ffr_lag_3 p_ffr_unrate_lag_1 p_ffr_unrate_lag_2 p_ffr_unrate_lag_4 p_ffr_unrate_lag_5 p_ffr_cpi_lag_4 p_unrate_cpi_lag_1 p_unrate_cpi_lag_2 p_unrate_cpi_lag_3 p_unrate_cpi_lag_4 p_unrate_cpi_lag_5 p_unrate_cpi_lag_6 p_cpi_ffr_lag_1 p_cpi_ffr_lag_2 p_cpi_cpi_lag_2;
26
27 // Declaration of the model. Note that you must associate a name to the equations. This is mandatory to
28 // select the equation for which you need to perform the decomposition.
29 model;
30
31 [name='ffr']
32 ffr = p_ffr_ffr_lag_1*ffr_lag_1 + p_ffr_ffr_lag_2*ffr_lag_2 + p_ffr_ffr_lag_3*ffr_lag_3
33 + p_ffr_unrate_lag_1*unrate_lag_1
34 + p_ffr_cpi_lag_4*cpi_lag_4;
35
36 [name='unrate']
37 unrate = unrate(-4)*p_ffr_unrate_lag_4 + unrate(-2)*p_ffr_unrate_lag_2 + unrate(-5)*p_ffr_unrate_lag_5 + cpi(-1)*p_unrate_cpi_lag_1 + cpi(-2)*p_unrate_cpi_lag_2 + cpi(-3)*p_unrate_cpi_lag_3 + cpi(-4)*p_unrate_cpi_lag_4 + cpi(-5)*p_unrate_cpi_lag_5 + cpi(-6)*p_unrate_cpi_lag_6;
38
39 [name='cpi']
40 cpi = ffr(-1)*p_cpi_ffr_lag_1 + ffr(-2)*p_cpi_ffr_lag_2 + cpi(-2)*p_cpi_cpi_lag_2;
41
42 // Definitions of the auxiliary variables (we don't need names for these equations).
43 ffr_lag_1 = ffr(-1);
44 ffr_lag_2 = ffr(-2);
45 ffr_lag_3 = ffr(-3);
46 unrate_lag_1 = unrate(-1);
47 cpi_lag_4 = cpi(-4);
48
49 end;
50
51 // Implicit parameters associated to the adl command must be calibrated after the model block.
52 p_ffr_ffr_lag_1 = 1;
53 p_ffr_ffr_lag_2 = p_ffr_ffr_lag_1*.5;
54 p_ffr_ffr_lag_3 = p_ffr_ffr_lag_2*.5;
55 p_ffr_unrate_lag_1 = 2;
56 p_ffr_cpi_lag_4 = 3;
57
58 // Actual paths for the variables. You migth instead do a stochastic simulation of the model
59 // to define these paths.
60 ds1 = dseries(randn(30, 3), 1990Q1, {'ffr', 'unrate', 'cpi'});
61
62 // Create auxiliary variables as dseries objects
63 verbatim;
64
65 ffr_lag_1 = dseries(ds1.ffr(-1).data, ds1.firstdate, 'ffr_lag_1');
66 ffr_lag_2 = dseries(ds1.ffr(-2).data, ds1.firstdate, 'ffr_lag_2');
67 ffr_lag_3 = dseries(ds1.ffr(-3).data, ds1.firstdate, 'ffr_lag_3');
68 unrate_lag_1 = dseries(ds1.unrate(-1).data, ds1.firstdate, 'unrate_lag_1');
69 cpi_lag_4 = dseries(ds1.cpi(-4).data, ds1.firstdate, 'cpi_lag_4');
70
71 end;
72
73 // Put them in ds1
74 ds1 = [ds1, ffr_lag_1, ffr_lag_2, ffr_lag_3, unrate_lag_1, cpi_lag_4];
75
76 // Baseline paths for the variables.
77 ds0 = dseries(zeros(30, 8), 1990Q1, {'ffr', 'unrate', 'cpi', 'ffr_lag_1', 'ffr_lag_2', 'ffr_lag_3', 'unrate_lag_1', 'cpi_lag_4'});
78
79 /* Trigger the decomposition in levels of an equation
80 **
81 ** - First argument (ffr) is the name of the equation to be decomposed.
82 ** - Second argument (ds1) is a dseries object containing the actual paths of the endogenous and exogenous variables.
83 ** - Third argument (ds0) is a dseries object containing the baseline paths of the endogenous and exogenous variables.
84 **
85 ** If there is no error (missing variables, undefined equations, ...) a figure will pop up with displaying the
86 ** contributions of the variables appearing on the right hand side of equation `ffr`.
87 */
88
89 plot_contributions ffr ds1 ds0 ;