[Gretl-users] VAR/Granger Causality

Logan Kelly logan.kelly at uwrf.edu
Mon Jul 15 23:26:52 EDT 2013

Thanks. For my purpose, your function is actually superior to running the var function in that I can skip estimating the irrelevant equations.


-------- Original message --------
From: "Riccardo (Jack) Lucchetti" <r.lucchetti at univpm.it>
Date: 07/15/2013 5:49 PM (GMT-06:00)
To: Gretl list <gretl-users at lists.wfu.edu>
Subject: Re: [Gretl-users] VAR/Granger Causality

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.

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)
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

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wfu.edu/pipermail/gretl-users/attachments/20130716/8f4e826c/attachment-0001.html 

More information about the Gretl-users mailing list