Hi
I have been working on estimating a VAR model. I have two sets of variables..each group has 51 variables..but I will be estimating the model in pairs so that y(i) and x(i) will form one VAR model, y(i+1) and 'x(i+1) forms second var model and so on...so I will have 51 bi-variate VAR models.
Enclosed below is my code thus far, stitched from various sources:
group y
group z
for !i=1 to y.@count
for !j=1 to z.@count
%iname = y.@seriesname(!i)
%jname = z@seriesname(!i)
var var_{%iname}_{%jname}.ls 1 8 {%iname} {%jname}
next
next
The above code gives me the desired result--it saves the VAR output for 51 var models in the workfile. My question is can I similarly store the lag length selection results for each model separately in my workfile? So using var.laglen(p, vname=) command, I would like to store the vname vector indicating selected lags for each of the 51 VAR models estimated in my code.
Thanks
Help on lag length Selection in VAR
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Help on lag length Selection in VAR
If it is truly bilateral - i.e. Y1 is only in a VAR with Z1 and Y2 is only in a VAR with Z2, you don't need a double loop:
Code: Select all
for !i=1 to y.@count
%iname = y.@seriesname(!i)
%jname = z.@seriesname(!i)
var var_{%iname}_{%jname}.ls 1 8 {%iname} {%jname}
var_{%iname}_{%jname}.laglen(10, vname=lags_{%iname}_{%jname})
next
Re: Help on lag length Selection in VAR
Thanks, Gareth. I really appreciate your help.
Re: Help on lag length Selection in VAR
Hi Gareth
The code works perfectly for me and saves the lag selections by 5 criteria for each pair as vector in eviews. I now want to test Granger Causality between each pair of Y and Z using the optimal lags. I am not sure how to do that. I have written a code that does this for a lag length of 4 for each pair. Do you have any suggestions on how I can combine the optimal lag length in Step 1 and testing of Granger Causality in Step 2?
' Step 1: Selecting lag length for bilateral pairs in two groups Y and Z ( the code you gave and works perfectly):
for !i=1 to y.@count
%iname = y.@seriesname(!i)
%jname = z.@seriesname(!i)
var var_{%iname}_{%jname}.ls 1 8 {%iname} {%jname}
var_{%iname}_{%jname}.laglen(10, vname=lags_{%iname}_{%jname})
next
'Step 2: Testing for Granger Causality for each pair in Y and Z. Here I assume lag length of 4. It works fine. But I want to use optimal lag for each pair from step 1 in this step.
'create a group which will contain the xs
group y
group z
matrix(51,2) Walds
''counter of how many equations we have run
!rowcounter=1
'run pairwise regressions between each series
for !i=1 to y.@count
%iname = y.@seriesname(!i)
%jname = z.@seriesname(!i)
equation eq_{%iname}_{%jname}.ls {%iname} c {%iname}(-1 to -4) {%jname}(-1 to-4)
freeze(waldtable) eq_{%iname}_{%jname}.wald c(2)=c(3) =c(4)=c(5)=c(6)=c(7)=c(8)=c(9)=0 ' perform wald test and freeze it into a table called WaldTable
walds(!rowcounter,1) = @val(waldtable(6,2)) ' store wald statistic (which is in cell 6,2 of the table)
walds(!rowcounter,2) = @val(waldtable(6,4)) ' store wald p-value (which is in cell 6,4 of the table)
!rowcounter=!rowcounter+1 ' increment row counter
d waldtable ' delete the table
next
Any help will be much appreciated. Thanks!
The code works perfectly for me and saves the lag selections by 5 criteria for each pair as vector in eviews. I now want to test Granger Causality between each pair of Y and Z using the optimal lags. I am not sure how to do that. I have written a code that does this for a lag length of 4 for each pair. Do you have any suggestions on how I can combine the optimal lag length in Step 1 and testing of Granger Causality in Step 2?
' Step 1: Selecting lag length for bilateral pairs in two groups Y and Z ( the code you gave and works perfectly):
for !i=1 to y.@count
%iname = y.@seriesname(!i)
%jname = z.@seriesname(!i)
var var_{%iname}_{%jname}.ls 1 8 {%iname} {%jname}
var_{%iname}_{%jname}.laglen(10, vname=lags_{%iname}_{%jname})
next
'Step 2: Testing for Granger Causality for each pair in Y and Z. Here I assume lag length of 4. It works fine. But I want to use optimal lag for each pair from step 1 in this step.
'create a group which will contain the xs
group y
group z
matrix(51,2) Walds
''counter of how many equations we have run
!rowcounter=1
'run pairwise regressions between each series
for !i=1 to y.@count
%iname = y.@seriesname(!i)
%jname = z.@seriesname(!i)
equation eq_{%iname}_{%jname}.ls {%iname} c {%iname}(-1 to -4) {%jname}(-1 to-4)
freeze(waldtable) eq_{%iname}_{%jname}.wald c(2)=c(3) =c(4)=c(5)=c(6)=c(7)=c(8)=c(9)=0 ' perform wald test and freeze it into a table called WaldTable
walds(!rowcounter,1) = @val(waldtable(6,2)) ' store wald statistic (which is in cell 6,2 of the table)
walds(!rowcounter,2) = @val(waldtable(6,4)) ' store wald p-value (which is in cell 6,4 of the table)
!rowcounter=!rowcounter+1 ' increment row counter
d waldtable ' delete the table
next
Any help will be much appreciated. Thanks!
Re: Help on lag length Selection in VAR
I am sorry, there was a typo in the step 2 wald test. It should read:
freeze(waldtable) eq_{%iname}_{%jname}.wald c(6)=c(7)=c(8)=c(9)=0 ' perform wald test and freeze it into a table called WaldTable
freeze(waldtable) eq_{%iname}_{%jname}.wald c(6)=c(7)=c(8)=c(9)=0 ' perform wald test and freeze it into a table called WaldTable
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Help on lag length Selection in VAR
I'm confused - I don't see where you're doing the Granger Causality test.
Re: Help on lag length Selection in VAR
I apologize for the confusion. The following command:
freeze(waldtable) eq_{%iname}_{%jname}.wald c(6)=c(7)=c(8)=c(9)=0 ' perform wald test and freeze it into a table called WaldTable
is testing for Granger causality of Z for Y. If we do not reject this null, then all lags of Z do not enter the Y regression and hence Z does not Granger Cause Y.
I am aware of Eviews canned Granger causality function which can be applied to all pairs of a group. But I want to test for Granger causality between bilateral pairs of two groups Y and Z: Y1 and Z1, Y2 and Z2, and so on. I could not figure out how to tweak the Granger causality function on Eviews and hence decided to simply compute the wald test myself for all the lags of Z in Y equation. I hope this clarifies the issue.
freeze(waldtable) eq_{%iname}_{%jname}.wald c(6)=c(7)=c(8)=c(9)=0 ' perform wald test and freeze it into a table called WaldTable
is testing for Granger causality of Z for Y. If we do not reject this null, then all lags of Z do not enter the Y regression and hence Z does not Granger Cause Y.
I am aware of Eviews canned Granger causality function which can be applied to all pairs of a group. But I want to test for Granger causality between bilateral pairs of two groups Y and Z: Y1 and Z1, Y2 and Z2, and so on. I could not figure out how to tweak the Granger causality function on Eviews and hence decided to simply compute the wald test myself for all the lags of Z in Y equation. I hope this clarifies the issue.
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Help on lag length Selection in VAR
I'd just create a temporary group with the two series you're interested in, then perform the built in procedure on that temporary group.
Re: Help on lag length Selection in VAR
Thanks, Gareth. However, issue still remains of how to call the optimal lags selected in step 1. So for each pair, step 1 creates a vector with 5 rows and 1 column that correspond to 5 lag length selection criteria. Number 4 in this vector is SC which is what I plan to use. Now suppose I create a temp group containing only Y1 and Z1 (where Y1 is first column of group Y in my earlier example, Z1 is first column of Z) and feed them through inbuilt Granger causality function --I still need to input the lag length which I want to be the 4th element of the lag length vector created in step 1. There are 51 such vectors, and will give me 51 lag length values to be fed into Granger Causality test.
You know typing this out makes me wonder whether doing this test for each pair at a time is more efficient. I am not sure if I can code what I just described above! For example, how to create a temp group from existing groups Y and Z, so that it iterates forward properly. So first temp group has to be Y1, Z1. Second has to be Y2, Z2 and so on. Once this hurdle is crossed I need to input 4th element of the lag length vector for each pair for Granger Causality test. I don't think I know how to do that either.
If this can be done, thats okay. Thanks for the help though. I did learn a few things that will come in handy in future.
You know typing this out makes me wonder whether doing this test for each pair at a time is more efficient. I am not sure if I can code what I just described above! For example, how to create a temp group from existing groups Y and Z, so that it iterates forward properly. So first temp group has to be Y1, Z1. Second has to be Y2, Z2 and so on. Once this hurdle is crossed I need to input 4th element of the lag length vector for each pair for Granger Causality test. I don't think I know how to do that either.
If this can be done, thats okay. Thanks for the help though. I did learn a few things that will come in handy in future.
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Help on lag length Selection in VAR
Code: Select all
for !i=1 to y.@count
%iname = y.@seriesname(!i)
%jname = z.@seriesname(!i)
var var_{%iname}_{%jname}.ls 1 8 {%iname} {%jname}
do var_{%iname}_{%jname}.laglen(10, vname=lags_{%iname}_{%jname})
group temp {%iname} {%jname}
!lags = lags_{%iname}_{%jname}(4)
freeze(cause_{%iname}_{%jname}) temp.cause(!lags)
d temp
next
Re: Help on lag length Selection in VAR
Gareth, this is just spectacular! Thanks, a lot.
Who is online
Users browsing this forum: No registered users and 2 guests
