My master´s thesis is due in three days and I need help urgently!
I have written a program for ARDL(n,n,n,n,) optimal lag selection using Schwarz. The program is based on Eviews_Gareth´s lag selector from the programming guide. The problem is that it will never choose lag level zero as optimal. Manual testing indicate a zero lag length to be optimal in a majority of the 154 equations.
What am I doing wrong? Please help!
---------------------------------------------------
'This program should find the best lag length for the ARDL(n,n,n,n,) model using SchwarzIC, it will freeze the table and rename the eq according to your wish. It will also perform a Wald-test on the level (Long-run) coefficients
' jjjj (_263 Cotton) and k (_265 Vegetable fibres, except cotton and) is excluded from list below because insufficient number of observations, so is now also ccc(_041_Wheat), dddd (052_Dried Fruit) hhhh mm
'Delete old matrix
'd waldmatrix
'd tablematrix
'd phimatrix
'd constantmatrix
' Delete old eq, table and wald files
'd wald_{%product}
'd eq_{%product}
'd table_{%product}
''matrix to hold all of the results
matrix(154,2) waldmatrix
matrix(154,43) tablematrix
matrix(154,8) phimatrix
matrix(154,2) constantmatrix
''counter of how many equations we have run
!rowcounter=1
for %product a aa aaa aaaa b bb bbb bbbb cc cccc ccccc dd ddd ddddd e ee eee eeee f ff fff ffff g gg ggg gggg h hh hhh i ii iii iiii j jj jjj kk kkk kkkk l ll lll llll m mmm mmmm n nn nnn nnnn o oo ooo oooo p pp ppp pppp q qq qqq qqqq r rr rrr rrrr s ss sss ssss t tt ttt tttt u uu uuu uuuu v vv vvv vvvv x xx xxx xxxx y yy yyy yyyy z za zaa zaaa zaaaa zb zbb zbbb zbbbb zc zcc zccc zcccc zd zdd zddd zdddd ze zee zeee zeeee zf zff zfff zffff zg zgg zggg zgggg zh zhh zhhh zhhhh zi zii ziii ziiii zj zjj zjjj zjjjj zk zkk zkkk zkkkk zl zll zlll zllll zm zmm zmmm zmmmm zn znn znnn znnnn zo zoo zooo zoooo zz zzz zzzz
'create emp y equation to be used inside the loop
equation eq
'variable to store the minimum SBC. Initialise it to a large number
!sbc = 99999999
'variable saying how many lags to go up to
!maxlags = 3
'Variable to store the "best" number of lags
!bestlag = 8
'set sample to be the !maxlag'th value onwards
smpl @first+!maxlags @last
'---------------- Lag finder --------------------
for !i=0 to !maxlags
'run regression of product(whatever) in the ARDL framwork to find best lag length, since Autoregressive model dependent variable should enter the right side as lagged
eq.ls diff_{%product} c diff_{%product}(-1 to -!i) diff_yse(0 to -!i) diff_yde(0 to -!i) diff_rebex(0 to -!i) {%product}(-1) yse(-1) yde(-1) rebex(-1)
if eq.@schwarz < !sbc then
!bestlag = !i 'if this lag specification has the best SBC, then store this lag as !bestlag.
!sbc = eq.@schwarz
endif
next
' ---------------------- Run regression with bestlag -------------
freeze(table_{%product}) eq.ls diff_{%product} c diff_{%product}(-1 to -!bestlag) diff_yse(0 to -!bestlag) diff_yde(0 to -!bestlag) diff_rebex(0 to -!bestlag) {%product}(-1) yse(-1) yde(-1) rebex(-1)
rename eq eq_{%product}
!bestlagrange = 0
'---------- Wald-test on level coeffs------
'Perform wald test on an eq with lag lenth 1, 2 or 3 depending on bestlag and freeze it in table
if !bestlag = 1 then
freeze(wald_{%product}) eq_{%product}.wald c(9)=c(10)=c(11)=c(12)=0 ' changed from 6, 7, 8, 9
!bestlagrange = 12
endif
if !bestlag = 2 then
freeze(wald_{%product}) eq_{%product}.wald c(13)=c(14)=c(15)=c(16)=0 ' changed from 9, 10, 11, 12
!bestlagrange = 16
endif
if !bestlag = 3 then
freeze(wald_{%product}) eq_{%product}.wald c(17)=c(18)=c(19)=c(20)=0 ' changed from 14, 15, 16, 17
!bestlagrange = 20
endif
'9-20
'9-24
'9-28
'-------Storing results in matrices-------
' Store all tables result into big matrix
waldmatrix(!rowcounter,1) = @val(wald_{%product}(6,2))
waldmatrix(!rowcounter,2) = @val(wald_{%product}(6,4))
tablematrix(!rowcounter,1) = !bestlag
tablematrix(!rowcounter,2) = @val(@mid(table_{%product}(5, 1), 24, 2)) ' get included observations which is a 2 digit number at position 24 in string
tablematrix(!rowcounter,3) = @val(table_{%product}(11+!bestlagrange, 2)) ' get adjusted r-square
' Get all coefficients values
for !i=1 to !bestlagrange
tablematrix(!rowcounter,!i+3) = @val(table_{%product}(!i+8, 2))
next
'Get all p-values
for !i=1 to !bestlagrange
tablematrix(!rowcounter,!i+23) = @val(table_{%product}(!i+8, 5))
next
'Get Phi-prod coeffs
if !bestlag = 1 then
phimatrix(!rowcounter,1) = @val(table_{%product}(17,2)) 'Prod
phimatrix(!rowcounter,2) = @val(table_{%product}(17,5)) 'PvalProd
phimatrix(!rowcounter,3) = @val(table_{%product}(18,2)) 'Yse
phimatrix(!rowcounter,4) = @val(table_{%product}(18,5)) 'PvalYse
phimatrix(!rowcounter,5) = @val(table_{%product}(19,2)) 'Yde
phimatrix(!rowcounter,6) = @val(table_{%product}(19,5)) 'PvalYde
phimatrix(!rowcounter,7) = @val(table_{%product}(20,2)) 'REBEX
phimatrix(!rowcounter,8) = @val(table_{%product}(20,5)) 'PvalREBEX
endif
if !bestlag = 2 then
phimatrix(!rowcounter,1) = @val(table_{%product}(21,2)) 'Prod
phimatrix(!rowcounter,2) = @val(table_{%product}(21,5)) 'PvalProd
phimatrix(!rowcounter,3) = @val(table_{%product}(22,2)) 'Yse
phimatrix(!rowcounter,4) = @val(table_{%product}(22,5)) 'PvalYse
phimatrix(!rowcounter,5) = @val(table_{%product}(23,2)) 'Yde
phimatrix(!rowcounter,6) = @val(table_{%product}(23,5)) 'PvalYde
phimatrix(!rowcounter,7) = @val(table_{%product}(24,2)) 'REBEX
phimatrix(!rowcounter,8) = @val(table_{%product}(24,5)) 'PvalREBEX
endif
if !bestlag = 3 then
phimatrix(!rowcounter,1) = @val(table_{%product}(25,2)) 'Prod
phimatrix(!rowcounter,2) = @val(table_{%product}(25,5)) 'PvalProd
phimatrix(!rowcounter,3) = @val(table_{%product}(26,2)) 'Yse
phimatrix(!rowcounter,4) = @val(table_{%product}(26,5)) 'PvalYse
phimatrix(!rowcounter,5) = @val(table_{%product}(27,2)) 'Yde
phimatrix(!rowcounter,6) = @val(table_{%product}(27,5)) 'PvalYde
phimatrix(!rowcounter,7) = @val(table_{%product}(28,2)) 'REBEX
phimatrix(!rowcounter,8) = @val(table_{%product}(28,5)) 'PvalREBEX
endif
'Store Constant and its p-val in separate tabel "constantmatrix"
if !bestlag = 1 then
constantmatrix(!rowcounter,1) = @val(table_{%product}(9,2)) 'Coeff
constantmatrix(!rowcounter,2) = @val(table_{%product}(9,5)) 'P-val
endif
if !bestlag = 2 then
constantmatrix(!rowcounter,1) = @val(table_{%product}(9,2)) 'Coeff
constantmatrix(!rowcounter,2) = @val(table_{%product}(9,5)) 'P-val
endif
if !bestlag = 3 then
constantmatrix(!rowcounter,1) = @val(table_{%product}(9,2)) 'Coeff
constantmatrix(!rowcounter,2) = @val(table_{%product}(9,5)) 'P-val
endif
!rowcounter=!rowcounter+1 ' increment row counter
'reset sample
smpl @all
'-----------------End of program--------------
next
show waldmatrix
show tablematrix
show phimatrix
show constantmatrix
------------------------------------------------------------------------------------
Help in all forms is appreciated, via forum, email or phone!
PLEASE ANYONE HELP!
Franz
On Eviews 5
Urgent Help Needed, thesis deadline in danger!
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13603
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Urgent Help Needed, thesis deadline in danger!
The problem is here:
Think about what happens during the first iteration (i.e. when i=0)
Code: Select all
for !i=0 to !maxlags
'run regression of product(whatever) in the ARDL framwork to find best lag length, since Autoregressive model dependent variable should enter the right side as lagged
eq.ls diff_{%product} c diff_{%product}(-1 to -!i) diff_yse(0 to -!i) diff_yde(0 to -!i) diff_rebex(0 to -!i) {%product}(-1) yse(-1) yde(-1) rebex(-1)
Re: Urgent Help Needed, thesis deadline in danger!
Hi Gareth,
thanks you very much for your response!
I have substituted the for loop with:
'Run the 0 lag and store the SBC from it
eq.ls diff_{%product} c diff_{%product}(-1) diff_yse diff_yde diff_rebex {%product}(-1) yse(-1) yde(-1) rebex(-1)
!sbc=eq.@schwarz
'Run 1 lag and store SBC value
eq.ls diff_{%product} c diff_{%product}(-1) diff_yse(-1) diff_yde(-1) diff_rebex(-1) {%product}(-1) yse(-1) yde(-1) rebex(-1)
if eq.@schwarz< !sbc then
!bestlag=1
endif
'Run 2 lag and store SBC value
eq.ls diff_{%product} c diff_{%product}(-1) diff_{%product}(-2) diff_yse(-1) diff_yse(-2) diff_yde(-1) diff_yde(-2) diff_rebex(-1) diff_rebex(-2) {%product}(-1) yse(-1) yde(-1) rebex(-1)
if eq.@schwarz< !sbc then
!bestlag=2
endif
'Run 3 lag and store SBC value
eq.ls diff_{%product} c diff_{%product}(-1) diff_{%product}(-2) diff_{%product}(-3) diff_yse(-1) diff_yse(-2) diff_yse(-3) diff_yde(-1) diff_yde(-2) diff_yde(-3) diff_rebex(-1) diff_rebex(-2) diff_rebex(-3) {%product}(-1) yse(-1) yde(-1) rebex(-1)
if eq.@schwarz< !sbc then
!bestlag=3
endif
---------
!bestlag is still initially set to 0 and everything is unchanged.
It now chooses the 0 lag length from time to time but not corresponding to the manual tests i ran, might this be because the program uses a fixed sample and in the manual test I don´t? Or is the problem now something else?
I treasure your help Gareth.
BR Franz
thanks you very much for your response!
I have substituted the for loop with:
'Run the 0 lag and store the SBC from it
eq.ls diff_{%product} c diff_{%product}(-1) diff_yse diff_yde diff_rebex {%product}(-1) yse(-1) yde(-1) rebex(-1)
!sbc=eq.@schwarz
'Run 1 lag and store SBC value
eq.ls diff_{%product} c diff_{%product}(-1) diff_yse(-1) diff_yde(-1) diff_rebex(-1) {%product}(-1) yse(-1) yde(-1) rebex(-1)
if eq.@schwarz< !sbc then
!bestlag=1
endif
'Run 2 lag and store SBC value
eq.ls diff_{%product} c diff_{%product}(-1) diff_{%product}(-2) diff_yse(-1) diff_yse(-2) diff_yde(-1) diff_yde(-2) diff_rebex(-1) diff_rebex(-2) {%product}(-1) yse(-1) yde(-1) rebex(-1)
if eq.@schwarz< !sbc then
!bestlag=2
endif
'Run 3 lag and store SBC value
eq.ls diff_{%product} c diff_{%product}(-1) diff_{%product}(-2) diff_{%product}(-3) diff_yse(-1) diff_yse(-2) diff_yse(-3) diff_yde(-1) diff_yde(-2) diff_yde(-3) diff_rebex(-1) diff_rebex(-2) diff_rebex(-3) {%product}(-1) yse(-1) yde(-1) rebex(-1)
if eq.@schwarz< !sbc then
!bestlag=3
endif
---------
!bestlag is still initially set to 0 and everything is unchanged.
It now chooses the 0 lag length from time to time but not corresponding to the manual tests i ran, might this be because the program uses a fixed sample and in the manual test I don´t? Or is the problem now something else?
I treasure your help Gareth.
BR Franz
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13603
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Urgent Help Needed, thesis deadline in danger!
It is probably the sample issue you mentioned.
Re: Urgent Help Needed, thesis deadline in danger!
Ok,
thank you so much Gareth!
I am very grateful to you for helping me.
Best regards
Franz
thank you so much Gareth!
I am very grateful to you for helping me.
Best regards
Franz
Who is online
Users browsing this forum: No registered users and 1 guest
