Lumsdaine-Papell Unit Root 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

Lumsdaine-Papell Unit Root Test

Postby tcfoon » Fri May 29, 2009 7:43 am

Hello,

I have written the following programme for Lumsdaine-Papell Unit root test for two structural breaks.

Code: Select all

smpl @all

for !i = 9 to 41
for !k = !i+2 to 39
series DU1 = @trend> !i
series DT1 = DU1*(@trend-!i)
series DU2 = @trend>!k
series DT2 = DU2*(@trend-!k)
series DSY = D(SY)

equation LPA{!i}{!k}.ls DSY c SY(-1) DU1 DT1 DU2 DT2 DSY(-1 TO -2)

next
next


My problem is how to programme to ask Eviews to shows the selected structural break1 and break2?

Thank you,

Regards,
tcfoon
Last edited by tcfoon on Tue Sep 28, 2010 2:50 am, edited 1 time in total.

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

Re: Lumsdaine-Papell Unit Root Test

Postby trubador » Fri May 29, 2009 11:58 am

I have modified your code and added a simulation exercise into the beginning. Although the following code seems to be working and identifying the structural breaks correctly, you can make all the necessary modifications and revisions for more efficient and accurate use.

Code: Select all

'Simulate a series that has two level shifts
wfcreate u 100
!b1=17 'First break
!b2=45 'Second break

smpl @first !b1-1
series sy=@trend + 10*nrnd
smpl !b1 !b2-1
sy = 5*@trend + 20*nrnd
smpl !b2 @last
sy = 7*@trend + 30*nrnd

'Apply Lumsdaine-Papell unit-root test
smpl @all
!trim = 0.1 'Trimming parameter
!t_min = 1000
vector(2) breaks
for !i = @round(@obs(sy)*!trim) to @round(@obs(sy)*(1-!trim))
  for !k = !i+2 to @round(@obs(sy)*(1-!trim))-2
    series DSY = D(SY)
     equation temp.ls DSY c SY(-1) (@trend>!i) (@trend>!i)*(@trend-!i) (@trend>!k) (@trend>!k)*(@trend-!k) DSY(-1 TO -2)
       if temp.@tstats(2) < !t_min then
        !t_min = temp.@tstats(2)
        breaks(1) = !i+2 'Identified first break point.
        breaks(2) = !k+2 'Identified second break point
        series DU1 = @trend> !i
        series DT1 = DU1*(@trend-!i)
        series DU2 = @trend>!k
        series DT2 = DU2*(@trend-!k)
        equation LPA.ls DSY c SY(-1) DU1 DT1 DU2 DT2 DSY(-1 TO -2) 'Selected equation
       endif
  next
next
delete temp

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

Re: Lumsdaine-Papell Unit Root Test

Postby tcfoon » Fri May 29, 2009 6:59 pm

Dear Trubador,

Thank you very much for the coding. I am really appreciate your help..

Warmest regards,
tcfoon
Last edited by tcfoon on Tue Sep 28, 2010 2:50 am, edited 1 time in total.

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

Re: Lumsdaine-Papell Unit Root Test

Postby tcfoon » Fri May 29, 2009 8:35 pm

Dear Trubador,

I have modified the code for Zivot-Andrews (1992) unit root test and also include the lag length selection criterion AIC. My problem is that: How to write a command to ask Eviews to select the lag length from 0 to maxlag. The command I modified only select from 1 to Maxlag.

The modified code is presented as follow:

Code: Select all

smpl @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))
       for !lag = 1 to 4
    series DSY = D(SY)
     equation temp.ls DSY c SY(-1) (@trend>!i) (@trend>!i)*(@trend-!i) DSY(-1 TO -!lag)
   if temp.@aic < !min_aic then
     !best_lag = !lag
     !min_aic = temp.@aic
       if temp.@tstats(2) < !t_min then
        !t_min = temp.@tstats(2)
        breaks(1) = !i+2 'Identified first break point.
                series DU1 = @trend> !i
        series DT1 = DU1*(@trend-!i)
              equation ZA.ls DSY c SY(-1) DU1 DT1 DSY(-1 TO -!best_lag) 'Selected equation
       endif
       endif
  next
next
delete temp



Thank you,

Regards,
tcfoon
Last edited by tcfoon on Tue Sep 28, 2010 2:51 am, edited 1 time in total.

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

Re: Lumsdaine-Papell Unit Root Test

Postby trubador » Sat May 30, 2009 6:18 am

The following version should be doing what you want. Let me know, if encounter any problems.

Code: Select all

smpl @all
!trim = 0.15 'Trimming parameter
!t_min = 1000
!min_aic = 1000
vector(1) breaks
series DSY = D(SY)
for !lag=0 to 4
  for !i = @round(@obs(sy)*!trim) to @round(@obs(sy)*(1-!trim))
     if !lag = 0 then
        equation temp.ls DSY c SY(-1) (@trend>!i) (@trend>!i)*(@trend-!i)
      else
        equation temp.ls DSY c SY(-1) (@trend>!i) (@trend>!i)*(@trend-!i) DSY(-1 TO -!lag)
     endif
     if temp.@aic < !min_aic then
     !best_lag = !lag
     !min_aic = temp.@aic
       if temp.@tstats(2) < !t_min then
         !t_min = temp.@tstats(2)
         breaks(1) = !i+2 'Identified first break point.
         series DU1 = @trend> !i
         series DT1 = DU1*(@trend-!i)
           if !best_lag = 0 then
             equation ZA.ls DSY c SY(-1) DU1 DT1 'Selected equation
           else
             equation ZA.ls DSY c SY(-1) DU1 DT1 DSY(-1 TO -!best_lag) 'Selected equation
           endif             
       endif
     endif
  next
next
delete temp

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

Re: Lumsdaine-Papell Unit Root Test

Postby tcfoon » Sat May 30, 2009 10:19 am

Dear Trubador,

I have tested the programme code and it is running well. However, I found that this programme tend to select the zero lag length even when the AIC for lag one is smaller that AIC for lag zero. In addition, I have modified the Lumsdaine-Papell code according to your suggestion. I also detected the same problem that the programme test to select lag zero. I suspect that there are some mistake in the coding. Overall, the code that you write is rational, I also failed to find the gap or problem cause this.

Here, I hope you could do something.

Thank you,

Regards,
tcfoon
Last edited by tcfoon on Tue Sep 28, 2010 2:51 am, edited 1 time in total.

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

Re: Lumsdaine-Papell Unit Root Test

Postby trubador » Sat May 30, 2009 11:53 am

If you are using the simulated series from the first code, then it is normal to expect the code to select zero lag since those series were generated that way. Please try the following simulated series, and you'll see that the code works fine (both in terms of estimating the parameters and locating the break). Yet, if you still think there is a problem, just let me know and I'll look into it in detail.

Code: Select all

'Simulate a series that has a single break
wfcreate u 100
!b1=21 'Location of the break
series sy=0
smpl @first+3 @last
sy = 7 -.2*sy(-1) + 130*(@trend>!b1-2) + 8*(@trend>!b1-2)*(@trend-!b1+2) +.8*d(sy(-1)) +.5*d(sy(-2)) + 20*nrnd

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

Re: Lumsdaine-Papell Unit Root Test

Postby tcfoon » Sun May 31, 2009 3:38 am

Dear Trubador,

Thank you very much for spending time to modified the code. I make a mistake and the code should be not problem because I am confusing the structural break selection procedure is based on t-statistics on the one period lagged level variable and not the AIC. I have tested again, although I can get smaller AIC but the t-statistics is not the smallest. So your code is no problem.

Apart from that, do you know how to ask Eviews to run the modified code for structural break unit root test for a group of variables?

Thank you,

Regards,
tcfoon
Last edited by tcfoon on Tue Sep 28, 2010 2:52 am, edited 1 time in total.

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

Re: Lumsdaine-Papell Unit Root Test

Postby trubador » Sun May 31, 2009 4:19 am

I also referred to the original study to verify it. And yes, selection procedure becomes more complicated when you also decide to find the optimum lag order along with the identification of the structural break. This is mainly due to interaction between AIC and t-value, where the latter has a priority in pinpointing the structural break. Therefore, I conducted a more general simulation exercise to see the efficiency and the accuracy of the code. I generated a series that has one structural break and two autoregressive orders. I ran the code 10,000 times and it correctly identified the location of the break in 9,828 cases, whereas it has successfully selected the correct lag order in 6,731 cases. Of course, results are sensitive to magnitude of disturbance term, where I preffered not to generate a conservative one.

You can refer to i-th series in a group (e.g. grp) via the command grp(i). So it is relatively straightforward to use the code for each series in a group. For instance, you can put another for-loop around the original code and repeat the analysis for all the series in the group. Something like:

Code: Select all

for !s=1 to !n
series y{!s} = grp(!s)
series dy{!s} = d(y{!s})
.....
.....
next

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

Re: Lumsdaine-Papell Unit Root Test

Postby tcfoon » Sun May 31, 2009 8:55 am

Dear Trubador,

Thank you very much your help and I get your idea and I have programme it. My second plan is to write a programme for Gregory-Hansen (1996) cointegration I will post to the forum get your comment and improvement. Of course, it is much more appreciate if you can write it as usually the way I write the programme is very long compare to the expert.

Thank you,

Regards,
tcfoon
Last edited by tcfoon on Tue Sep 28, 2010 2:52 am, edited 1 time in total.

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

Re: Lumsdaine-Papell Unit Root Test

Postby trubador » Sun May 31, 2009 10:24 am

It would be my pleasure to help you write another procedure. Looking forward to it...

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

Re: Lumsdaine-Papell Unit Root Test

Postby tcfoon » Sun May 31, 2009 4:46 pm

Dear Trubador,

Thank you for your time spent and willingness to help me. Regarding the unit root programme, I encountered some problems within the programme written for Zivot-Andrews unit root for a group of series. According to your advice, I have came out the following code for group of series:

Code: Select all

