Zivot-Andrews Unit Root Test

For posting your own programs to share with others

Moderators: EViews Gareth, EViews Moderator

Did you use forum search?
Posts: 1518
Joined: Thu Nov 20, 2008 12:04 pm

Zivot-Andrews Unit Root Test

Attached is a subroutine to carry out Zivot-Andrews procedure for testing unit root in the case of a single break in the series (i.e. level, trend or both). Please feel free the optimize the code further.

Code: Select all

`'Zivot-Andrews Unit Root Test'Reference: Zivot, E. and Andrews, D. W. K. (1992), “Further Evidence on the Great Crash, the Oil-Price Shock, and the Unit-Root Hypothesis”, Journal of Business & Economic Statistics, Vol. 10, No. 3, pp. 251-270.call zivot(y,"C",4)' ----------------------------------------------------------------------------------------------------' Arguments'-----------------------------------------------------------------------------------------------------'series Y                ' dependent variable'scalar Maxlag       ' Maximum number of lags for unit root testing'string %Model      ' Location of the break ("A" = Intercept, "B" = Trend, "C" = Both)' ----------------------------------------------------------------------------------------------------subroutine zivot(series y,string %Model,scalar maxlag)!trim = 0.15 'Trimming parameterseries DY = D(Y)!nobs = @obs(y)-maxlag-1smpl @first+maxlag+1 @lastequation temp.ls dy c @trend y(-1)!aic0 = log(temp.@ssr/!nobs)+2*(temp.@ncoef/!nobs)!bic0 = log(temp.@ssr/!nobs)+ log(!nobs)*(temp.@ncoef/!nobs)!min_aic = !aic0for !lag=maxlag to 1 step -1  equation temp.ls dy y(-1) c @trend dy(-1 to -!lag)  !aic = log(temp.@ssr/!nobs)+2*(temp.@ncoef/!nobs)  !bic = log(temp.@ssr/!nobs)+log(!nobs)*(temp.@ncoef/!nobs)      if !aic < !min_aic then       !min_aic = !aic       !best_lag = !lag        else if !min_aic = !aic0 then        !best_lag =0        endif     endifnextsmpl @all!znobs = @obs(y) - !best_lag!lower = 1+!best_lag+@round(!znobs*!trim)!upper =  @obs(y)-@round(!znobs*!trim)vector(!upper-!lower+1) resultssmpl @first + !best_lag @lastfor !i = !lower to !upper  if !best_lag=0 and %Model = "A" then     equation temp.ls DY Y(-1) C @trend (@trend>!i-2)     else if !best_lag=0 and %Model = "B" then        equation temp.ls DY Y(-1) C @trend (@trend>!i-2)*(@trend-!i+2)       else if !best_lag=0 and %Model = "C" then          equation temp.ls DY Y(-1) C @trend (@trend>!i-2) (@trend>!i-2)*(@trend-!i+2)         else if !best_lag>0 and %Model = "A" then            equation temp.ls DY Y(-1) C @trend (@trend>!i-2) DY(-1 to -!best_lag)           else if !best_lag>0 and %Model = "B" then              equation temp.ls DY Y(-1) C @trend (@trend>!i-2)*(@trend-!i+2) DY(-1 to -!best_lag)              else if !best_lag>0 and %Model = "C" then                 equation temp.ls DY Y(-1) C @trend (@trend>!i-2) (@trend>!i-2)*(@trend-!i+2) DY(-1 to -!best_lag)              endif           endif         endif       endif     endif  endif  results(!i-!lower+1) = temp.@tstats(1)nextvector t_min =@cmin(results)!t_min = t_min(1)vector break = @cimin(results)+!lower-1!break = break(1)            series DT = (@trend>!break-2)*(@trend-!break+2)              if %Model = "A" or %Model="C" then                series DU = @trend> !break-2              endif         if !best_lag=0 and %Model="A" then           equation ZA.ls DY Y(-1) C @trend DU 'Selected equation            else if !best_lag=0 and %Model="B" then              equation ZA.ls DY Y(-1) C @trend DT 'Selected equation                else if !best_lag=0 and %Model="C" then                  equation ZA.ls DY Y(-1) C @trend DU DT 'Selected equation                    else if !best_lag>0 and %Model = "A" then                       equation ZA.ls DY Y(-1) C @trend DU DY(-1 to -!best_lag) 'Selected equation                       else if !best_lag>0 and %Model = "B" then                          equation ZA.ls DY Y(-1) C @trend DT DY(-1 to -!best_lag) 'Selected equation                            else if !best_lag>0 and %Model = "C" then                               equation ZA.ls DY Y(-1) C @trend DU DT DY(-1 to -!best_lag) 'Selected equation                            endif                                    endif                    endif                 endif            endif         endiftable(6,2) ZAZZAZ(1,1) = "Variable(s)"ZAZ(3,1) = "t-stat(s)"ZAZ(4,1) = "Lag(s)"ZAZ(5,1) = "Break"ZAZ(6,1) = "DU1 p-value"ZAZ(1,2) = y.@nameZAZ(3,2) = !t_minZAZ(4,2) = !best_lagif @datestr(@now,"F") = "?" then  ZAZ(5,2) = !breakelse  ZAZ(5,2) = @otod(!break)endifZAZ(6,2) = @tdist(za.@tstat(4),za.@regobs-za.@ncoef)setline(ZAZ, 2)show ZAZsmpl @alldelete temp break results t_minendsub`

