Commit a8107e15 authored by Marco Ratto's avatar Marco Ratto Committed by Stéphane Adjemian
Browse files

added new annual aggregation types, for consistent quantity/price aggregations, if required.

parent cb3362b8
function [ya, yass, gya, gyass] = quarterly2annual(y,yss,GYTREND0,type,islog)
% function [ya, yass, gya, gyass] = quarterly2annual(y,yss,GYTREND0,type,islog)
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.
%
......@@ -11,8 +11,13 @@ function [ya, yass, gya, gyass] = quarterly2annual(y,yss,GYTREND0,type,islog)
% 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
% islog 0 level (default)
% 1 log-level
% aux optional input used when type>4
%
%
% OUTPUTS
% ya annual (log-)level
......@@ -48,30 +53,75 @@ 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
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
[yna, ynass] = quarterly2annual(y.*yaux,yss.*yauxss,GYTREND0+GYTREND0aux,typeaux,0,0);
% real series
[yra, yrass] = quarterly2annual(yaux,yauxss,GYTREND0aux,typeaux,0,0);
% deflator
yass = ynass/yrass;
ya = yna./yra;
case 6
% nominal series
[yna, ynass] = quarterly2annual(y.*yaux,yss.*yauxss,GYTREND0+GYTREND0aux,typeaux,0,0);
% deflator
[pa, pass] = quarterly2annual(yaux,yauxss,GYTREND0aux,2,0,0);
% real series
yass = ynass/pass;
ya = yna./pa;
case 7
% nominal series
[ya, yass] = quarterly2annual(y.*yaux,yss.*yauxss,GYTREND0+GYTREND0aux,typeaux,0,0);
GYTREND0=GYTREND0+GYTREND0aux;
otherwise
error('Wrong type input')
end
ya = tmp(4:4:end);
% annual growth rate
gyass = GYTREND0*4;
gya = (ya+yass)./(lagged(ya,1)+yass).*exp(4*GYTREND0)-1-gyass;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment