| 1 |
function [yact,yactmg,yactqg,yactCalyg,yactCal] = datactcon(xinput) |
| 2 |
% [yact,yactmg,yactqg,yactCalyg,yactCal] = datactcon(xinput) |
| 3 |
% Data-actual-conditions. Take the raw data xdata to mlog, mg, qg, and yg. |
| 4 |
% Note yact(mlog), yactqg, and yactCalyg corr. to myears, qyears, and yearsCal |
| 5 |
% |
| 6 |
% xdata=xinput{1}: data, all logged except R, U, etc. |
| 7 |
% nSample=xinput{2}: sample size (including lags or initial periods) |
| 8 |
% nSampleCal=xinput{3}: converting nSample to sample marked by calendar years; |
| 9 |
% actup=xinput{4}: periods for actual data (monthly) |
| 10 |
% actupq=xinput{5}: periods for actual data (quarterly) |
| 11 |
% actupy=xinput{6}: periods for actual data (calendar yearly) |
| 12 |
% vlist=xinput{7}: list of variables |
| 13 |
% vlistlog=xinput{8}: sub list of variables that are in log |
| 14 |
% vlistper=xinput{9}: sub list of variables that are in percent |
| 15 |
% q_m=xinput{10}: month or quarter in the model |
| 16 |
% forep=xinput{11}: forecast periods (monthly) |
| 17 |
% forepq=xinput{12}: quarters in the forecast period |
| 18 |
% forepy=xinput{13}: calendar years in the forecast period |
| 19 |
% Psuedo=xinput{14}: 1: Psuedo out-of-sample; 0: real time out-of-sample |
| 20 |
% qmEnd=xinput{15}: last month (or quarter) of the sample |
| 21 |
%------------- |
| 22 |
% yact: (actup+forep*Psuedo)-by-nvar; log(y) except R, ect. (monthly). |
| 23 |
% Begin: nSample-actup+1; End: nSample+forep*Psuedo. Match dates myears |
| 24 |
% yactmg: (size(yact,1)-1)-by-nvar; month-to-month annualized growth for actual data. |
| 25 |
% Begin: nSample-actup+2; End: nSample+forep*Psuedo. Match dates "myears(2:end)" |
| 26 |
% yactqg: prior-quarter annualized growth for actual data |
| 27 |
% Match dates "qyears." |
| 28 |
% yactCalyg: annual growth for actual data |
| 29 |
% Match dates "yearsCal." |
| 30 |
% yactCal: weirdo -- seldom used. Same as yact but ends at the end of the |
| 31 |
% last calendar year. If Psuedo, it includes some actual data in |
| 32 |
% the 1st forecast calendar year. I haven't found the use of this weirdo. |
| 33 |
% |
| 34 |
% Written by Tao Zha March 1998 |
| 35 |
% Revised, October 1998 |
| 36 |
% |
| 37 |
% Copyright (C) 1997-2012 Tao Zha |
| 38 |
% |
| 39 |
% This free software: you can redistribute it and/or modify |
| 40 |
% it under the terms of the GNU General Public License as published by |
| 41 |
% the Free Software Foundation, either version 3 of the License, or |
| 42 |
% (at your option) any later version. |
| 43 |
% |
| 44 |
% It is distributed in the hope that it will be useful, |
| 45 |
% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 46 |
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 47 |
% GNU General Public License for more details. |
| 48 |
% |
| 49 |
% If you did not received a copy of the GNU General Public License |
| 50 |
% with this software, see <http://www.gnu.org/licenses/>. |
| 51 |
% |
| 52 |
|
| 53 |
|
| 54 |
xdata=xinput{1}; nSample=xinput{2}; nSampleCal=xinput{3}; |
| 55 |
actup=xinput{4}; actupq=xinput{5}; actupy=xinput{6}; vlist=xinput{7}; |
| 56 |
vlistlog=xinput{8}; vlistper=xinput{9}; q_m=xinput{10}; forep=xinput{11}; |
| 57 |
forepq=xinput{12}; forepy=xinput{13}; Psuedo=xinput{14}; qmEnd=xinput{15}; |
| 58 |
|
| 59 |
%-------------------------------------- |
| 60 |
% Monthly log, acutal data |
| 61 |
% yact the way it is and yactCal ends at the end of calendar year |
| 62 |
%---------------------------------------- |
| 63 |
yact = xdata(nSample-actup+1:nSample+forep*Psuedo,:); |
| 64 |
% actup (not calendar) months + forep |
| 65 |
yactCal = xdata(nSampleCal-actupy*q_m+1:nSampleCal+forepy*q_m*Psuedo,:); |
| 66 |
% calendar years |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
%--------------------------------------------------------------- |
| 72 |
% Actual monthly growth rate, Prior quarter, and calendar yearly change |
| 73 |
%--------------------------------------------------------------- |
| 74 |
% |
| 75 |
%@@@ Monthly change (annaluized rate) |
| 76 |
% |
| 77 |
yactm = yact; |
| 78 |
mT1 = length(yact(:,1)); |
| 79 |
% |
| 80 |
yactmg = yactm(2:mT1,:); % start at second month to get growth rate |
| 81 |
yactmg(:,vlistlog) = (yactm(2:mT1,vlistlog) - yactm(1:mT1-1,vlistlog)) .* q_m; |
| 82 |
% monthly, 12*log(1+growth rate), annualized growth rate |
| 83 |
yactmg(:,vlistlog) = 100*(exp(yactmg(:,vlistlog))-1); |
| 84 |
yactmg(:,vlistper) = 100*yactmg(:,vlistper); |
| 85 |
|
| 86 |
% |
| 87 |
%@@@ Prior Quarter change (annaluized rate) |
| 88 |
% |
| 89 |
yactQ = xdata(nSample-mod(qmEnd,3)-actupq*3+1:nSample-mod(qmEnd,3)+forepq*3*Psuedo,:); |
| 90 |
yactq = zeros(actupq+forepq*Psuedo,length(vlist)); |
| 91 |
% |
| 92 |
qT1 = length(yactQ(:,1))/3; |
| 93 |
qT1a = length(yactq(:,1)); |
| 94 |
if qT1 ~= qT1a |
| 95 |
warning('line #') |
| 96 |
error('qT1: Beginings or ends of monthly and quarterly series do not match!') |
| 97 |
end |
| 98 |
% |
| 99 |
for i = 1:qT1 |
| 100 |
i1 = 1+3*(i-1); |
| 101 |
i2 = 3*i; |
| 102 |
yactq(i,:) = sum(yactQ(i1:i2,:)) ./ 3; |
| 103 |
end |
| 104 |
% |
| 105 |
yactqg = yactq(5:qT1,:); % 4+1=5 where 4 means 4 quarters |
| 106 |
yactqg(:,vlistlog) = (yactq(5:qT1,vlistlog) - yactq(4:qT1-1,vlistlog)) .* 4; |
| 107 |
% quarterly, 4*log(1+growth rate), annualized growth rate |
| 108 |
yactqg(:,vlistlog) = 100*(exp(yactqg(:,vlistlog))-1); |
| 109 |
yactqg(:,vlistper) = 100*yactqg(:,vlistper); |
| 110 |
|
| 111 |
% |
| 112 |
%@@@ Calendar year-over-year change |
| 113 |
% |
| 114 |
yactCaly = zeros(actupy+forepy*Psuedo,length(vlist)); |
| 115 |
% past "actupy" calendar years + forepy*Psuedo |
| 116 |
yT1 = length(yactCal(:,1))/q_m; |
| 117 |
yT1a = length(yactCaly(:,1)); |
| 118 |
if yT1 ~= yT1a |
| 119 |
warning('Line #') |
| 120 |
error('yT1: Beginings or ends of monthly and quarterly series are not the same!') |
| 121 |
end |
| 122 |
% |
| 123 |
for i = 1:yT1 |
| 124 |
i1 = 1+q_m*(i-1); |
| 125 |
i2 = q_m*i; |
| 126 |
yactCaly(i,:) = sum(yactCal(i1:i2,:)) ./ q_m; |
| 127 |
end |
| 128 |
% |
| 129 |
yactCalyg = yactCaly(2:yT1,:); % 1+1=2 where 1 means 1 year |
| 130 |
yactCalyg(:,vlistlog) = (yactCaly(2:yT1,vlistlog) - yactCaly(1:yT1-1,vlistlog)); |
| 131 |
% annual rate: log(1+growth rate) |
| 132 |
yactCalyg(:,vlistlog) = 100*(exp(yactCalyg(:,vlistlog))-1); |
| 133 |
yactCalyg(:,vlistper) = 100*yactCalyg(:,vlistper); |