Using the SSTAT command

Use this forum to post questions about syntax problems or general programming issues. Questions on implementing a particular aspect of econometrics should go in "Econometrics Issues" below.
alex600
Posts: 6
Joined: Wed Aug 07, 2013 10:26 am

Using the SSTAT command

Unread post by alex600 »

I have the following code that I am using to create rolling MGARCH regressions, I need to calculate the covariance for the four variables each time through. My SSTAT equation returns "NA". Any help will be appreciated. My code is below.

Code: Select all

compute width=1305
do begin=2001:01,2002:01,22
*
lin(noprint,define=Cash1) dls1 ; # constant
lin(noprint,define=Futures1) dlf1 ; # constant
lin(noprint,define=Cash2) dls2 ; # constant
lin(noprint,define=Futures2) dlf2 ; # constant
group macro Cash1 Futures1 Cash2 Futures2

garch(noprint,p=1,q=1,rvectors=resids0,mvhmatricies=ht0,model=macro,mv=bekk, $
  iterations=500,subiterations=100,cvcrit=0.0001) begin begin+width
if %converged<>1;garch(noprint,p=1,q=1,rvectors=resids0,mvhmatricies=ht0,model=macro,mv=bekk, $
  iterations=1500,subiterations=500,cvcrit=0.000001,hessian=%xx,      $
  initial=%BETA) begin begin+width
if %converged<>1;garch(noprint,p=1,q=1,rvectors=resids0,mvhmatricies=ht0,model=macro,mv=bekk, $
  iterations=1500,subiterations=500,cvcrit=0.000001,hessian=%xx,      $
  initial=%BETA) begin begin+width
if %converged<>1;garch(noprint,p=1,q=1,rvectors=resids0,mvhmatricies=ht0,model=macro,mv=bekk, $
  iterations=2500,subiterations=1000,cvcrit=0.0001,hessian=%xx,      $
  initial=%BETA) begin begin+width

*
  dis %datelabel(begin)
  if %converged<>1;dis 'Model did not converge'
  if %converged==1;dis 'Model converged'
  com AIC = -2.*%funcval + 2.0*%nreg/%nobs
  com HQC = -2.*%funcval + %nreg*2.0*log(log(%nobs))/%nobs
  com SBC = -2.*%funcval + %nreg*log(%nobs)/%nobs
  set OHR_euro = ht0(2,1)/ht0(2,2)
  stat(noprint) OHR_euro
  dis 'OHR Euro     '  %mean
  set OHR_urals = ht0(4,3)/ht0(4,4)
  stat(noprint) OHR_urals
  dis 'OHR URALS    ' %mean
  com s = sqrt(%variance/%nobs)
  com tratio = %mean/s
  dis 'Log Likelihood =' %FUNCVAL
dis 'T-stat' tratio '  aic = ' aic ' hqc = ' hqc '  and sbc = ' sbc

stat(noprint) dls1
com m1=%mean
stat(noprint) dlf1
com m2=%mean
stat(noprint) dls2
com m3=%mean
stat(noprint) dlf2
com m4=%mean
dis m1 m2 m3 m4

SSTAT / (m1)*(m3)*(ht0(2,4))+(m1)*(m4)*(ht0(2,3))+(m2)*(m3)*(ht0(1,4))+(m2)*(m4)*(ht0(1,3))  $
+(m1)*(dls2-dls2{1})*(dlf1-dlf1{1})*(dlf2-dlf2{1})+(m2)*(dls1-dls1{1})*(dls2-dls2{1})*(dlf2-dlf2{1})  $
+(m3)*(dls1-dls1{1})*(dlf1-dlf1{1})*(dlf2-dlf2{1})+(m4)*(dls1-dls1{1})*(dlf1-dlf1{1})*(dls2-dls2{1})  $
-(ht0(1,2))*(ht0(3,4))>>COV4
dis COV4
end do
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Using the SSTAT command

Unread post by TomDoan »

Because SSTATS is designed to be applied to potentially multiple target expressions, it's a bit fussier about ranges than (for instance) a single STATISTICS instruction. One question is what range you actually want to use for many of those calculations. For instance, for the following:

Code: Select all

stat(noprint) dls1
com m1=%mean
stat(noprint) dlf1
com m2=%mean
stat(noprint) dls2
com m3=%mean
stat(noprint) dlf2
com m4=%mean
dis m1 m2 m3 m4
all those STATISTICS instructions will be applied to the full available range. However, those are inside the DO loop, so I'm guessing that you really want them restricted to the same range as the GARCH instructions. You could do those with a single SSTATISTICS with

SSTATS(mean) %regstart() %regend() dls1>>m1 dlf1>>m2 dls2>>m3 dlf2>>m4
dis m1 m2 m3 m4

The final SSTATS would be revised to

SSTAT %regstart()+1 %regend() (m1)*(m3)*(ht0(2,4))+(m1)*(m4)*(ht0(2,3))+(m2)*(m3)*(ht0(1,4))+(m2)*(m4)*(ht0(1,3)) $
+(m1)*(dls2-dls2{1})*(dlf1-dlf1{1})*(dlf2-dlf2{1})+(m2)*(dls1-dls1{1})*(dls2-dls2{1})*(dlf2-dlf2{1}) $
+(m3)*(dls1-dls1{1})*(dlf1-dlf1{1})*(dlf2-dlf2{1})+(m4)*(dls1-dls1{1})*(dlf1-dlf1{1})*(dls2-dls2{1}) $
-(ht0(1,2))*(ht0(3,4))>>COV4

to take into account the lost data point due to the lags (did you want the MEAN option on that as well?)
alex600
Posts: 6
Joined: Wed Aug 07, 2013 10:26 am

