## Check stationarity of VAR

Questions and discussions on Vector Autoregressions

### Check stationarity of VAR

I would like to implement a code to check whether the VAR is stationary or not. Given the VAR,

A(L)y_t = e_t

If the VAR is stationary, then det(A(z)) = 0 has all roots that lie outside unit circle. However, if one of the roots lies inside the unit circel, then the VAR is said to be non-stationary. I would like to implement a code to check the stationarity according to the rule.

The equation involves determinant of matrix which depends on z. I think of using %det to implement the code. However, the matrix considered depends on z, so it involves other commands as well. Is there any short command to implement this? Or I need to consider some other kinds of numerical methods to solve the problem?

dennis0125hk

Posts: 15
Joined: Thu Apr 09, 2009 8:17 am

### Re: Check stationarity of VAR

Check out kpsw1.prg in the King, Plosser, Stock, Watson AER 1991 replication. It uses

eigen(cvalues=cvt) %modelcompanion(v3)

to get the eigenvalues of the companion matrix for the model, which is the set of roots (actually reciprocals of the roots) that you want.
TomDoan

Posts: 2725
Joined: Wed Nov 01, 2006 5:36 pm

### Re: Check stationarity of VAR

It's good to know that RATS allows for that, though it would be great if there was a dedicated function for this.

dennis0125hk were you able to draft your function ?
apollon

Posts: 17
Joined: Thu Sep 30, 2010 8:01 am

### Re: Check stationarity of VAR

The problem you have is that the working definition of "stationary" can vary from situation to situation. Due to the possibility of roundoff error, a hard cut-off of 1.0 isn't a good idea. The typical cutoff choice is around .99 or .999, such as the following:

Code: Select all
`   compute testroot=%modelcompanion(qualvar)   eigen(cvalues=cv) testroot   if %cabs(cv(1))>.999 {      disp "VAR draw rejected"      goto redraw   }`

The following will return the absolute value of the dominant root of a model, which you can then test as you need.

Code: Select all
`function %ModelLargestRoot modeltype model model*local vect[complex] cveigen(cvalues=cv) %modelcompanion(model)compute %ModelLargestRoot=%cabs(cv(1))end`
TomDoan

Posts: 2725
Joined: Wed Nov 01, 2006 5:36 pm

### Re: Check stationarity of VAR

Thanks so much for your promt reply. That would seem to be what I'm looking for.
I couldn't find kpsw1.prg anywhere though, can you pls advise ?
apollon

Posts: 17
Joined: Thu Sep 30, 2010 8:01 am

### Re: Check stationarity of VAR

It's in one of the paper replication folders: KPSW AER 1991
TomDoan

Posts: 2725
Joined: Wed Nov 01, 2006 5:36 pm

### Re: Check stationarity of VAR

I got this now. Can you pls advise how to incorporate the two pieces of code you wrote into KPSW1.PRG ?
I tried by copying and pasting the first by changing model to v3 and I didn't see any output.
The second was giving me the error that "CV is not a PROCEDURE/FUNCTION Parameter". I then took it out
and pasted this line under your code: %ModelLargestRoot v3. I am now getting "Expected Instruction Here".
apollon

Posts: 17
Joined: Thu Sep 30, 2010 8:01 am

### Re: Check stationarity of VAR

Sorry. I corrected the function above - it should have been local ... cv, not type ... cv

You would use it as follows (regarding the earlier test)

if %ModelLargestRoot(qualvar)>.999 {
disp "VAR draw rejected"
goto redraw
}
TomDoan

Posts: 2725
Joined: Wed Nov 01, 2006 5:36 pm

### Re: Check stationarity of VAR

It still doesn't produce any output. Below is my modified var_1_2.prg:

Code: Select all
`function %ModelLargestRoot modeltype model model*local vect[complex] cveigen(cvalues=cv) %modelcompanion(model)compute %ModelLargestRoot=%cabs(cv(1))endopen data e1.datcalendar(q) 1960data(format=prn,org=columns,skips=6) 1960:01 1982:04 invest income cons*set dinc  = log(income/income{1})set dcons = log(cons/cons{1})set dinv  = log(invest/invest{1})*system(model=varmodel)variables dinv dinc dconslags 1 2det constantend(system)estimate(resids=unresids) * 1978:4if %ModelLargestRoot(varmodel)>.001 {disp "VAR draw rejected"goto redraw}dis %ModelLargestRoot(varmodel)`
apollon

Posts: 17
Joined: Thu Sep 30, 2010 8:01 am

### Re: Check stationarity of VAR

Your function is working fine; you're just taking code out of a more complicated procedure which, for instance, has a "redraw" label. Just get rid of your faulty

if %ModelLargestRoot(varmodel)>.001 {
disp "VAR draw rejected"
goto redraw
}

and just leave the DISPLAY instruction at the end, and you'll see that it works correctly.
TomDoan

Posts: 2725
Joined: Wed Nov 01, 2006 5:36 pm