GregoryHansen Cointegration Test
Moderators: EViews Gareth, EViews Moderator
Re: GregoryHansen Cointegration Test
It works well now! Thanks a lot QMS Gareth! thanks also to trubador!
Re: GregoryHansen Cointegration Test
Sorry, I have a problem when I run the code selecting regime shift (that is, selecting 4 in the part "call greghansen(log_pce_r_pc,independents,4,"aic",8)"). Eviews gives this message of error: "Near Singular Matrix in "Do_ghc.ls Y C (@trend>352) G".
Re: GregoryHansen Cointegration Test
Again you should post your workfile along with the code. "Near Singular Matrix" is a very common error, so it is difficult to determine the problem without seeing the original files.
Re: GregoryHansen Cointegration Test
Here is the workfile with my code. Thanks.
Another question: if the potential structural break is at the end of sample (that is, 2004q1), GH test can ascertain it?
Another question: if the potential structural break is at the end of sample (that is, 2004q1), GH test can ascertain it?
 Attachments

 my_workfile.wf1
 (57.61 KiB) Downloaded 785 times

 prog_gh_prova.prg
 (4.88 KiB) Downloaded 842 times
Re: GregoryHansen Cointegration Test
You should group your variables outside the program (in the command line for instance). Otherwise, each time you run the code with different independent variables it adds these variables into the same group (e.g. independents), which ultimately leads to singularity. Therefore, I suggest you to form your group of variables first and run the code later with supplying the name of the group as input. Please do not forget to generate a new group when you decide to work with a different set of variables.
In the command line type the following one at a time:
Then in the program window simply call the subroutine:
Regarding to your second question, please note that the analysis is based on sequentially generating dummy and trend variables and the trimming parameter adjusts your sample to allow this type of analysis. In the code above, the parameter is set to 0.15, which means 15% of observations from both ends will not be checked for a break. If your sample is large enough, you can lower the value of this parameter without any loss of generality. However, you should keep in mind that doing so might lead to a/n meaningless/infeasible trend variable.
In the command line type the following one at a time:
Code: Select all
group independents
independents.add log_ylyt_r log_stnw_r log_nstnw_r fedf_n
Then in the program window simply call the subroutine:
Code: Select all
call greghansen(log_pce_r_pc,independents,4,"aic",8)
....
Regarding to your second question, please note that the analysis is based on sequentially generating dummy and trend variables and the trimming parameter adjusts your sample to allow this type of analysis. In the code above, the parameter is set to 0.15, which means 15% of observations from both ends will not be checked for a break. If your sample is large enough, you can lower the value of this parameter without any loss of generality. However, you should keep in mind that doing so might lead to a/n meaningless/infeasible trend variable.
Re: GregoryHansen Cointegration Test
I have tried to create independently the independents group in the line command and then recall it in the program as you suggested. But it appears the same error of near singluar matrix. If you have a little time you can prove. Thanks.
I have also tried to reduce the trimming (I have simply change the line command: "!trim = 0.15" with "!trim = 0.05") but the same message error appears ("near singular matrix in do.ghc.ls Y C G (@trend>232)).
I have also tried to reduce the trimming (I have simply change the line command: "!trim = 0.15" with "!trim = 0.05") but the same message error appears ("near singular matrix in do.ghc.ls Y C G (@trend>232)).
 Attachments

 prog_gh_prova.prg
 (4.8 KiB) Downloaded 502 times

 my_workfile.wf1
 (50.03 KiB) Downloaded 455 times
Re: GregoryHansen Cointegration Test
There are missing observations in your variables. Resizing the range of your workfile to 1952Q2 2012Q1 would do I guess.
Re: GregoryHansen Cointegration Test
I have tried to reduce the sample to 1955q1 2009q2, but the same error appears.
Re: GregoryHansen Cointegration Test
Resizing the sample will not work. You should adjust the range altogether, which means there should be no missing values in your variables in the beginning. Of course, this is just a workaround for now to help you make some progress on your study. I'll try to figure out something else, if the problem is really caused by these missing values.
Re: GregoryHansen Cointegration Test
I have generated a new workfile in eviews without NA at the beginning as suggested by trubador. The code now works well. Thanks a lot trubador!
Re: GregoryHansen Cointegration Test
hello sir
i am completely new to eviews.was trying to run the gregory hansen code in eviews 5 but the software reports this error:
@CMIN is an illegal or reserved name in vector min_t_lag = @cmin(GHtest)..
also if u can refer me some link whr i can read more details about reading codes!!
thank you
i am completely new to eviews.was trying to run the gregory hansen code in eviews 5 but the software reports this error:
@CMIN is an illegal or reserved name in vector min_t_lag = @cmin(GHtest)..
also if u can refer me some link whr i can read more details about reading codes!!
thank you
Re: GregoryHansen Cointegration Test
That is because the function is not supported in earlier versions of EViews. Please try the modified version below. For more information on the use of EViews' programming features, please refer to the manual and the examples listed in EViews' directory...
Code: Select all
'GregoryHansen Cointegration Test
'Reference: Gregory, A. W. and Hansen, B. E. (1996). "ResidualBased Tests for Cointegration in Models with Regime Shifts", Journal of Econometrics, Vol. 70, pp. 99126.
call greghansen(y,x,2,"aic",6)
' 
' Arguments
'
'series Y ' dependent variable
'group G ' group of independent variable(s) (including single series)
'scalar Model ' 2 = Level Shift, 3 = Level Shift with Trend, 4 = Regime Shift
'scalar Maxlag ' Maximum number of lags for unit root testing
'string %Criterion ' Selection criteria for unit root testing (i.e. aic / sic / hqc)
' 
subroutine greghansen(series Y, group G, scalar Model, string %Criterion, scalar Maxlag)
smpl @all
!trim = 0.15
!maxlag = Maxlag
!n = @obs(y)
!nindep = G.@count
!lower = @round(@obs(Y)*!trim)
!upper = @round(@obs(Y)*(1!trim))
matrix(!upper!lower+1,4) GHtest
equation ghc
Table GHZ
GHZ(1,1) = "THE GREGORYHANSEN"
GHZ(2,1) = "COINTEGRATION TEST"
if Model=2 then GHZ(3,1) = "MODEL 2: Level Shift"
else if Model =3 then GHZ(3,1) = "MODEL 3: Level Shift with Trend"
else if Model = 4 then GHZ(3,1) = "MODEL 4: Regime Shift"
endif
endif
endif
GHZ(5,1) = "ADF Procedure"
GHZ(7,1) = "tstat"
GHZ(8,1) = "Lag"
GHZ(9,1) = "Break"
GHZ(11,1) = "Phillips Procedure"
GHZ(13,1) = "Zastat"
GHZ(14,1) = "Zabreak"
GHZ(15,1) = "Ztstat"
GHZ(16,1) = "Ztbreak"
for !ref = 2 to 4
GHZ.setwidth(!ref) 15
next
GHZ.setlines(a4:b4) +d
GHZ.setlines(a6:b6) +d
GHZ.setlines(a10:b10) +d
GHZ.setlines(a12:b12) +d
for !i = !lower to !upper
if Model=2 then
'MODEL 2  C: LEVEL SHIFT MODEL
ghc.ls Y c G (@trend>!i2)
ghc.makeresid res
uroot(adf, none, info={%criterion}, maxlag=!maxlag, save=level) res
GHtest(!i!lower+1,1) = level(3,1)
GHtest(!i!lower+1,2) = level(2,1)
call phillips(res)
GHtest(!i!lower+1,3) = !Za
GHtest(!i!lower+1,4) = !Zt
else if Model=3 then
'MODEL 3  C/T: LEVEL SHIFT WITH TREND MODEL
ghc.ls Y c @trend G (@trend>!i2)
ghc.makeresid res
uroot(adf, none, info={%criterion}, maxlag=!maxlag, save=level) res
GHtest(!i!lower+1,1) = level(3,1)
GHtest(!i!lower+1,2) = level(2,1)
call phillips(res)
GHtest(!i!lower+1,3) = !Za
GHtest(!i!lower+1,4) = !Zt
else if Model = 4 then
'MODEL 4  C/S: REGIME SHIFT MODEL
for !g = 1 to !nindep
G.add (@trend>!i2)*G(!g)
next
ghc.ls Y c (@trend>!i2) G
ghc.makeresid res
uroot(adf, none, info={%criterion}, maxlag=!maxlag, save=level) res
GHtest(!i!lower+1,1) = level(3,1)
GHtest(!i!lower+1,2) = level(2,1)
call phillips(res)
GHtest(!i!lower+1,3) = !Za
GHtest(!i!lower+1,4) = !Zt
for !g = G.@count to !nindep+1 step 1
%name = G.@seriesname(!g)
G.drop {%name}
next
endif
endif
endif
next
vector(3) break
!i =1
while !i<=!upper!lower+1
if GHtest(!i,1) = @min(@columnextract(GHtest,1)) then
break(1) = !i
endif
if GHtest(!i,3) = @min(@columnextract(GHtest,3)) then
break(2) = !i
endif
if GHtest(!i,4) = @min(@columnextract(GHtest,4)) then
break(3) = !i
endif
!i = !i+1
wend
GHZ(7,2) = @min(@columnextract(GHtest,1))
GHZ(8,2) = GHtest(break(1),2)
GHZ(13,2) = @min(@columnextract(GHtest,3))
GHZ(15,2) = @min(@columnextract(GHtest,4))
GHZ(9,2) = @otod(break(1) + !lower  2)
GHZ(14,2) = @otod(break(2) + !lower  2)
GHZ(16,2) = @otod(break(3) + !lower  2)
show GHZ
delete res level GHtest break
endsub
subroutine phillips(series y) 'MATLAB code of this routine is available at Bruce E. Hansen's website: http://www.ssc.wisc.edu/~bhansen/progs/joe_96.html
!n = @obs(y)
equation eq1.ls y y(1)
!be = eq1.@coefs(1)
series ue = y  !be*y(1)
'Bandwidth selection
!nu = @obs(ue)
equation eq2.ls ue ue(1)
!bu = eq2.@coefs(1)
series uu = ue  !bu*ue(1)
!su = @sumsq(uu)/@obs(uu)
!a2 = (4*!bu^2*!su/(1!bu)^8)/(!su/(1!bu)^4)
!bw =1.3221*((!a2*!nu)^0.2)
!pi = @acos(1)
!j=1
!lemda = 0
while !j <= !bw
series temp = ue*ue(!j)
!gama = @sum(temp)/!nu
!w=(75/(6*!pi*!j/!bw)^2)*(@sin(1.2*!pi*!j/!bw)/(1.2*!pi*!j/!bw)@cos(1.2*!pi*!j/!bw))
!lemda=!lemda+!w*!gama
!j=!j+1
wend
series temp = y*y(1)  !lemda
!p = @sum(temp)/@sumsq(y(1))
!Za = !n*(!p1)
!Zt = (!p1)/@sqrt((2*!lemda + @sumsq(ue)/!nu)/(@sumsq(y(1))))
smpl @all
delete eq1 eq2 ue uu temp
endsub
Re: GregoryHansen Cointegration Test
Hello,
I would like to test cointegration with two unknow regime shifts, as Abdulnasser HatemiJ(2008) "Testing cointegration with two unknown regime shifts with an application to financial market integration". The program code (Gregory Hansen Cointegration Test) you provided above tests for one unknown regime shift. My programming skills are very poor therefore I would appreciate your help me to update the above code.
I would appreciate your response.
Kinga
I would like to test cointegration with two unknow regime shifts, as Abdulnasser HatemiJ(2008) "Testing cointegration with two unknown regime shifts with an application to financial market integration". The program code (Gregory Hansen Cointegration Test) you provided above tests for one unknown regime shift. My programming skills are very poor therefore I would appreciate your help me to update the above code.
I would appreciate your response.
Kinga
 Attachments

 Tests for cointegration with two unknown regime shifts.pdf
 (134.04 KiB) Downloaded 1146 times
Re: GregoryHansen Cointegration Test
Dear Mr. Trubador and Mr. Gareth, I'm a researcher in Brazil and found this code very useful for my studies. I started making the corrections for earlier versions as presented by Mr. Gareth and everything run alright. I used 1 dep. variable against 3 indep. variables. Well, my difficulty is that I want to run the test using just 1 dependent variable against 1 independent variable, or even 2 independents variables, but the program even returns the results for 1 dep. against 3 indeps. So I have two questions: (a) how to perform the test in such a way(s); and (b) why the test do not perform the Wald statistics? Thank you very much in advance. Margalef.
Re: GregoryHansen Cointegration Test
Hi Trubador,
I need some help on the GH cointegration. Is there any way to get the coefficients of the GregoryHansen cointegration? I mean coefficients such as those included in Eviews' Johansen's cointegrating equation.
Thanks in advance.
Gordeza
I need some help on the GH cointegration. Is there any way to get the coefficients of the GregoryHansen cointegration? I mean coefficients such as those included in Eviews' Johansen's cointegrating equation.
Thanks in advance.
Gordeza
Return to “Program Repository”
Who is online
Users browsing this forum: No registered users and 4 guests