hetero
Posts: 18
Joined: Tue Sep 08, 2009 11:40 am

Re: Zivot-Andrews Unit Root Test

Hi,

I have compared the results delivered from the above E-views code with those delivered from the corresponding RATS code. They are identical. This is a perfect piece of work. We are grateful Trubador!!

For users convenience the asymptotic critical values are provided below:
model Α model Β model C
1% -5.34 -4.93 -5.57
5% -4.80 -4.42 -5.08
10% -4.58 -4.11 -4.82

Regards

Posts: 6
Joined: Sun Aug 02, 2009 1:02 am

Re: Zivot-Andrews Unit Root Test

Thank you so much Trubador! You are so nice. Cheers.

hetero
Posts: 18
Joined: Tue Sep 08, 2009 11:40 am

Re: Zivot-Andrews Unit Root Test

It would be of great pleasure if a Monte Carlo simulation was also applied to calculate the exact critical values according to the sample size used each time. Is it hard to program something like that? Once again thank you for your contribution!

Regards

Did you use forum search?
Posts: 1518
Joined: Thu Nov 20, 2008 12:04 pm

Re: Zivot-Andrews Unit Root Test

hetero wrote:It would be of great pleasure if a Monte Carlo simulation was also applied to calculate the exact critical values according to the sample size used each time.

Yes, you are right. This will also complete program and fully replicate the original study.
hetero wrote:Is it hard to program something like that?

It is not that much a difficult task, but definitely requires a different way of programming.

hetero
Posts: 18
Joined: Tue Sep 08, 2009 11:40 am

Re: Zivot-Andrews Unit Root Test

Please forgive me for the indiscreet question but is there any intension to complete the program by incorporating Monte Carlo simulations?

Kind Regards

Did you use forum search?
Posts: 1518
Joined: Thu Nov 20, 2008 12:04 pm

Re: Zivot-Andrews Unit Root Test

It is in my mind, but I do not think I can spare the time in the foreseeable future.

nat
Posts: 4
Joined: Wed Nov 04, 2009 10:51 am

Re: Zivot-Andrews Unit Root Test

Hello,
I have a question. When I tried to run this programm in E-views the Error message appeared and it said that @cmin command from

"vector t_min =@cmin(results)
!t_min = t_min(1)
vector break = @cimin(results)+!lower-1
!break = break(1)"

is illigal or allready used. Could you tell me what can be wrong?
Thank you.

Did you use forum search?
Posts: 1518
Joined: Thu Nov 20, 2008 12:04 pm

Re: Zivot-Andrews Unit Root Test

