With –sort– I'm aware that unless the –stable– option is specified that ties among the sort varlist are broken randomly. That said, can anyone inform me why I get different sort orders when I run the following code multiple times.
Code:
cap preserve
cap drop _all

set seed 2345
set obs 6
gen subject=_n
gen u=runiform()
gen var=ceil(_n/3)
list
sort u
sort var
list
sort u
sort var
list
sort u
sort var
list

cap restore
First execution:
Code:
. list

     +--------------------------+
     | subject          u   var |
     |--------------------------|
  1. |       1   .2763898     1 |
  2. |       2   .1392859     1 |
  3. |       3   .1685803     1 |
  4. |       4   .2651878     2 |
  5. |       5   .5484495     2 |
     |--------------------------|
  6. |       6   .3501784     2 |
     +--------------------------+

. sort u

. sort var

. list

     +--------------------------+
     | subject          u   var |
     |--------------------------|
  1. |       1   .2763898     1 |
  2. |       2   .1392859     1 |
  3. |       3   .1685803     1 |
  4. |       6   .3501784     2 |
  5. |       4   .2651878     2 |
     |--------------------------|
  6. |       5   .5484495     2 |
     +--------------------------+

. sort u

. sort var

. list

     +--------------------------+
     | subject          u   var |
     |--------------------------|
  1. |       3   .1685803     1 |
  2. |       2   .1392859     1 |
  3. |       1   .2763898     1 |
  4. |       5   .5484495     2 |
  5. |       6   .3501784     2 |
     |--------------------------|
  6. |       4   .2651878     2 |
     +--------------------------+

. sort u

. sort var

. list

     +--------------------------+
     | subject          u   var |
     |--------------------------|
  1. |       2   .1392859     1 |
  2. |       1   .2763898     1 |
  3. |       3   .1685803     1 |
  4. |       5   .5484495     2 |
  5. |       6   .3501784     2 |
     |--------------------------|
  6. |       4   .2651878     2 |
     +--------------------------+
Second execution:
Code:
. list

     +--------------------------+
     | subject          u   var |
     |--------------------------|
  1. |       1   .2763898     1 |
  2. |       2   .1392859     1 |
  3. |       3   .1685803     1 |
  4. |       4   .2651878     2 |
  5. |       5   .5484495     2 |
     |--------------------------|
  6. |       6   .3501784     2 |
     +--------------------------+

. sort u

. sort var

. list

     +--------------------------+
     | subject          u   var |
     |--------------------------|
  1. |       2   .1392859     1 |
  2. |       1   .2763898     1 |
  3. |       3   .1685803     1 |
  4. |       6   .3501784     2 |
  5. |       5   .5484495     2 |
     |--------------------------|
  6. |       4   .2651878     2 |
     +--------------------------+

. sort u

. sort var

. list

     +--------------------------+
     | subject          u   var |
     |--------------------------|
  1. |       3   .1685803     1 |
  2. |       2   .1392859     1 |
  3. |       1   .2763898     1 |
  4. |       5   .5484495     2 |
  5. |       4   .2651878     2 |
     |--------------------------|
  6. |       6   .3501784     2 |
     +--------------------------+

. sort u

. sort var

. list

     +--------------------------+
     | subject          u   var |
     |--------------------------|
  1. |       2   .1392859     1 |
  2. |       1   .2763898     1 |
  3. |       3   .1685803     1 |
  4. |       5   .5484495     2 |
  5. |       6   .3501784     2 |
     |--------------------------|
  6. |       4   .2651878     2 |
     +--------------------------+