GregoryHansen Cointegration Test
Moderators: EViews Gareth, EViews Moderator

 Posts: 1
 Joined: Wed Jul 01, 2015 4:15 am
Re: GregoryHansen Cointegration Test
Dear brother,
Can you please tell me how to install the add in for gregory hansen cointegration in eviews8
Can you please tell me how to install the add in for gregory hansen cointegration in eviews8
Re: GregoryHansen Cointegration Test
This is not an addin. Just copypaste the code into a new program window and change only the part above the subroutine before running it.

 Posts: 2
 Joined: Sun Jul 31, 2016 1:48 am
Re: GregoryHansen Cointegration Test
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

 Posts: 2
 Joined: Sun Jul 31, 2016 1:48 am
Re: GregoryHansen Cointegration Test
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 subsamples 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 breakpoints occur at T1, when q=2, and at T1 and T2, when q=3.
' The breakpoint 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 crosscheck 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 PVALUES 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 (q1) of structural breaks.
' When q=2, we set a=0 in Table 4 of Johansen et al. (2000) & b = min[ V1 , (1V1)]
' When q=3, we set a=min[V1, (V2V1), (1V2)] & b = min[remaining two V expressions ]
if q=2 then
c2.fill v1, 1v1
a=0
b=@min(c2)
endif
if q=3 then
c3.fill v1, v2v1, 1v2
a=@min(c3)
b=@median(c3)
endif
if q=1 then
a=0
b=0
endif
' Let pr denote (pr)
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*b0.0269*!pr^20.0363*a*!pr0.0195*b*!pr4.21*a^22.35*b^2+0.000840*!pr^3+6.01*a^31.33*a^2*b+2.04*b^32.05/!pr0.304*a/!pr+1.06*b/!pr+9.35*a^2/!pr+3.82*a*b/!pr+2.12*b^2/!pr22.8*a^3/!pr7.15*a*b^2/!pr4.95*b^3/!pr+0.681/!pr^20.828*b/!pr^25.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*b0.00898*!pr^20.0688*a*!pr4.08*a^2+4.75*a^30.587*b^32.47/!pr+1.62*a/!pr+3.13*b/!pr4.52*a^2/!pr1.21*a*b/!pr5.87*b^2/!pr+4.89*b^3/!pr+0.874/!pr^20.865*b/!pr^2
meanL(!pr)=exp(lmL(!pr))(3q)*!pr
varL(!pr)=exp(lvL(!pr))2*(3q)*!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*b0.0309*!pr^20.0600*a*!pr5.72*a^21.12*a*b1.70*b^2+0.000974*!pr^3+0.168*a^2*!pr+6.34*a^3+1.89*a*b^2+1.85*b^32.19/!pr0.438*a/!pr+1.79*b/!pr+6.03*a^2/!pr+3.08*a*b/!pr1.97*b^2/!pr8.08*a^3/!pr5.79*a*b^2/!pr+0.717/!pr^21.29*b/!pr^21.52*a^2/!pr^2+2.87*b^2/!pr^22.03*b^3/!pr^2
lvC(!pr)= 3.78+0.346*!pr+0.859*a0.0106*!pr^20.0339*a*!pr2.35*a^2+3.95*a^30.282*b^32.73/!pr+0.874*a/!pr+2.36*b/!pr2.88*a^2/!pr4.44*b^2/!pr+4.31*b^3/!pr+1.02/!pr^20.807*b/!pr^2
meanC(!pr)=exp(lmC(!pr))(3q)*!pr
varC(!pr)=exp(lvC(!pr))2*(3q)*!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
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 subsamples 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 breakpoints occur at T1, when q=2, and at T1 and T2, when q=3.
' The breakpoint 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 crosscheck 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 PVALUES 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 (q1) of structural breaks.
' When q=2, we set a=0 in Table 4 of Johansen et al. (2000) & b = min[ V1 , (1V1)]
' When q=3, we set a=min[V1, (V2V1), (1V2)] & b = min[remaining two V expressions ]
if q=2 then
c2.fill v1, 1v1
a=0
b=@min(c2)
endif
if q=3 then
c3.fill v1, v2v1, 1v2
a=@min(c3)
b=@median(c3)
endif
if q=1 then
a=0
b=0
endif
' Let pr denote (pr)
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*b0.0269*!pr^20.0363*a*!pr0.0195*b*!pr4.21*a^22.35*b^2+0.000840*!pr^3+6.01*a^31.33*a^2*b+2.04*b^32.05/!pr0.304*a/!pr+1.06*b/!pr+9.35*a^2/!pr+3.82*a*b/!pr+2.12*b^2/!pr22.8*a^3/!pr7.15*a*b^2/!pr4.95*b^3/!pr+0.681/!pr^20.828*b/!pr^25.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*b0.00898*!pr^20.0688*a*!pr4.08*a^2+4.75*a^30.587*b^32.47/!pr+1.62*a/!pr+3.13*b/!pr4.52*a^2/!pr1.21*a*b/!pr5.87*b^2/!pr+4.89*b^3/!pr+0.874/!pr^20.865*b/!pr^2
meanL(!pr)=exp(lmL(!pr))(3q)*!pr
varL(!pr)=exp(lvL(!pr))2*(3q)*!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*b0.0309*!pr^20.0600*a*!pr5.72*a^21.12*a*b1.70*b^2+0.000974*!pr^3+0.168*a^2*!pr+6.34*a^3+1.89*a*b^2+1.85*b^32.19/!pr0.438*a/!pr+1.79*b/!pr+6.03*a^2/!pr+3.08*a*b/!pr1.97*b^2/!pr8.08*a^3/!pr5.79*a*b^2/!pr+0.717/!pr^21.29*b/!pr^21.52*a^2/!pr^2+2.87*b^2/!pr^22.03*b^3/!pr^2
lvC(!pr)= 3.78+0.346*!pr+0.859*a0.0106*!pr^20.0339*a*!pr2.35*a^2+3.95*a^30.282*b^32.73/!pr+0.874*a/!pr+2.36*b/!pr2.88*a^2/!pr4.44*b^2/!pr+4.31*b^3/!pr+1.02/!pr^20.807*b/!pr^2
meanC(!pr)=exp(lmC(!pr))(3q)*!pr
varC(!pr)=exp(lvC(!pr))2*(3q)*!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
Re: GregoryHansen Cointegration Test
Please, I am new in using EVIEWS 9. I wish to perform the GregoryHansen ; 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. HatemiJ cointegration test.
Thank you.
Thank you.
Re: GregoryHansen Cointegration Test
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 subperiods and estimate two models?
I appreciate any guidance,
Kahn.
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 subperiods and estimate two models?
I appreciate any guidance,
Kahn.
Re: GregoryHansen Cointegration Test
Would it be valid to use the GH test for multiple series at once?

 Posts: 5
 Joined: Tue Dec 06, 2016 9:19 am
