On Tue, 7 Dec 2010, Robert Kirkby wrote:
I am running a simulation in which I generate 100 copies of 3 time
series. I want to write a script that will run cointegration tests on
them and store all the p-values. I can easily do this for the
Engel-Granger test for cointegration using $pvalue, for example the
contents of the for loop look something like
coint 4 v1 v2 v3 --ct
genr pval=$pvalue
I would like to do much the same thing, but with the Johansen test,
storing the p-values from the Lmax (or trace) test (so there would be
3 p-values for each simulation). Running the test is easy with
coint2 4 v1 v2 v3
but is there any way that I can get the p-values for the Lmax test out
of this automatically?
Not easily, at present. The trouble is that the $pvalue and $test
accessors are set up to deal with scalars (only) while the
Johansen test generates multiple values. I think we should
probably aim to generalize this retrieval mechanism. In the
meantime, however, the best we can offer is the following sort of
thing, using gretl's string-handling: we write the test results to
file (using the --quiet option), read the content of the file into
a string, then parse out the pvalues into a matrix.
<script>
open denmark.gdt
list L = LRM LRY IBO IDE
outfile pvals.txt --write
coint2 2 L --seasonals --rc --quiet
outfile --close
string pvstr = readfile("pvals.txt")
scalar rankmax = nelem(L)
matrix pvals = zeros(rankmax, 2)
scalar x
loop i=1..rankmax --quiet
loop j=1..2 --quiet
pvstr = strstr(pvstr, "[") + 1
sscanf(pvstr, "%g", x)
pvals[i,j] = x
endloop
endloop
print pvals
</script>
Allin Cottrell