I want to compute some unit root tests on a data generating process. I already split the sample in 100 single samples, but how can I do a unit root test on all of them and store the results in another table? I tried several ways but can't find a solution...

Here is my code:

le = 100;

px = Table[0, {100}];

Do[e = RandomReal[NormalDistribution[0, 1], le];

 p = Table[0, {le}];

 Do[p[[i]] = p[[i - 1]] + e[[i]];, {i, 2, Length[p]}];

 px[[ii]] = p;, {ii, 1, 100}]

s = Split[px]

(it works up to here, so I have this hundred subsamples, but I have no idea how to perform the hundred corresponding unit-root tests; doing it by hand can't be the solution or ^^..)

Here my attempt:

pt = Table[0, {100}];

Do[UnitRootTest[px[[t]], {t, 1, 100}]

  • $\begingroup$ does that RandomReal work? Its not a documented usage (likely you mean RandomVariate )? $\endgroup$
    – george2079
    Oct 18 '14 at 13:38
  • $\begingroup$ UnitRootTest/@px seems to be all you need.. $\endgroup$
    – george2079
    Oct 18 '14 at 13:39
  • $\begingroup$ @george2079 RandomVariate superseded RandomReal and RandomInteger for distributions in M8. For distributions that existed prior to that time it should still work but RandomVariate is certainly encouraged. $\endgroup$
    – Andy Ross
    Oct 19 '14 at 23:12

The following code should do what you need:

UnitRootTest /@ (Accumulate[#] - #[[1]] & /@ RandomVariate[NormalDistribution[0, 1], {le, le}])

It does exactly the same thing as your original block of code, but is much shorter, and eliminates the need for multiple Do loops.

  • $\begingroup$ Thank you so much, it worked out well! $\endgroup$
    – and
    Oct 20 '14 at 6:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.