You are probably using an earlier version of EViews. Those functions were introduced as of version 6 and are not supported in earlier versions of EViews. Please try the (slightly) modified code below:

Code: Select all

`'Zivot-Andrews Unit Root Test'Reference: Zivot, E. and Andrews, D. W. K. (1992), “Further Evidence on the Great Crash, the Oil-Price Shock, and the Unit-Root Hypothesis”, Journal of Business & Economic Statistics, Vol. 10, No. 3, pp. 251-270.call zivot(y,"C",4)' ----------------------------------------------------------------------------------------------------' Arguments'-----------------------------------------------------------------------------------------------------'series Y                ' dependent variable'scalar Maxlag       ' Maximum number of lags for unit root testing'string %Model      ' Location of the break ("A" = Intercept, "B" = Trend, "C" = Both)' ----------------------------------------------------------------------------------------------------subroutine zivot(series y,string %Model,scalar maxlag)!trim = 0.15 'Trimming parameterseries DY = D(Y)!nobs = @obs(y)-maxlag-1smpl @first+maxlag+1 @lastequation temp.ls dy c @trend y(-1)!aic0 = log(temp.@ssr/!nobs)+2*(temp.@ncoef/!nobs)!bic0 = log(temp.@ssr/!nobs)+ log(!nobs)*(temp.@ncoef/!nobs)!min_aic = !aic0for !lag=maxlag to 1 step -1  equation temp.ls dy y(-1) c @trend dy(-1 to -!lag)  !aic = log(temp.@ssr/!nobs)+2*(temp.@ncoef/!nobs)  !bic = log(temp.@ssr/!nobs)+log(!nobs)*(temp.@ncoef/!nobs)      if !aic < !min_aic then       !min_aic = !aic       !best_lag = !lag        else if !min_aic = !aic0 then        !best_lag =0        endif     endifnextsmpl @all!znobs = @obs(y) - !best_lag!lower = 1+!best_lag+@round(!znobs*!trim)!upper =  @obs(y)-@round(!znobs*!trim)vector(!upper-!lower+1) resultssmpl @first + !best_lag @lastfor !i = !lower to !upper  if !best_lag=0 and %Model = "A" then     equation temp.ls DY Y(-1) C @trend (@trend>!i-2)     else if !best_lag=0 and %Model = "B" then        equation temp.ls DY Y(-1) C @trend (@trend>!i-2)*(@trend-!i+2)       else if !best_lag=0 and %Model = "C" then          equation temp.ls DY Y(-1) C @trend (@trend>!i-2) (@trend>!i-2)*(@trend-!i+2)         else if !best_lag>0 and %Model = "A" then            equation temp.ls DY Y(-1) C @trend (@trend>!i-2) DY(-1 to -!best_lag)           else if !best_lag>0 and %Model = "B" then              equation temp.ls DY Y(-1) C @trend (@trend>!i-2)*(@trend-!i+2) DY(-1 to -!best_lag)              else if !best_lag>0 and %Model = "C" then                 equation temp.ls DY Y(-1) C @trend (@trend>!i-2) (@trend>!i-2)*(@trend-!i+2) DY(-1 to -!best_lag)              endif           endif         endif       endif     endif  endif  results(!i-!lower+1) = temp.@tstats(1)nextvector t_min =@min(results)!t_min = t_min(1)vector break  !i =1    while !i<=!upper-!lower+1      if results(!i) = @min(results) then       break = !i+!lower-1     endif       !i = !i+1    wend!break = break(1)            series DT = (@trend>!break-2)*(@trend-!break+2)              if %Model = "A" or %Model="C" then                series DU = @trend> !break-2              endif         if !best_lag=0 and %Model="A" then           equation ZA.ls DY Y(-1) C @trend DU 'Selected equation            else if !best_lag=0 and %Model="B" then              equation ZA.ls DY Y(-1) C @trend DT 'Selected equation                else if !best_lag=0 and %Model="C" then                  equation ZA.ls DY Y(-1) C @trend DU DT 'Selected equation                    else if !best_lag>0 and %Model = "A" then                       equation ZA.ls DY Y(-1) C @trend DU DY(-1 to -!best_lag) 'Selected equation                       else if !best_lag>0 and %Model = "B" then                          equation ZA.ls DY Y(-1) C @trend DT DY(-1 to -!best_lag) 'Selected equation                            else if !best_lag>0 and %Model = "C" then                               equation ZA.ls DY Y(-1) C @trend DU DT DY(-1 to -!best_lag) 'Selected equation                            endif                                    endif                    endif                 endif            endif         endiftable(6,2) ZAZZAZ(1,1) = "Variable(s)"ZAZ(3,1) = "t-stat(s)"ZAZ(4,1) = "Lag(s)"ZAZ(5,1) = "Break"ZAZ(6,1) = "DU1 p-value"ZAZ(1,2) = y.@nameZAZ(3,2) = !t_minZAZ(4,2) = !best_lagZAZ(5,2) = @otod(!break)ZAZ(6,2) = @tdist(za.@tstat(4),za.@regobs-za.@ncoef)setline(ZAZ, 2)show ZAZsmpl @alldelete temp break results t_minendsub`
Last edited by trubador on Fri Nov 06, 2009 5:59 am, edited 1 time in total.