Group g lnm2 lny r lnex
table ZAZ
for !kk = 1 to g.@count
%name = g.@seriesname(!kk)
series Y  = {%name}
!trim = 0.15 'Trimming parameter
!t_min = 1000
!min_aic = 1000
vector(1) breaks
series DY = D(Y)
for !lag=0 to 4 
for !i = @round(@obs(Y)*!trim) to @round(@obs(Y)*(1-!trim))
     if !lag = 0 then
        equation temp.ls DY Y(-1) C @trend (@trend>!i)
      else
        equation temp.ls DY Y(-1) C @trend (@trend>!i) DY(-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
                    if !best_lag = 0 then
             equation ZA.ls DY Y(-1) C @trend DU1 'Selected equation
           else
             equation ZA.ls DY Y(-1) C @trend DU1 DY(-1 to -!best_lag) 'Selected equation
           endif             
     endif
endif
  next
next
ZAZ(1,1) = "Variables"
setline(ZAZ, 2)
ZAZ(3,1) = "t-stat"
ZAZ(4,1) = "Lag"
ZAZ(5,1) = "Breaks1"
ZAZ(6,1) = "DU1-tstat"
ZAZ(1,1+!kk) = %name
ZAZ(3,1+!kk) = ZA.@tstat(1)
ZAZ(4,1+!kk) = !best_lag
ZAZ(5,1+!kk) = breaks(1)
ZAZ(6,1+!kk) = @tstat(4)
next
delete temp
show ZAZ


Regret to inform that, the lag length shows in table "ZAZ(4,1)" is not the lag order used to compute the ZA test. For example, if I run the programe without grouping the series(i.e. individual series programme) then the lag length show on the estimated equation output is zero, while when I use the above command its lag length has been changed to three (3). How can I modified the programme code, thus the results in table ZAZ become consistent to the output?

Apart from that, for table "ZAZ(6,1)", I have programmed to show the t-statistics for the dummy variables, but is it plausible to show p-value?

Finally, why the "setline(ZAZ, 2)" command does not perform for the last variable result? - For your information, this is not an important issue, don't spend to much time at this stage.

Thank you in advance,

Warmest regards,
tcfoon
Last edited by tcfoon on Tue Sep 28, 2010 2:53 am, edited 1 time in total.

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

Re: Lumsdaine-Papell Unit Root Test

Postby trubador » Mon Jun 01, 2009 12:52 am

The following version might help:

Code: Select all

Group g lnm2 lny r lnex
table ZAZ
for !kk = 1 to g.@count
%name = g.@seriesname(!kk)
series Y  = {%name}
call zivot(Y)
ZAZ(1,1) = "Variables"
ZAZ(3,1) = "t-stat"
ZAZ(4,1) = "Lag"
ZAZ(5,1) = "Breaks1"
ZAZ(6,1) = "DU1 p-value"
ZAZ(1,1+!kk) = %name
ZAZ(3,1+!kk) = !t_min
ZAZ(4,1+!kk) = !best_lag
ZAZ(5,1+!kk) = breaks(1)
ZAZ(6,1+!kk) = @tdist(za.@tstat(4),za.@regobs-za.@ncoef) 'I would prefer t-statistics, since this will yield very small p-values.
setline(ZAZ, 2)
next
show ZAZ

subroutine zivot(series y)
!trim = 0.15 'Trimming parameter
!t_min = 1000
!min_aic = 1000
vector(1) breaks
series DY = D(Y)
for !lag=0 to 4 
  for !i = @round(@obs(Y)*!trim) to @round(@obs(Y)*(1-!trim))
     if !lag = 0 then
        equation temp.ls DY Y(-1) C @trend (@trend>!i)
      else
        equation temp.ls DY Y(-1) C @trend (@trend>!i) DY(-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
           if !best_lag = 0 then
           equation ZA.ls DY Y(-1) C @trend DU1 'Selected equation
           else
           equation ZA.ls DY Y(-1) C @trend DU1 DY(-1 to -!best_lag) 'Selected equation
           endif             
      endif
    endif
  next
next
delete temp
endsub

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

Re: Lumsdaine-Papell Unit Root Test

Postby tcfoon » Mon Jun 01, 2009 1:29 am

Dear Trubador,

Thank you for modified the programme for me. The results is same as before that is the final ZA output is zero lag that yield higher absolute value of t-statistics, but the group series programme show that the selected lag length is 4. The rest of the thing is consistent, except lag only. In fact, the former and later programme should yield the same results as the different only (1) running inside the programme, while (2) running outside the sub-routine. With this email, I attached the workfile for you to have a try..

Thank you,

Regards,
tcfoon
Attachments
Japan M2.WF1
(15.42 KiB) Downloaded 483 times
Last edited by tcfoon on Tue Sep 28, 2010 2:54 am, edited 1 time in total.

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

Re: Lumsdaine-Papell Unit Root Test

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

I think the following minor revision will solve the problem. Yet, I still believe that the procedure itself is not very efficient in identifying the optimal lag order.

Code: Select all

Group g lnm2 lny r lnex
table ZAZ
vector(4) lags
for !kk = 1 to g.@count
%name = g.@seriesname(!kk)
series Y  = {%name}
ZAZ(1,1) = "Variables"
ZAZ(3,1) = "t-stat"
ZAZ(4,1) = "Lag"
ZAZ(5,1) = "Breaks1"
ZAZ(6,1) = "DU1 p-value"
call zivot(Y)
ZAZ(1,1+!kk) = %name
ZAZ(3,1+!kk) = !t_min
ZAZ(4,1+!kk) = !final_lag
ZAZ(5,1+!kk) = breaks(1)
ZAZ(6,1+!kk) = @tdist(za.@tstat(4),za.@regobs-za.@ncoef) 'I would prefer t-statistics, since this will yield very small p-values.
setline(ZAZ, 2)
next
show ZAZ

subroutine zivot(series y)
!trim = 0.15 'Trimming parameter
!t_min = 1000
!min_aic = 1000
vector(1) breaks
series DY = D(Y)
for !lag=0 to 4 
  for !i = @round(@obs(Y)*!trim) to @round(@obs(Y)*(1-!trim))
    if !lag = 0 then
        equation temp.ls DY Y(-1) C @trend (@trend>!i)
      else
        equation temp.ls DY Y(-1) C @trend (@trend>!i) DY(-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
           if !best_lag = 0 then
           equation ZA.ls DY Y(-1) C @trend DU1 'Selected equation
           !final_lag=!best_lag
           else
           equation ZA.ls DY Y(-1) C @trend DU1 DY(-1 to -!best_lag) 'Selected equation
           !final_lag=!best_lag
           endif             
      endif
    endif
  next
next
delete temp
endsub


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 3 guests