/*-------------------------------------------------------------------------- @ @ ABIC.PRC @ Purpose: Find the optimal lags by Akaike Information Criteria and @ Bayesian Information Criteria @ Written by Hyeongwoo Kim (Mar 13, 2004) @--------------------------------------------------------------------------- @ @ Format: abic(y,pmax); @ @ Input : y (nX1) univariate time series @ pmax (1X1) Maximum number of lag @ @ Output: None. It prints out all values @ First column is AIC values @ Second column is BIC values @ ---------------------------------------------------------------------------*/ proc (0) = abic(y,pmax); local lag,obs,non,i,yl,j,yd,rsd,ssq,xtic; lag = zeros(pmax,2); obs = rows(y); non = obs - pmax; i = 1; do until i>pmax; yl = ones(obs-i,i+1); j = 1; do until j>i; yl[.,j+1] = trimr(y,i-j,j); @ Keep first column for constant @ j = j+1; endo; yd = trimr(y,i,0); rsd = yd - yl*inv(yl'yl)*yl'yd; ssq = rsd'rsd; lag[i,1] = ln(ssq/non) + 2*(i+1)/non; @ AIC Value @ lag[i,2] = ln(ssq/non) + ln(non)*(i+1)/non; @ BIC Value @ i = i+1; endo; lag; @ Print the results @ library pgraph; graphset; _plctrl = { 1, 1 }; /* 2 curves w/symbols,*/ _pltype = { 1, 2 }; /* dashed, dotted, */ _pstype = { 1, 2}; /* symbol types */ _plegctl= { 2, 3, 1.7, 4.5 }; /* legend size and */ /* locations */ _plegstr= "AIC \0"\ "BIC"; ylabel("Value"); /* Y axis label */ xlabel("Number of Lags"); /* X axis label */ title("AIC/BIC"); /* main title */ xtic = seqa(1,1,pmax); xy(xtic,lag); endp;