Re: GregoryHansen Cointegration Test
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 GH test, that I need to apply to my timeseries 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
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 GH test, that I need to apply to my timeseries 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

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 12416
 Joined: Tue Sep 16, 2008 5:38 pm
Re: GregoryHansen Cointegration Test
Probably the best thing to do is to learn about subroutines.
http://www.eviews.com/help/helpintro.ht ... ng.html%23
http://www.eviews.com/help/helpintro.ht ... ng.html%23
Follow us on Twitter @IHSEViews

 Posts: 88
 Joined: Tue Jun 29, 2010 7:09 am
Re: GregoryHansen Cointegration Test
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>92) 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!
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>92) 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!

 Posts: 88
 Joined: Tue Jun 29, 2010 7:09 am
Re: GregoryHansen Cointegration Test
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.
I found this post; Thinking my problem was related, I run you suggestion but I still get the same error message.
Thanks again.

 Nonnormality and collinearity are NOT problems!
 Posts: 3527
 Joined: Wed Sep 17, 2008 2:25 pm
Re: GregoryHansen Cointegration Test
(@TREND>92) is constant in your sample period.

 Posts: 88
 Joined: Tue Jun 29, 2010 7:09 am
Re: GregoryHansen Cointegration Test
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
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

 Nonnormality and collinearity are NOT problems!
 Posts: 3527
 Joined: Wed Sep 17, 2008 2:25 pm
Re: GregoryHansen Cointegration Test
Perhaps just delete that variable.
Re: GregoryHansen Cointegration Test
Hi,
I would like to know, how to apply Gregory  Hansen Cointegration Test using Eviews 10?
Taking into account that I have Y as the dependent variable and X1, X2 and X3 as the independent variables
Best wishes,
Salwan
I would like to know, how to apply Gregory  Hansen Cointegration Test using Eviews 10?
Taking into account that I have Y as the dependent variable and X1, X2 and X3 as the independent variables
Best wishes,
Salwan
Return to “Program Repository”
Who is online
Users browsing this forum: No registered users and 4 guests