| 1 |
function [phi,y,ncoe] = mformd1(z,lags) |
| 2 |
% |
| 3 |
% [phi,y,ncoe] = mformd1(z,lags) where size(z,1)=T+lags. |
| 4 |
% This file is a subset of sye.m, but only designed to arrange matrix form data as |
| 5 |
% y(T*nvar) = XB + u, X--phi: T*k, B: k*nvar; where T=sp-lags, k=ncoe. |
| 6 |
% Note T>=0. If T=0, y is empty, but phi (X) is still well defined. |
| 7 |
% |
| 8 |
% z: (T+lags)-by-(nvar+1) raw data matrix (nvar of variables + constant). |
| 9 |
% e.g., C = ones(nSample,1); z=[xdget C]; |
| 10 |
% lags: number of lags |
| 11 |
% phi: (T-lags)-by-k X; where k=ncoe=[nvar for 1st lag, ..., nvar for last lag, const] |
| 12 |
% y: Y: (T-lags)-by-nvar |
| 13 |
% ncoe: number of coeffcients per equation: k=nvar*lags + 1 |
| 14 |
% |
| 15 |
% See also sye.m |
| 16 |
% |
| 17 |
% October 1998 Tao Zha. Revised, 03/13/99 |
| 18 |
% |
| 19 |
% Copyright (C) 1997-2012 Tao Zha |
| 20 |
% |
| 21 |
% This free software: you can redistribute it and/or modify |
| 22 |
% it under the terms of the GNU General Public License as published by |
| 23 |
% the Free Software Foundation, either version 3 of the License, or |
| 24 |
% (at your option) any later version. |
| 25 |
% |
| 26 |
% It is distributed in the hope that it will be useful, |
| 27 |
% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 28 |
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 29 |
% GNU General Public License for more details. |
| 30 |
% |
| 31 |
% If you did not received a copy of the GNU General Public License |
| 32 |
% with this software, see <http://www.gnu.org/licenses/>. |
| 33 |
% |
| 34 |
|
| 35 |
|
| 36 |
% ** setup of orders and lengths ** |
| 37 |
[sp,nvar] = size(z); % sp: sample period T include lags |
| 38 |
nvar = nvar-1; % -1: takes out the counting of constant |
| 39 |
|
| 40 |
ess = sp-lags; % effective sample size |
| 41 |
sb = lags+1; % sample beginning |
| 42 |
sl = sp; % sample last period |
| 43 |
ncoe = nvar*lags + 1; % with constant |
| 44 |
|
| 45 |
% ** construct X for Y = X*B + U where phi = X ** |
| 46 |
if ess<0 |
| 47 |
warning('The length of the data must be >= lags') |
| 48 |
disp('Check yrEnd and qmEnd in parac.m to make sure') |
| 49 |
disp('Press ctrl-c to abort') |
| 50 |
disp(' ') |
| 51 |
pause |
| 52 |
elseif ess==0 |
| 53 |
x = z(:,1:nvar); |
| 54 |
C = z(:,nvar+1); |
| 55 |
phi = zeros(1,ncoe); |
| 56 |
phi(1,ncoe) = C(1); |
| 57 |
for k=1:lags, phi(1,nvar*(k-1)+1:nvar*k) = x(sb-k:sl-k+1,:); end |
| 58 |
% row: T-lags; column: [nvar for 1st lag, ..., nvar for last lag, const] |
| 59 |
% Thus, # of columns is nvar*lags+1 = ncoef. |
| 60 |
y = x(sb:sl,:); |
| 61 |
else |
| 62 |
x = z(:,1:nvar); |
| 63 |
C = z(:,nvar+1); |
| 64 |
phi = zeros(ess,ncoe); |
| 65 |
phi(:,ncoe) = C(1:ess); |
| 66 |
for k=1:lags, phi(:,nvar*(k-1)+1:nvar*k) = x(sb-k:sl-k,:); end |
| 67 |
% row: T-lags; column: [nvar for 1st lag, ..., nvar for last lag, const] |
| 68 |
% Thus, # of columns is nvar*lags+1 = ncoef. |
| 69 |
y = x(sb:sl,:); |
| 70 |
end |