[Gretl-users] ADF test inside a loop

Allin Cottrell cottrell at wfu.edu
Mon Jan 31 12:39:14 EST 2011

On Mon, 31 Jan 2011, Henrique Andrade wrote:

> I'm trying to perform several ADF tests and save the results (statistic +
> p-value) inside a matrix. Please take a look at my script:
> <script>
> open australia.gdt
> list Variables = lpus iau2 lpau
> scalar T = nelem(Variables)
> scalar lag = int(12*($nobs/100)^(1/4))
> matrix ADF = zeros(nelem(Variables),2)
> colnames(ADF, "estatistica p-valor")
> rownames(ADF, "lpus iau2 lpau")
> loop foreach i Variables
>     loop j=1..T
>         adf lag $i --c --test-down
>         matrix ADF[$j,] = $test ~ $pvalue
>     endloop
> endloop

Why are you using two loops? Conceptually, there's only one:

loop foreach i Variables -q
  adf lag $i --c --test-down
  ADF[i,] = $test ~ $pvalue

You should use "$i" (and the like) _only_ when you need string
substitution (as in the adf command): otherwise use plain "i"
(as in matrix indexation) to get the numerical value.

Allin Cottrell

More information about the Gretl-users mailing list