以下是引用shanxinning在2009-4-11 21:36:00的发言:
原来如此,我怎么就没想到呢,谢谢谢谢!!
你如果用stata的帮助的话,在sort命令的解释里面的最下面的链接里面就有介绍gsort
所以要学会知道一个命令以后,如何查找相关的命令
----------------------------------------------------------------------------------------------------------
help for sort manual: [R] sort
dialog: sort
----------------------------------------------------------------------------------------------------------
Sort data
sort varlist [in range] [, stable]
Description
sort arranges the observations of the current data in ascending order of the values of the variables
in varlist. There is no limit to the number of variables in varlist. Missing values (see help
missing) are interpreted as being larger than any other number and thus are placed last, with .
being placed first followed by .a, .b, ... .z. (Exception: When sorting on a string variable, null
strings are placed first.) The dataset is marked as being sorted by varlist unless in range is
specified.
Note: ties in the sort index (i.e., identical sorting values) are broken in an arbitrary (i.e.,
random) order, unless the stable option is specified.
Option
stable specifies that observations with the same values of the variables in varlist are to keep
their same relative order in the sorted data as they had previously. For instance, consider the
following data:
x b
3 1
1 2
1 1
1 3
2 4
Typing sort x without the stable option produces one of the following 6 orderings.
x b | x b | x b | x b | x b | x b
1 2 | 1 2 | 1 1 | 1 1 | 1 3 | 1 3
1 1 | 1 3 | 1 2 | 1 3 | 1 1 | 1 2
1 3 | 1 1 | 1 3 | 1 2 | 1 2 | 1 1
2 4 | 2 4 | 2 4 | 2 4 | 2 4 | 2 4
3 1 | 3 1 | 3 1 | 3 1 | 3 1 | 3 1
Without the stable option, the ordering of observations with equal values of varlist is
randomized. With sort x, stable, you will always get the first result and never the other five.
If your intent was to have the observations sorted first on x and then on b within tied values
of x (the third result above), you should type sort x b and not sort x, stable.
stable is rarely of use and, when specified, causes sort to execute more slowly.
Examples
. sort personid
. sort lstname frstname midinitl
. regress y x1 x2 x3
. predict r, resid
. sort r
. list in 1/10
. list in -10/l
Also see
Manual: [R] sort
Online: help for describe, gsort