Re: Using the SSTAT command

Unread post by alex600 »

Thanks for your help. I will have to think about whether I need to adjust the mean for the lost observation.

My final calculation is as follows:

set OHR = COV4 / (ht0(2,4))
dis " OHR = " OHR

I get this

OHR = DISPLAY cannot show SERIES[REAL]

It doesn't like me dividing the covariance that I calculated (COV4) by the covariance of two of my variables ht0(2,4). Any thoughts?
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Using the SSTAT command

Unread post by TomDoan »

You can't DISPLAY a series. Use PRINT instead.

Is COV4 supposed to be fixed across time (given an estimation interval)?
alex600
Posts: 6
Joined: Wed Aug 07, 2013 10:26 am

Re: Using the SSTAT command

Unread post by alex600 »

Tom,

I was headed in the wrong direction, I don need to use SSTAT, I need to calculate the covariance at each observation. My formula is as follows:

set COV4=(%beta(1))*(%beta(3))*ht0(2,4)+(%beta(1))*(%beta(4))*ht0(2,3)+(%beta(2))*(%beta(3))*ht0(1,4)+(%beta(2))*(%beta(4))*ht0(1,3) $
+(%beta(1)))*(spot2-%beta(3))*(fut1-%beta(2))*(fut2-%beta(4))+(%beta(2))*(spot1-%beta(1))*(spot2-%beta(3))*(fut2-%beta(4)) $
+(%beta(3))*(spot1-%beta(1))*(fut1-%beta(2))*(fut2-%beta(4))+(%beta(4))*(spot1-%beta(1))*(fut1-%beta(2))*(spot2-%beta(3)) $
-ht0(1,2)*ht0(3,4)

I need to multiply the intercept terms by various covariances, which are series, in the first part of the equation and then the residuals are multiplied by the covariances in the second part. I can't figure out how to multiply a whole number by each observation in the covariance series.

Thanks,
Marty
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Using the SSTAT command

Unread post by TomDoan »

alex600 wrote:Tom,

I was headed in the wrong direction, I don need to use SSTAT, I need to calculate the covariance at each observation. My formula is as follows:

set COV4=(%beta(1))*(%beta(3))*ht0(2,4)+(%beta(1))*(%beta(4))*ht0(2,3)+(%beta(2))*(%beta(3))*ht0(1,4)+(%beta(2))*(%beta(4))*ht0(1,3) $
+(%beta(1)))*(spot2-%beta(3))*(fut1-%beta(2))*(fut2-%beta(4))+(%beta(2))*(spot1-%beta(1))*(spot2-%beta(3))*(fut2-%beta(4)) $
+(%beta(3))*(spot1-%beta(1))*(fut1-%beta(2))*(fut2-%beta(4))+(%beta(4))*(spot1-%beta(1))*(fut1-%beta(2))*(spot2-%beta(3)) $
-ht0(1,2)*ht0(3,4)

I need to multiply the intercept terms by various covariances, which are series, in the first part of the equation and then the residuals are multiplied by the covariances in the second part. I can't figure out how to multiply a whole number by each observation in the covariance series.
As you have this written, COV4 will be a series generated using the elements of HT0, the SPOTx and FUTx series, and the GARCH coefficients. Is that what you want? (Note that you're missing a space between set COV4 and =).
alex600
Posts: 6
Joined: Wed Aug 07, 2013 10:26 am

Re: Using the SSTAT command

Unread post by alex600 »

Yes, I'm trying to create a series of conditional covariances of all four variables.

I added the space and got:

## SX22. Expected Type SERIES[REAL], Got RECTANGULAR[REAL] Instead
>>>>set COV4 <<<<

Do I need a different operator to multiply a constant by a series?
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Using the SSTAT command

Unread post by TomDoan »

No. The problem is that somewhere earlier you've done something that's defined COV4 as a matrix, rather than a series.
alex600
Posts: 6
Joined: Wed Aug 07, 2013 10:26 am

Re: Using the SSTAT command

Unread post by alex600 »

I'm working on a similar rolling MGARCH regression but I am now using observation numbers in place of dates because I have too many missing values. My problem is that the window is not moving, the start date is the same in all my regressions. My goal is to run 1-year (width=250) regressions every six months over my data set. I have posted a portion of my code below.

Thanks,
Marty


compute width=250
do begin=2,1252,125
*
lin(noprint,define=Cash1) dspot1 ; # constant
lin(noprint,define=Futures1) dfut1 ; # constant
group macro Cash1 Futures1

garch(noprint,p=1,q=1,rvectors=resids0,mvhmatricies=ht0,model=macro,mv=bekk, $
iterations=500,subiterations=100,cvcrit=0.0001) begin begin+width
if %converged<>1;garch(noprint,p=1,q=1,rvectors=resids0,mvhmatricies=ht0,model=macro,mv=bekk, $
iterations=1500,subiterations=500,cvcrit=0.000001,hessian=%xx, $
initial=%BETA) begin begin+width
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Using the SSTAT command

Unread post by TomDoan »

You have a NOPRINT option on the GARCH, so how do you know that the window isn't "moving"? (BTW, as this is written it has to be moving).

These can (and should) be outside the loop. Now as those are written they will run over the same range each time, but since you never use those, it won't matter.

lin(noprint,define=Cash1) dspot1 ; # constant
lin(noprint,define=Futures1) dfut1 ; # constant
group macro Cash1 Futures1
alex600
Posts: 6
Joined: Wed Aug 07, 2013 10:26 am

Re: Using the SSTAT command

Unread post by alex600 »

Thanks, my regressions are rolling properly. The new results were being added to the prior results. which looked like the window was increasing. I fixed that myself.

Marty
Post Reply