On Fri, 17 Oct 2014, Matteo Chiorboli wrote:
Dear Gretl users,
I need your help for running the Johansen test automatically on (n)
historic series, matched in pairs.
Substantially, I have 30 historic series, and I must test the cointegration
between all the possible pairs. Then, existing 435 possible pairs, I need
an automatic procedure to make this great number of Johansen tests.
Overall, I need a procedure that can run all possible cointegration tests
on a number of pairs of historic series given by the binomial coefficient
(combination), that in the specific case is n=30, k=2, then
[30!/(2!*(30-2)!]=435 pairs, and 435 Johansen tests.
This should be close to what you need, if I'm not mistaken. The example
uses the AWM database (supplied with gretl) and 6 series, so you have 15
tests, but of course it should just be a matter of redefining the list
called X in the example. The procedure selects the best lag order via the
Hannan-Quinn criterion and uses the default choice for the
determinstic part ("unrestricted constant"). Of course, this can be
changed quite easily by suitably manipulating the function you find at the
top of the script. The return values are the small-sample ajdusted pvalues
for the trace test, for the hypotheses r = 0 and r = 1.
<hansl>
set echo off
set messages off
function matrix do_automated_joh_test(series x, series y)
var 8 x y --lagselect --silent
# use minimum hqc
scalar bestlag = iminc($test[,3])
coint2 bestlag y x --silent
ret = $pvalue
return ret[,1]'
end function
open AWM.gdt --quiet
consump = ln(PCR)
income = ln(YER)
invest = ln(ITR)
export = ln(XTR)
import = ln(MTR)
list X = consump income invest export import
scalar n = nelem(X)
scalar k = 1
matrix xvec = X
loop foreach i X --quiet
list Z = xvec[k+1:]
string s1 = varname(X[i])
loop foreach j Z --quiet
string s2 = varname(Z[j])
pvals = do_automated_joh_test($i, $j)
printf "%10s vs %10s: %8.5f", s1, s2, pvals
endloop
if k < nelem(X)-1
k++
else
break
endif
endloop
</hansl>
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------