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
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 | +--------------------------+
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 | +--------------------------+
0 Response to Random tiebreaking with –sort–
Post a Comment