Gregory-Hansen cointegration test

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt

tcfoon
Posts: 54
Joined: Fri May 15, 2009 4:33 am

Gregory-Hansen cointegration test

Postby tcfoon » Sun May 31, 2009 5:07 pm

Dear trubador and others Eviews programming expert,

With the help from Trubador, I have written the following sets of codes for Gregory and Hansen (1996) cointegration test. Unfortunately, both codes seem to be correct but I am not sure why the results is vary between the programme used. In term of result, I think the second set of code should be correct, while the first set of code will produce more easy and presentable result. Therefore, I attempt to request the Eviews programming expert to improve the first codes. Of course, I would also appreciate that if the Eviews programming expert willing to write a more shorter and presentable code for the Gregory-Hansen test.

The Gregory-Hansen programming code were reported as below:

First set of GH code:

Code: Select all

!trim = 0.15 'Trimming parameter
!t_min = 1000
!min_aic = 1000
vector(1) breaks
for !i = @round(@obs(sy)*!trim) to @round(@obs(sy)*(1-!trim))

smpl @all
equation temp.ls SY c IY (@trend>!i)
temp.makeresid EEC
genr ZZ = EEC
genr DZZ = D(EEC)

for !lag = 0 to 4
if !lag = 0 then
equation temp.ls DZZ  ZZ(-1)
else
equation temp.ls DZZ  ZZ(-1) DZZ(-1 TO -!lag)
endif
   if temp.@aic < !min_aic then
     !best_lag = !lag
     !min_aic = temp.@aic
       if temp.@tstats(1) < !t_min then
        !t_min = temp.@tstats(1)
        breaks(1) = !i+2 'Identified first break point.
                series DU1 = @trend> !i
        series DT1 = DU1*(@trend-!i)
if !best_lag = 0 then
equation GH.ls DZZ  ZZ(-1)
else
              equation GH.ls DZZ ZZ(-1) DZZ(-1 TO -!best_lag) 'Selected equation
       endif
       endif
endif
  next
next
delete temp


Second set of code:

Code: Select all

!trim = 0.15 'Trimming parameter
for !i = @round(@obs(sy)*!trim) to @round(@obs(sy)*(1-!trim))

matrix(!i,2) GHtest1
vector(1) breaks

smpl @all
equation ghc1.ls sy c iy (@trend>!i)
ghc1.makeresid EEC
genr ZZ = EEC
genr DZZ = D(EEC)

uroot(adf, none, info=aic, maxlag=4, save=level!i) ZZ
GHtest1(!i,1) = level!i(3,1)
GHtest1(!i,2) = level!i(2,1)
next

vector minaic = @cmin(GHtest1)

vector eqn_minaic = @cimin(GHtest1)


Thank you in advance,

Warmest regards,
tcfoon
Last edited by tcfoon on Sun Sep 04, 2011 3:52 am, edited 1 time in total.

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

Re: Gregory-Hansen cointegration test

Postby trubador » Mon Jun 01, 2009 2:19 am

For the first code you should change the following line:

Code: Select all

...
breaks(1) = !i+3 'Identified first break point.
...


For the second code:

Code: Select all

...
vector eqn_minaic = @cimin(GHtest1)
eqn_minaic(1) = eqn_minaic(1)+3
...


However, in the second code, selection procedure based on ADF unit root test fails to correctly pinpoint the location of the structural break with plus or minus one observation.

tcfoon
Posts: 54
Joined: Fri May 15, 2009 4:33 am

Re: Gregory-Hansen cointegration test

Postby tcfoon » Mon Jun 01, 2009 3:13 am

Dear Trubador,

Thank you for correcting the codes. I wonder why the we have to use break(1) = !i+3 instead of break(1) = !i+2 for the first code.

My concern is that why both tests results and also the identify breaks date vary so much. Is there anything wrong?? For example, the first code noted that the break point should be 15 after adjusted to !i+3, but the second code suggest that the break date should be 39 after adjusted to +3.

Here, I also attached the workfile for you to have a look.

Thank you,

Regards,
CF Tang
Attachments
GH.WF1
(8.62 KiB) Downloaded 759 times

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

Re: Gregory-Hansen cointegration test

Postby trubador » Mon Jun 01, 2009 5:01 am

Plus one is due to trend variable, since it begins with zero. Plus two is due to "greater than" inequality operator. And plus three is due to first difference of the residual series.

First code does not take into account the information from the initial equation that you first obtain residuals, which creates the major source of difference I believe. Your code ignores the initial setting and does an exhaustive search only on the secondary equations that first difference of the residuals from the first equations are the dependent variables. In the second code, however, you apply unit root tests to the level of residuals. Therefore, you should expect the second code to perform better in most cases.

rnt2008
Posts: 4
Joined: Tue Sep 30, 2008 7:29 am

Re: Gregory-Hansen cointegration test

Postby rnt2008 » Wed Jun 03, 2009 7:24 am

To QMS people, why not writing a structured routine to be inserted in the program repository using the pieces of code herein posted?

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13318
Joined: Tue Sep 16, 2008 5:38 pm

Re: Gregory-Hansen cointegration test

