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

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 = 1000vector(1) breaksfor !i = @round(@obs(sy)*!trim) to @round(@obs(sy)*(1-!trim))smpl @allequation temp.ls SY c IY (@trend>!i)temp.makeresid EECgenr ZZ = EECgenr DZZ = D(EEC)for !lag = 0 to 4if !lag = 0 thenequation temp.ls DZZ  ZZ(-1) elseequation 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 thenequation GH.ls DZZ  ZZ(-1)else              equation GH.ls DZZ ZZ(-1) DZZ(-1 TO -!best_lag) 'Selected equation       endif       endifendif  nextnextdelete temp`

Second set of code:

Code: Select all

`!trim = 0.15 'Trimming parameterfor !i = @round(@obs(sy)*!trim) to @round(@obs(sy)*(1-!trim))matrix(!i,2) GHtest1vector(1) breakssmpl @allequation ghc1.ls sy c iy (@trend>!i)ghc1.makeresid EECgenr ZZ = EECgenr DZZ = D(EEC)uroot(adf, none, info=aic, maxlag=4, save=level!i) ZZGHtest1(!i,1) = level!i(3,1)GHtest1(!i,2) = level!i(2,1)nextvector minaic = @cmin(GHtest1)vector eqn_minaic = @cimin(GHtest1)`

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

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

Re: Gregory-Hansen cointegration test

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

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

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

Re: Gregory-Hansen cointegration test

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

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: 12416
Joined: Tue Sep 16, 2008 5:38 pm

Re: Gregory-Hansen cointegration test

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.

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

Re: Gregory-Hansen cointegration test

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

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.

Shahid

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

Re: Gregory-Hansen cointegration test

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
ghtest.prg

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

Re: Gregory-Hansen cointegration test

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
prog_gh_prova.prg

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

Re: Gregory-Hansen cointegration test

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 independentsindependents.add ylyt stnw nstnw fedf_ncall greghansen(pce,independents,3,"aic",8)`

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

Re: Gregory-Hansen cointegration test

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

Thanks a lot !!
-Kakali.

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

Re: Gregory-Hansen cointegration test

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.

Attachments
oilsex.WF1
ghtestex.prg
GHTEST Results.xlsx

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

Re: Gregory-Hansen cointegration test

Regards,
-Kakali.

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

Re: Gregory-Hansen cointegration test

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