# Loops for Unit Root Test

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}]

px[[t]]=pt

• does that RandomReal work? Its not a documented usage (likely you mean RandomVariate )? Oct 18 '14 at 13:38
• UnitRootTest/@px seems to be all you need.. Oct 18 '14 at 13:39
• @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. Oct 19 '14 at 23:12

UnitRootTest /@ (Accumulate[#] - #[] & /@ 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.