Postby EViews Gareth » Wed Jun 03, 2009 8:11 am

I am sure that, and would be pleased if, once Trubador and TCFoon have got the code to their satisfaction, they will put it in the program repository.
Follow us on Twitter @IHSEViews

jjaa
Posts: 10
Joined: Tue Sep 28, 2010 8:19 pm

Re: Gregory-Hansen cointegration test

Postby jjaa » Wed Oct 06, 2010 6:00 pm

Hi,
i have a problem, when i run the test and define the series IY and SY, it appears a window thats says, insufficient number of observations, and i am working with more than 100 observations.
Thank you

mdshahid
Posts: 1
Joined: Mon Jul 18, 2011 2:16 am

Re: Gregory-Hansen cointegration test

Postby mdshahid » Mon Jul 18, 2011 2:32 am

Dear Trubador and Gereth

I am using EViews for last few years. I am a PhD student in Australia. Recently, I tried to run the Gregory and Hansen (G-H) cointegration test program developed by Trubador and TCFoon. I could run the program successfully. I really appreciate your help.

Now, the program you developled only gives result for constend and trend (model 3). I need to see the G-H conintegration test results only for constant (C) and without trend. Also I want to get the G-H conintegration test result for constant and regime shift (C/S). Could you please kindly know me how I can change the codes to get the results for C and C/S.

Thanks for your help

Shahid

kakali
Posts: 6
Joined: Wed Apr 25, 2012 1:48 am

Re: Gregory-Hansen cointegration test

Postby kakali » Wed Apr 25, 2012 2:37 am

Dear trubador, tcfoon and others Eviews programming expert,

I am new to Eviews programming, I have tried to run the attached code and found the following error

Type Mismatch at Argument 2 in CALL GREGHANSEN(Y, X, 3, "AIC", 6)

Data file is also attached.

Your help will be highliy appreciated.
Thanks,
-Kakali.
Attachments
gold.xls
(18.5 KiB) Downloaded 413 times
ghtest.prg
(4.8 KiB) Downloaded 723 times

kakali
Posts: 6
Joined: Wed Apr 25, 2012 1:48 am

Re: Gregory-Hansen cointegration test

Postby kakali » Wed Apr 25, 2012 2:44 am

Dear trubador , tcfoon, wolly77,

I have been trying to run the following code, which returns the error

!NINDEP is not defined or an illegal command in !NINDEP=G.@COUNT. Data and Program files are attached.

I am new to E-views programming. I appreciate your help.

Thanks so much!
-Kakali.
Attachments
my_workfile.WF1
(26.47 KiB) Downloaded 428 times
prog_gh_prova.prg
(5.41 KiB) Downloaded 473 times

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

Re: Gregory-Hansen cointegration test

Postby trubador » Wed Apr 25, 2012 12:38 pm

kakali wrote:!NINDEP is not defined or an illegal command in !NINDEP=G.@COUNT. Data and Program files are attached.

You should not change the arguments in the subroutine. The relevant parts for your analysis are as follows:

Code: Select all

open .\my_workfile
group independents
independents.add ylyt stnw nstnw fedf_n
call greghansen(pce,independents,3,"aic",8)

kakali
Posts: 6
Joined: Wed Apr 25, 2012 1:48 am

Re: Gregory-Hansen cointegration test

Postby kakali » Thu Apr 26, 2012 4:59 am

Thanks very much Trubador.
It ran now. I will now run on my data and certainly touchbase with you if there is any problem.

Thanks a lot !! :D
-Kakali.

kakali
Posts: 6
Joined: Wed Apr 25, 2012 1:48 am

Re: Gregory-Hansen cointegration test

Postby kakali » Mon Apr 30, 2012 4:06 am

Dear Trubador,

Please advise if the values received for Za test...needs to be multiplied by 100. The test statistics I have obtained seem to be to low to be true, also does not seem to be correct as the formula of the test statistic shows that it has a multiplier of n (sample size), so it is unlikely that the values will be <1.

Also, the crtical values that Bruce obtained has three values corresponding to 3 models, however, while running the code I get same results for all three models.

I attach here the test results.

Please advise?

Thanking you for your help in advance.
Attachments
oilsex.WF1
(95.45 KiB) Downloaded 396 times
ghtestex.prg
(5.46 KiB) Downloaded 708 times
GHTEST Results.xlsx
(12.18 KiB) Downloaded 472 times

kakali
Posts: 6
Joined: Wed Apr 25, 2012 1:48 am

Re: Gregory-Hansen cointegration test

Postby kakali » Wed May 02, 2012 12:13 am

Dear Trubador,

Can you please advise on the above queries?

Appreciate your quick response.

Regards,
-Kakali.

sherrihan
Posts: 1
Joined: Tue May 29, 2012 6:53 am

Re: Gregory-Hansen cointegration test

Postby sherrihan » Fri Jun 01, 2012 9:05 am

Dear Trubador

I would like to use the above code to test for cointegration between six countries in the presence of a structural break. Can you please help me in updating the main code i.e. extending it to a multivariate case?

Thank you.

Regards,
Sheri


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 74 guests