Gregory-Hansen Cointegration Test

For posting your own programs to share with others

Moderators: EViews Gareth, EViews Moderator

Mobeen ur Rehman
Posts: 1
Joined: Wed Jul 01, 2015 4:15 am

Re: Gregory-Hansen Cointegration Test

Postby Mobeen ur Rehman » Wed Mar 23, 2016 1:05 am

Dear brother,

Can you please tell me how to install the add in for gregory hansen cointegration in eviews8

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

Re: Gregory-Hansen Cointegration Test

Postby trubador » Wed Mar 23, 2016 11:57 am

This is not an add-in. Just copy-paste the code into a new program window and change only the part above the subroutine before running it.

hafizah0486
Posts: 2
Joined: Sun Jul 31, 2016 1:48 am

Re: Gregory-Hansen Cointegration Test

Postby hafizah0486 » Tue Aug 02, 2016 1:27 am

Dear Mr. Trubador, thank you very much for sharing. Your post really help me in conducting my research. I really appreciate if you could also share on how to conduct the unit root test with break proposed by Narayan and Popp (2010) and Johansen, Mosconi & Nielsen (2000) cointegration test with break. You kind help is highly appreciated :)

hafizah0486
Posts: 2
Joined: Sun Jul 31, 2016 1:48 am

Re: Gregory-Hansen Cointegration Test

Postby hafizah0486 » Tue Aug 02, 2016 1:34 am

I have found the program file for Johansen et al (2000) from Prof. Dave Giles website. However, I am not sure on how can I conduct the test. Hope you can help.
http://web.uvic.ca/~dgiles/downloads/johansen/

' COMPUTATION OF ASYMPTOTIC CRITICAL VALUES FOR THE H(c) and H(L) COINTEGRATION TESTS WHEN THERE ARE 2 or 3 STRUCTURAL BREAKS
' =============================================================

' Written by David Giles, Dept. of Economics, University of Victoria.
' Last Modified: 28 June, 2011.

' The total sample size is T. The number of sub-samples due to the structural breaks is "q". So, q=2 corresponds to one structural break, and q=3 corresponds to 2 structural breaks. If q=1 there are no structural breaks.
' The break-points occur at T1, when q=2, and at T1 and T2, when q=3.
' The break-point proportions are V1=(T1/T), when q=2; and V1 and V2=(T2/T), when q=3.
' (If q=2, the value of V2 below is not used)

' r = cointegrating rank
' p = no. of variables in system

' To cross-check the results for the H(c) test with the last column of Table 5 in Johansen et al., set q=1 (V1 and V2 can be left at their current values as they will not be used)
'===================================
' EDIT THE NEXT 3 LINES, AS APPROPRIATE:

scalar q=3
scalar V1=0.3
scalar V2=0.85
'================================
'EDIT THE NEXT 2 LINES IF P-VALUES ARE REQUIRED

scalar traceL=123.6
scalar traceC=114.7
'================================
vector(2) c2
vector(3) c3
vector(2) c4
vector(2) c5
vector(2) c6
scalar a
scalar b
' The values of "a" and "b" depend on the number (q-1) of structural breaks.
' When q=2, we set a=0 in Table 4 of Johansen et al. (2000) & b = min[ V1 , (1-V1)]
' When q=3, we set a=min[V1, (V2-V1), (1-V2)] & b = min[remaining two V expressions ]

if q=2 then
c2.fill v1, 1-v1
a=0
b=@min(c2)
endif
if q=3 then
c3.fill v1, v2-v1, 1-v2
a=@min(c3)
b=@median(c3)
endif
if q=1 then
a=0
b=0
endif
' Let pr denote (p-r)
vector(10) pr
vector(10) lmL
vector(10) lvL
vector(10) meanL
vector(10) varL
vector(10) lmC
vector(10) lvC
vector(10) meanC
vector(10) varC
vector(10) theta
vector(10) k
vector(10) crit_HL90
vector(10) crit_HL95
vector(10) crit_HL99
vector(10) crit_HC90
vector(10) crit_HC95
vector(10) crit_HC99
vector(10) pvalL
vector(10) pvalC

' lm denotes the logarithm of the mean of the asymptotic distribution
' lv denotes the logarithm of the variance of the asymptotic distribution
' See Table 4 of Johansen et al. (2000). We then add L or C to the names to reflect the H(L) test or the H(c) test.

' First construct critical values for the H(L) test, and then for the H(c) test
for !pr = 1 to 10
pr(!pr)=!pr

