File: quarterly2annual.m

package info (click to toggle)
dynare 6.3-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 67,632 kB
  • sloc: cpp: 79,090; ansic: 28,916; objc: 12,430; yacc: 4,528; pascal: 1,993; lex: 1,441; sh: 1,121; python: 634; makefile: 626; lisp: 163; xml: 18
file content (150 lines) | stat: -rw-r--r-- 4,668 bytes parent folder | download | duplicates (2)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
function [ya, yass, gya, gyass] = quarterly2annual(y,yss,GYTREND0,type,islog,aux)
% function [ya, yass, gya, gyass] = quarterly2annual(y,yss,GYTREND0,type,islog,aux)
% transforms quarterly (log-)level time series to annual level and growth rate
% it accounts for stock/flow/deflator series.
%
% INPUTS
% y        quarterly time series
% yss      steady state of y
% GYTREND0 growth rate of y
% type     1 sum (default)
%          2 average
%          3 last period (Q4)
%          4 geometric average
%          5 annual price as quantity weighted average
%          6 annual quantity from average price
%          7 annual nominal from Q real and deflator
%          8 annual ratio [e.g. trade balance to GDP]
% islog    0 level (default)
%          1 log-level
%          2 growth rate Q frequency
% aux      optional input used when type>4
%
%
% OUTPUTS
% ya       annual (log-)level
% yass     annual steadystate (log-)level
% gya      annual growth rate
% gyass    annual growth rate steadystate

% Copyright © 2017 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 nargin ==0
    disp('[ya, yass, gya, gyass] = quarterly2annual(y,yss,GYTREND0,type,islog);')
    return
end

if nargin<4 || isempty(type)
    type=1;
end
if nargin<5 || isempty(islog)
    islog=0;
end
if isstruct(aux)
    yaux=aux.y;
    yauxss=aux.yss;
    islogaux=aux.islog;
    GYTREND0aux=aux.GYTREND0;
    typeaux=aux.type;
    if islogaux
        yaux=exp(yaux+yauxss);
        yauxss=exp(yauxss);
        yaux=yaux-yauxss;
    end
elseif type > 4
    error('TYPE>4 requires auxiliary variable!')
end
if islog == 2
    % construct loglevel out of growth rate
    y = cumsum(y);
    yss=0;
    islog=1;
end
if islog == 1
    y=exp(y+yss);
    yss=exp(yss);
    y=y-yss;
end
switch type
  case 1
    yass = yss*(exp(-GYTREND0*3)+exp(-GYTREND0*2)+exp(-GYTREND0)+1);
    tmp = lagged(y,3)*exp(-GYTREND0*3)+lagged(y,2)*exp(-GYTREND0*2)+lagged(y,1)*exp(-GYTREND0)+y; % annualized level
    ya = tmp(4:4:end);
  case 2
    yass = yss*(exp(-GYTREND0*3)+exp(-GYTREND0*2)+exp(-GYTREND0)+1)/4;
    tmp = (lagged(y,3)*exp(-GYTREND0*3)+lagged(y,2)*exp(-GYTREND0*2)+lagged(y,1)*exp(-GYTREND0)+y)/4; % annualized level
    ya = tmp(4:4:end);
  case 3
    yass=yss;
    tmp = y;
    ya = tmp(4:4:end);
  case 4
    yass = yss*(exp(-GYTREND0*3/2));
    tmp = (lagged(y+yss,3)*exp(-GYTREND0*3).*lagged(y+yss,2)*exp(-GYTREND0*2).*lagged(y+yss,1)*exp(-GYTREND0).*(y+yss)).^(1/4); % annualized level
    tmp = tmp - yass;
    ya = tmp(4:4:end);
  case 5
    % nominal series
    yn = (y+yss).*(yaux+yauxss) - yss.*yauxss;
    [yna, ynass] = quarterly2annual(yn,yss.*yauxss,GYTREND0+GYTREND0aux,typeaux,0,0);
    % real series
    [yra, yrass] = quarterly2annual(yaux,yauxss,GYTREND0aux,typeaux,0,0);
    % deflator
    yass = ynass/yrass;
    ya = (yna+ynass)./(yra+yrass)-yass;
  case 6
    % nominal series
    yn = (y+yss).*(yaux+yauxss) - yss.*yauxss;
    [yna, ynass] = quarterly2annual(yn,yss.*yauxss,GYTREND0+GYTREND0aux,typeaux,0,0);
    % deflator
    [pa, pass] = quarterly2annual(yaux,yauxss,GYTREND0aux,2,0,0);
    % real series
    yass = ynass/pass;
    ya = (yna+ynass)./(pa+pass)-yass;
  case 7
    % nominal series
    yn = (y+yss).*(yaux+yauxss) - yss.*yauxss;
    [ya, yass] = quarterly2annual(yn,yss.*yauxss,GYTREND0+GYTREND0aux,typeaux,0,0);
    GYTREND0=GYTREND0+GYTREND0aux;

    case 8
        % numerator
        yn = y;
        [yna, ynass] = quarterly2annual(yn,yss,GYTREND0,typeaux(1),0,0);
        % denominator
        yd = yaux;
        [yda, ydass] = quarterly2annual(yd,yauxss,GYTREND0aux,typeaux(2),0,0);
        % ratio
        yass = ynass/ydass;
        ya = (yna+ynass)./(yda+ydass)-yass;    
        GYTREND0 = GYTREND0 - GYTREND0aux;

  otherwise
    error('Wrong type input')
end

% annual growth rate
% gyass = GYTREND0*4; % this is for log diff
gyass = exp(4*GYTREND0)-1; % this is for exact growth rate definition
gya = (ya+yass)./(lagged(ya,1)+yass).*exp(4*GYTREND0)-1-gyass;

if islog
    ya=log(ya+yass);
    yass=log(yass);
    ya=ya-yass;
end