[Gretl-users] VAR/Granger Causality
Riccardo (Jack) Lucchetti
r.lucchetti at univpm.it
Mon Jul 15 18:44:49 EDT 2013
On Mon, 15 Jul 2013, Logan Kelly wrote:
> Thanks for your quick response. I can see the f-stats in the output that
> are the GC test, but I would like to collect the test statistic in a
> matrix for further formatting. In a single equation model I would use
>
> matrix matFSTAT = $Fstat
>
> I am running several VAR's in a loop and need to store only these
> f-stats. My question is only about storing this stat after running var.
> Any suggestions?
I suppose a function could do the job quite nicely. The following is an
example of the many ways in which this could be done.
<hansl>
set echo off
set messages off
function scalar GCtest(series y, series x, list detvars,
scalar order, scalar *pv[null])
ols y detvars y(-1 to -order) x(-1 to -order) --quiet
omit x(-1 to -order) --silent
pv = $pvalue
return $test
end function
# -- open data ----------------------------------
open AWM.gdt --quiet
# -- check the function works as intended -------
var 3 LTN STN --quiet
# compare
GC1 = GCtest(LTN, STN, const, 3)
PV = NA
GC2 = GCtest(STN, LTN, const, 3, &PV)
print GC2 PV
# -- apply the function in a loop ---------------
smpl +12 ;
matrix moo = zeros(12,2)
loop for i=1..12 --quiet
GC = GCtest(STN, LTN, const, i, &PV)
printf "GC test (%2d lags) = %g, (p-value = %g)\n", i, GC, PV
moo[i,] = {GC, PV}
end loop
print moo
</hansl>
Of course you could prefer incorporating the loop inside the function and
have it spit out the matrix you want, it would just be a matter of style.
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti at univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------
More information about the Gretl-users
mailing list