help mata mm_unorder2()-------------------------------------------------------------------------------

Title

mm_unorder2() -- Stable unorder

Syntax

real colvectormm_unorder2(real scalar n)

transmorphic matrixmm_jumble2(transmorphic matrix X)

voidmm__jumble2(transmorphic matrix X)

where

Xmay not be a pointer matrix.

DescriptionThe results from official Stata's

unorder()are not reproducible ifnis large. That is, differing results may be obtained fromunorder(), although the random-number seed has been set beforehand (see help for[M-5] uniform()).mm_unorder2()is an improved version of officialunorder()that produces stable results.

mm_jumble2()andmm__jumble2()are stable versions of officialjumble()and_jumble().For descriptions of

unorder(),jumble(), and_jumble()see help for[M-5] sort().

RemarksThe following example illustrates the problem:

: for (i=1;i<=10;i++) { > uniformseed(3) > p1 = unorder(100000) > uniformseed(3) > p2 = unorder(100000) > if (p1!=p2) { > printf("round %g: unequal results\n", i) > break > } > } round 2: unequal results

Explanation:

uniform()may return duplicate pseudo random numbers due to computer precision constraints. Example:: uniformseed(3) : rows(uniqrows(uniform(100000,1))) 99999

Since the results from

unorder()rely on the sort order of uniform pseudo random numbers and since the sort order of duplicate values is randomized independently from the usual random-number seed, results fromunorder()may differ.

mm_unorder2()solves the problem by using two pseudo random-number sequences instead of one.

Conformability

mm_unorder2(n):n: 1x1result:n x1

mm_jumble2(X):X:r1 x c1result:r1 x c1

mm__jumble2(X):X:r1 x c1result:void;Xrow order modified

DiagnosticsSee help for

[M-5] sort().

Source codemm_unorder2.mata, mm_jumble2.mata, mm__jumble2.mata.

AuthorBen Jann, ETH Zurich, jann@soz.gess.ethz.ch

Also seeManual:

[M-5] sort()Online: help for

[M-5] sort();moremata