lmL(!pr)=3.06+0.456*!pr+1.47*a+0.993*b-0.0269*!pr^2-0.0363*a*!pr-0.0195*b*!pr-4.21*a^2-2.35*b^2+0.000840*!pr^3+6.01*a^3-1.33*a^2*b+2.04*b^3-2.05/!pr-0.304*a/!pr+1.06*b/!pr+9.35*a^2/!pr+3.82*a*b/!pr+2.12*b^2/!pr-22.8*a^3/!pr-7.15*a*b^2/!pr-4.95*b^3/!pr+0.681/!pr^2-0.828*b/!pr^2-5.43*a^2/!pr^2+13.1*a^3/!pr^2+1.5*b^3/!pr^2

lvL(!pr)= 3.97+0.314*!pr+1.79*a+0.256*b-0.00898*!pr^2-0.0688*a*!pr-4.08*a^2+4.75*a^3-0.587*b^3-2.47/!pr+1.62*a/!pr+3.13*b/!pr-4.52*a^2/!pr-1.21*a*b/!pr-5.87*b^2/!pr+4.89*b^3/!pr+0.874/!pr^2-0.865*b/!pr^2

meanL(!pr)=exp(lmL(!pr))-(3-q)*!pr
varL(!pr)=exp(lvL(!pr))-2*(3-q)*!pr

' Use the asymptotic mean and variance to obtain the shape and scale parameters of the gamma distribution to be used to approximate the asymptotic distribution of the test statistic, and hence obtain the desired quantiles under the null:

theta(!pr)=(varL(!pr)/meanL(!pr))
k(!pr)=meanL(!pr)^2/varL(!pr)
crit_HL90(!pr)=@qgamma(0.90, theta(!pr),k(!pr))
crit_HL95(!pr)=@qgamma(0.95, theta(!pr),k(!pr))
crit_HL99(!pr)=@qgamma(0.99, theta(!pr),k(!pr))

if traceL>0 then
pvalL(!pr)=1-@cgamma(traceL, theta(!pr),k(!pr))
endif

lmC(!pr)=2.80+0.501*!pr+1.43*a+0.399*b-0.0309*!pr^2-0.0600*a*!pr-5.72*a^2-1.12*a*b-1.70*b^2+0.000974*!pr^3+0.168*a^2*!pr+6.34*a^3+1.89*a*b^2+1.85*b^3-2.19/!pr-0.438*a/!pr+1.79*b/!pr+6.03*a^2/!pr+3.08*a*b/!pr-1.97*b^2/!pr-8.08*a^3/!pr-5.79*a*b^2/!pr+0.717/!pr^2-1.29*b/!pr^2-1.52*a^2/!pr^2+2.87*b^2/!pr^2-2.03*b^3/!pr^2

lvC(!pr)= 3.78+0.346*!pr+0.859*a-0.0106*!pr^2-0.0339*a*!pr-2.35*a^2+3.95*a^3-0.282*b^3-2.73/!pr+0.874*a/!pr+2.36*b/!pr-2.88*a^2/!pr-4.44*b^2/!pr+4.31*b^3/!pr+1.02/!pr^2-0.807*b/!pr^2

meanC(!pr)=exp(lmC(!pr))-(3-q)*!pr
varC(!pr)=exp(lvC(!pr))-2*(3-q)*!pr

' use the asymptotic mean and variance to obtain the shape and scale parameters of the gamma distribution to be used to approximate the asymptotic distribution of the test statistic, and hence obtain the desired quantiles under the null:

theta(!pr)=varC(!pr)/meanC(!pr)
k(!pr)=meanC(!pr)^2/varC(!pr)
crit_HC90(!pr)=@qgamma(0.90, theta(!pr),k(!pr))
crit_HC95(!pr)=@qgamma(0.95, theta(!pr),k(!pr))
crit_HC99(!pr)=@qgamma(0.99, theta(!pr),k(!pr))


if traceC>0 then
pvalC(!pr)=1-@cgamma(traceC, theta(!pr),k(!pr))
endif
next

smpl 1 10
mtos(pr,p_minus_r)
mtos(crit_HL90, crit_HL_90)
mtos(crit_HL95, crit_HL_95)
mtos(crit_HL99, crit_HL_99)
mtos(crit_HC90, crit_HC_90)
mtos(crit_HC95, crit_HC_95)
mtos(crit_HC99, crit_HC_99)
group crit_vals p_minus_r crit_HL_90 crit_HL_95 crit_HL_99 crit_HC_90 crit_HC_95 crit_HC_99

show crit_vals

if traceL>0 then
mtos(pvalL,p_val_HL)
group pval_HL p_minus_r p_val_HL
show pval_HL
endif

