File: subst_auxvar.m

package info (click to toggle)
dynare 5.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 77,852 kB
  • sloc: cpp: 94,481; ansic: 28,551; pascal: 14,532; sh: 5,453; objc: 4,671; yacc: 4,442; makefile: 2,923; lex: 1,612; python: 677; ruby: 469; lisp: 156; xml: 22
file content (100 lines) | stat: -rw-r--r-- 3,882 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
function str = subst_auxvar(var_index, aux_lead_lag, M_)
% Given the index of an endogenous (possibly an auxiliary var), and a
% lead/lag, creates a string of the form "x(lag)".
% In the case of auxiliary vars for lags, replace by the original variable
% name, and compute the lead/lag accordingly.
% INPUTS
% - aux_index           [double]    index of auxiliary variable
% - aux_lead_lag        [double]    index for lead or lag
% - M_                  [struct]    model structure
%
% OUTPUTS
% - str                 [string]    name of auxiliary

% Copyright (C) 2001-2021 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare.  If not, see <https://www.gnu.org/licenses/>.

if var_index <= M_.orig_endo_nbr
    str = sprintf('%s(%d)', M_.endo_names{var_index}, aux_lead_lag);
    return
end
aux_index=find([M_.aux_vars(:).endo_index]==var_index);
if ~isempty(aux_index)
    switch M_.aux_vars(aux_index).type
        case 0
            % endo leads >= 2
            str = sprintf('%s(%d)', M_.endo_names{var_index}, aux_lead_lag);
            return
        case 1
            % endo lags >= 2
            orig_name = M_.endo_names{M_.aux_vars(aux_index).orig_index};
        case 2
            % exo leads >= 1
            orig_name = M_.exo_names{M_.aux_vars(aux_index).orig_index};
        case 3
            % exo lags >= 1
            orig_name = M_.exo_names{M_.aux_vars(aux_index).orig_index};
        case 4
            % Expectation operator
            str = sprintf('EXPECTATION(%d)(...)', aux_lead_lag);
            return
        case 6
            % Ramsey's multipliers
            if ~isempty(aux_lead_lag)
                str = sprintf('%s(%d)', M_.endo_names{M_.aux_vars(aux_index).endo_index}, aux_lead_lag);
            else
                str = sprintf('%s', M_.endo_names{M_.aux_vars(aux_index).endo_index});
            end
            return
        case 7
            % currently unused
            error('This type of auxiliary variable should not occur, please contact the developers.')
        case 8
            % Diff operator
            str = sprintf('diff(%s)', M_.endo_names{M_.aux_vars(aux_index).orig_index});
            return
        case 9
            % Lagged diff
            lags = 0;
            j = aux_index;
            while M_.aux_vars(j).type==9
                j = M_.aux_vars(j).orig_index;
                lags = lags+1;
            end
            str = sprintf('diff(%s(-%u))', M_.endo_names{M_.aux_vars(j).orig_index}, lags);
            return
        case 10
            % Variable created when diff was taken of unary operator (log, exp)
            error('This type of auxiliary variable should not occur, please contact the developers.')
        case 11
            % Leaded diff
            leads = 0;
            j = aux_index;
            while M_.aux_vars(j).type==11
                j = M_.aux_vars(j).orig_index;
                lags = lags+1;
            end
            str = sprintf('diff(%s(%u))', M_.endo_names{M_.aux_vars(j).orig_index}, leads);
            return
        otherwise
            error('Invalid auxiliary type: %s', M_.endo_names{var_index})
    end
    str = sprintf('%s(%d)', orig_name, M_.aux_vars(aux_index).orig_lead_lag+aux_lead_lag);
    return
else
    error('Could not find aux var: %s', M_.endo_names{var_index})
end