|
new;
cls;
@ Here the matrix y (nx1) @
load y[]=y.txt;
load c[]=c.txt;
load i[]=i.txt;
ipi=y~c~i;
n=cols(ipi);
hp=ipi[2:rows(y),.]~ipi[1:rows(y)-1,.];
dly=100*ln(hp[.,1:n]./hp[.,n+1:2*n]);
"";"";"";"";"";"";"";
"**********************************************************************";"";
" Choosing the order of the VAR (p)";"";
" Enter maximun number of lags you want for the model (p.max): ";"";
"**********************************************************************";
@ Some parameters of interest @
pmax=con(1,1); @ pmax is the maximum lag-length @
n=cols(dly); @ n is the dimension of the VAR @
nk=pmax+1; @ nk is the first obs for which
OLS is calculated @
capt=rows(dly); @ capt is the original sample size @
captst=capt-pmax; @ captst is the effective sample size @
resul=zeros(pmax,4); @ result will include the AIC, BIC and HQ
for each lag p @
ome=zeros(n,n); @ ome will include the VARCOV matrix @
@ OLS estimate of VARCOV @
p=1;
reg=ones(captst,1);
do until p>pmax;
err=zeros(captst,n);
reg=reg~dly[nk-p:capt-p,.]; @ reg is the matrix of
regressors @
k=n+(n*n*p); @ k is the total number of
param. to be estimated @
i=1;
do until i>n;
Dy=dly[nk:capt,i];
err[.,i]=Dy-reg*inv(reg'reg)*reg'Dy;
i=i+1;
endo;
r=1;
do until r>n;
c=1;
do until c>n;
den=captst-k;
ome[r,c]=(1/den)*(err[.,r]'err[.,c]);
c=c+1;
endo;
r=r+1;
endo;
aka=ln(det(ome))+(2*(n^2)*p/captst);
sch=ln(det(ome))+(ln(captst)*(n^2)*p/captst);
hq=ln(det(ome))+(2*ln(ln(captst))*(n^2)*p/captst);
resul[p,.]=p~aka~sch~hq;
p=p+1;
endo;
@ Output files @
output file=AIC.txt reset;
resul[.,2]-1;
output off;
output file=BIC.txt reset;
resul[.,3];
output off;
output file=HQ.txt reset;
resul[.,4]+1;
output off;
@ Results @
cls;
" ";
" p Akaike Schwartz Hanan & Quinn ";
resul;
" ";
end;
|