if traceC>0 then
mtos(pvalC,p_val_HC)
group pval_HC p_minus_r p_val_HC
show pval_HC
endif

baah
Posts: 1
Joined: Wed Aug 03, 2016 7:04 am

Re: Gregory-Hansen Cointegration Test

Postby baah » Wed Aug 03, 2016 9:08 pm

Please, I am new in using EVIEWS 9. I wish to perform the Gregory-Hansen ; and Hatemi -J cointegration test . I have copied the codes stated above into the proceedure shown( File/New/Program). I have also edited to suit my variables. Now, what do i do next to run the following 1. Gregory Hansen cointegration test and 2. Hatemi-J cointegration test.
Thank you.

Kahn
Posts: 8
Joined: Sun Apr 10, 2016 6:29 am

Re: Gregory-Hansen Cointegration Test

Postby Kahn » Thu Aug 04, 2016 4:58 pm

Dear Trubador,

Assuming we do find evidence of cointegration, how would we proceed with our analysis if we had to estimate a VECM? How would the structural break or regime change be modelled in EViews? Would it suffice to simply split the sample into two sub-periods and estimate two models?

I appreciate any guidance,

Kahn.

Kahn
Posts: 8
Joined: Sun Apr 10, 2016 6:29 am

Re: Gregory-Hansen Cointegration Test

Postby Kahn » Sun Aug 21, 2016 11:37 am

Would it be valid to use the GH test for multiple series at once?

albertozzio
Posts: 5
Joined: Tue Dec 06, 2016 9:19 am

Re: Gregory-Hansen Cointegration Test

Postby albertozzio » Sat Jan 28, 2017 12:49 pm

Dear trubador,
I know NOTHING about subroutines on Eviews but i need to learn them for my master thesis. I am a student of Economics but unfortunately we didn't learn on time how to work on Eviews.
Basically, you wrote a subroutine for this G-H test, that I need to apply to my time-series variables. How can I do that? I mean, I should just substitute my variables putting them in your subroutine and then press "run". How to do that?

Thanks a lot, you can save me!
Alberto

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

Re: Gregory-Hansen Cointegration Test

Postby EViews Gareth » Sat Jan 28, 2017 6:55 pm

Probably the best thing to do is to learn about subroutines.

http://www.eviews.com/help/helpintro.ht ... ng.html%23
Follow us on Twitter @IHSEViews

maragloria
Posts: 60
Joined: Tue Jun 29, 2010 7:09 am

Re: Gregory-Hansen Cointegration Test

Postby maragloria » Tue Apr 11, 2017 3:15 pm

Hello Trubador,

Thanks very much for your code.

I'm using EViews 9 and I got the following error message:
"Near singular matrix error. Regressors may be perfectly collinear in "DO_ GHC.LS Y C (@TREND>9-2) G"
I've tested for different values of scalar Model (2 to 4); the same error message appears.

Please find attached my data and the program.

Many thanks!
breakpts.WF1
(18.6 KiB) Downloaded 6 times

coint_greghansen.prg
(4.95 KiB) Downloaded 9 times

maragloria
Posts: 60
Joined: Tue Jun 29, 2010 7:09 am

Re: Gregory-Hansen Cointegration Test

Postby maragloria » Tue Apr 11, 2017 3:33 pm

Hello Trubador,

I found this post; Thinking my problem was related, I run you suggestion but I still get the same error message.

Thanks again.

Capture.PNG
Capture.PNG (30.75 KiB) Viewed 237 times

startz
Non-normality and collinearity are NOT problems!
Posts: 3037
Joined: Wed Sep 17, 2008 2:25 pm

Re: Gregory-Hansen Cointegration Test

Postby startz » Tue Apr 11, 2017 3:34 pm

(@TREND>9-2) is constant in your sample period.

maragloria
Posts: 60
Joined: Tue Jun 29, 2010 7:09 am

Re: Gregory-Hansen Cointegration Test

Postby maragloria » Wed Apr 12, 2017 10:00 am

Hello startz,

Thanks for your prompt reply.

Sorry, I can't grasp the implications of your answer. What should I do to fix the problem?

Best regards, Mara

startz
Non-normality and collinearity are NOT problems!
Posts: 3037
Joined: Wed Sep 17, 2008 2:25 pm

Re: Gregory-Hansen Cointegration Test

Postby startz » Wed Apr 12, 2017 10:43 am

Perhaps just delete that variable.


Return to “Program Repository”

Who is online

Users browsing this forum: No registered users and 2 guests