📄 sort.hlp
字号:
{smcl}
{* 01dec2004}{...}
{cmd:help sort}{right:dialog: {bf:{dialog sort}}}
{hline}
{title:Title}
{p2colset 5 17 19 2}{...}
{p2col :{hi:[D] sort} {hline 2}}Sort data{p_end}
{p2colreset}{...}
{title:Syntax}
{p 8 13 2}
{opt so:rt}
{varlist}
[{it:{help in}}]
[{cmd:,} {opt stable}]
{title:Description}
{pstd}
{opt sort} arranges the observations of the current data into ascending order
based on the values of the variables in {varlist}. There is no limit to the
number of variables in the {it:varlist}. Missing numeric values (see
{help missing}) are interpreted as being larger than any other number, so they
are placed last with {cmd:. < .a < .b ... < .z}. When you sort on a string
variable, however, null strings are placed first. The dataset is marked as
being sorted by {it:varlist} unless {help in:{bf:in} {it:range}} is specified.
If {opt in} {it:range} is specified, only those observations are rearranged.
The unspecified observations remain in the same place.
{title:Option}
{phang}
{opt stable} specifies that observations with the same values of the variables
in {varlist} keep the same relative order in the sorted data that
they had previously. For instance, consider the following data:
{center:x b}
{center:3 1}
{center:1 2}
{center:1 1}
{center:1 3}
{center:2 4}
{pmore}
Typing {cmd:sort x} without the {opt stable} option produces one of the
following 6 orderings.
{center:x b {c |} x b {c |} x b {c |} x b {c |} x b {c |} x b}
{center:1 2 {c |} 1 2 {c |} 1 1 {c |} 1 1 {c |} 1 3 {c |} 1 3}
{center:1 1 {c |} 1 3 {c |} 1 3 {c |} 1 2 {c |} 1 1 {c |} 1 2}
{center:1 3 {c |} 1 1 {c |} 1 3 {c |} 1 2 {c |} 1 2 {c |} 1 1}
{center:2 4 {c |} 2 4 {c |} 2 4 {c |} 2 4 {c |} 2 4 {c |} 2 4}
{center:3 1 {c |} 3 1 {c |} 3 1 {c |} 3 1 {c |} 3 1 {c |} 3 1}
{pmore}
Without the {opt stable} option, the ordering of observations with equal
values of {it:varlist} is randomized. With {cmd:sort x, stable}, you will
always get the first ordering and never the other five.
{pmore}
If your intent is to have the observations sorted first on {opt x} and then
on {opt b} within tied values of {opt x} (the third ordering above), you should
type {opt sort x b} rather than {opt sort x, stable}.
{pmore}
{opt stable} is seldom used, and, when specified, causes {opt sort} to
execute more slowly.
{title:Examples}
{phang}{cmd:. sort person id}{p_end}
{phang}{cmd:. sort lstname frstname midinitl}{p_end}
{phang}{cmd:. regress y x1 x2 x3}{p_end}
{phang}{cmd:. predict r, resid}{p_end}
{phang}{cmd:. sort r}{p_end}
{phang}{cmd:. list in 1/10}{p_end}
{phang}{cmd:. list in -10/l}{p_end}
{title:Also see}
{psee}
Manual: {bf:[D] sort}
{psee}
Online: {helpb describe},
{helpb gsort}
{p_end}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -