!n=49 scalar lambda=6.25 smpl 1962 2010 series yseries=dlgdp series tauhat series sess series seas stom(yseries,y) ' Construct the K matrix matrix(!n-2,!n) K=0 for !i=1 to !n-2 for !j=1 to !n if !i = !j then k(!i,!j)=1 endif if !j = !i+2 then k(!i,!j) = 1 endif if !j=!i+1 then k(!i,!j) = -2 endif next next matrix kk=@transpose(k)*k*lambda matrix a =@identity(!n)+KK matrix tau=@inverse(a)*y mtos(tau,tauhat) series cycle=yseries-tauhat ' for simplicity, first assume that V(y) = scalar matrix scalar sigsq=@vars(y) matrix vs=@identity(!n)*sigsq matrix var_tauhats=@inverse(a)*vs*@inverse(a) matrix ses=@sqrt(@getmaindiagonal(var_tauhats)) mtos( ses, sess) series lowers=tauhat-1.96*sess series uppers=tauhat+1.96*sess ' now let's be more realistic and specify V(y) more appropriately. I've identified an AR(1) process for the series. ' construct V(y) scalar ssq=0.000392 scalar rho=0.411384 sym(!n) va for !i=1 to !n for !j=!i+1 to !n va(!i,!j)=rho^(!j-!i) next next for !i=1 to !n va(!i,!i)=1 next sym va=va*ssq/(1-rho^2) sym var_tauhata=@inverse(a)*va*@inverse(a) matrix sea=@sqrt(@getmaindiagonal(var_tauhata)) mtos( sea, seas) series lowera=tauhat-1.96*seas series uppera=tauhat+1.96*seas