** This program estimates the degrees of freedom of student-t innovations.
all 0  792:1
open data sp500.dat
data(org=obs) / rt 
set h = 0.0
nonlin mu a0 a1 b1 v 
frml at = rt(t)-mu 
frml gvar = a0+a1*at(t-1)**2+b1*h(t-1)                                
frml tt = at(t)**2/(h(t)=gvar(t))   
frml tln = %LNGAMMA((v+1)/2.)-%LNGAMMA(v/2.)-0.5*log(v-2.)
frml garchln = tln-((v+1)/2.)*log(1.0+tt(t)/(v-2.0))-0.5*log(h(t)) 
smpl  2 792
eval v = 10
eval a1 = 0.1
eval b1 = 0.6
eval mu = 0.01
eval a0 = 0.01
maximize(method=bhhh,recursive,iterations=150) garchln 
set fv = gvar(t)                                                      
set resid = at(t)/sqrt(fv(t)) 
set residsq = resid(t)*resid(t) 
*** 
*** Checking standardized residuals ***
cor(qstats,number=20,span=10) resid 
*** Checking squared standardized residuals ***
cor(qstats,number=20,span=10) residsq 
*** Last few observations needed for forecasts ***
set shock = at(t) 
print   786  792 rt shock fv