各位高手,小弟有一个问题想请教,我用一个下载来的code要修改成我想要的,可是我发现,再p=pMAX的地方很怪,p值已经固定,所以跑出来的的SIC,AIC,和HQ皆为落后一期最好,这样是因为我的p直被固定的关西...那我到底要怎样修我的code,p值才不会固定呢...
还有 hp=ipi[2:rows(y),.]~ipi[1:rows(y)-1,.]; dly=100*ln(hp[.,1:n]./hp[.,n+1:2*n]); 是什么..
有人可以帮小弟解释吗...感谢各位大大的帮忙
/* Testing the VAR order selection */
new;
cls;
@ Here the matrix y (nx1) @
format 8,5;
load y[45,1]=y1;
load c[45,2]=c1;
ipi=y~c;
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=6; @ pmax为落后的期数 @
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;
x1=p[1,1];
@ 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;
在此小弟附上附檔,跪求各位高手请帮小弟解答!
[此贴子已经被作者于2008-4-18 16:07:12编辑过]


雷达卡





京公网安备 11010802022788号







