Hi, I did some mistake in the program, after the correction, it doesn't work anymore.
- Code: Select all
OPEN DATA "data.txt"
CALENDAR(M) 1990
DATA(FORMAT=PRN,ORG=COLUMNS) 1990:01 2008:12 SATN TMIL APMA AUHS AUVE BSAI RP SMB HML
*
*
*
source markov.src
compute nstates=2
*
dec rect p(nstates-1,nstates)
*
dec vect pstar(nstates)
*
dec series[vect] pt_t pt_t1 psmooth
gset pt_t 1 2008:12 = %zeros(nstates,1)
gset pt_t1 1 2008:12 = %zeros(nstates,1)
gset psmooth 1 2008:12 = %zeros(nstates,1)
*
*
*
*
dofor y = SATN TMIL APMA AUHS AUVE BSAI
linreg(noprint,robust) y
# constant rp smb hml
*
compute olsvar=%seesq
compute olsbeta=%beta
*
*
garch(noprint, p=1,q=1,reg,resids=u,hseries=h) / y
# constant rp hml smb
compute onestate=%beta
*
set usqr = u**2/h
*
nonlin a01 a02 a11 a12 a21 a22 a31 a32 b01 b11 b21 b02 b12 b22 p
compute a01=%beta(1),a11=%beta(2),a21=%beta(3), a31=%beta(4), b01=olsvar,b11=0.0,b21=0.0
compute a02=%beta(1),a12=%beta(2),a22=%beta(3), a32=%beta(4), b02=%beta(5),b12=%beta(6),b22=%beta(7)
compute p=||.95,.05||
*
set uu = olsvar
set h = olsvar
*
*
function RegimeGARCHF t
type vector RegimeGARCHF
type integer t
local real hh1 hh2 mu1 mu2 mu
*
* Compute state dependent variances
*
compute hh1=b01+b11*uu(t-1)+b21*h(t-1)
compute hh2=b02+b12*uu(t-1)+b22*h(t-1)
*
* Compute state dependent means
*
compute mu1=a01+a11*rp(t)+a21*smb(t)+a31*hml(t)
compute mu2=a02+a12*rp(t)+a22*smb(t)+a32*hml(t)
*
* Compute the return vector (densities in the two states)
*
compute RegimeGARCHF=||%density((y(t)-mu1)/sqrt(hh1))/sqrt(hh1),$
%density((y(t)-mu2)/sqrt(hh2))/sqrt(hh2)||
*
* Compute the values of uu (squared residual) and h (variance) to be used for
* the period following
*
compute mu=mu1*pstar(1)+mu2*pstar(2)
compute uu(t)=(y(t)-mu)**2
compute h(t)=pstar(1)*(mu1**2+hh1)+pstar(2)*(mu2**2+hh2)-mu**2
end
*
inquire(series=y) first last
*
frml logl = f=RegimeGARCHF(t),$
pt_t1=%mcstate(p,pstar),pt_t=pstar=%msupdate(f,pt_t1,fpt),log(fpt)
*
nonlin a01 a02 a11 a12 a21 a22 a31 a32 b01 b11 b21 b02 b12 b22
maximize(start=(pstar=%mcergodic(p)),method=bfgs,iters=100,pmethod=simplex,piters=50) logl first last
end dofor
I got the error of "PROCEDURE/FUNCTION Must be Initial Statement in a Compiled Section". I also have tried to put the RegimeGarch Function before I start the loop, however, the error is "SX17. Missing Operator or Adjacent Operands >>>>RCHF=||%density((y(<<<<".
Your help is much appreciated.