nat
Posts: 4
Joined: Wed Nov 04, 2009 10:51 am

Re: Zivot-Andrews Unit Root Test

Thank you Trubador, youou are right, I am using 4.0 version. But the lighter version which you sent has some problems as well. It does not recognize
@datestr in
"if @datestr(@now,"F") = "?" then".
So I will try to find upper version.

nat
Posts: 4
Joined: Wed Nov 04, 2009 10:51 am

Re: Zivot-Andrews Unit Root Test

I am sorry version which I am using is 4.1, not 4.0. After showing an error message (which I mentioned above), I noticed that two equations Temp and ZA were created in my workfile, and ZaZ table. Is it what I have to have after this programm? In this case it seems that no problem?

Did you use forum search?
Posts: 1518
Joined: Thu Nov 20, 2008 12:04 pm

Re: Zivot-Andrews Unit Root Test

Since you are using an older version, you may not always be able to run codes written in newer versions. In this case, however, I do not think that you are facing a serious problem. You can remove the following part altogether:

Code: Select all

` if @datestr(@now,"F") = "?" then  ZAZ(5,2) = !breakelse  ZAZ(5,2) = @otod(!break)endif`

and replace it with the following single line, since @otod provides a more general use:

Code: Select all

`  ZAZ(5,2) = @otod(!break)`

I have already edited my previous post in the same way...
Last edited by trubador on Fri Nov 06, 2009 6:01 am, edited 1 time in total.

nat
Posts: 4
Joined: Wed Nov 04, 2009 10:51 am

Re: Zivot-Andrews Unit Root Test

Thank you very much! It worked!
Thanks again!

donihue
Posts: 137
Joined: Wed Oct 07, 2009 8:51 am

Re: Zivot-Andrews Unit Root Test

Following up on this very helpful exchange:
Would you have written a code for the Clemente-Montanes-Reyes unit root test, which also alows for two structural breaks (it is implemented in Stata as "clemao" or "clemio", depending on form)?
Many thanks
Regards
Donihue

Did you use forum search?
Posts: 1518
Joined: Thu Nov 20, 2008 12:04 pm

Re: Zivot-Andrews Unit Root Test

donihue wrote:Following up on this very helpful exchange:
Would you have written a code for the Clemente-Montanes-Reyes unit root test, which also alows for two structural breaks (it is implemented in Stata as "clemao" or "clemio", depending on form)?
Many thanks
Regards
Donihue

As you might have noticed, we tried to write a code for Lumsdaine-Papell unit root test. However, we did not have enough time to finish it. I cannot promise anytime soon, but I will complete that work as soon as I have spare time.

Actually, I am not an expert on unit root testing and do not follow the recent developments in the literature very closely. I do know that there are lots of variants of unit root tests, each of which serves to a different purpose. I think it would be useful and helpful to implement unit root tests in EViews that are commonly used or proved to be robust in practice.