help sortrows -------------------------------------------------------------------------------Title
sortrows -- Sort data within rows
Syntax
sortrows varlist, {replace | generate(newvarlist)} missing descending
Description
sortrows sorts observations row-wise and either generates new variables to hold the sorted values or replaces the existing variables. The variables are sorted in ascending order in the order of the the variable list. Both numeric and string variables can be sorted, though all variables in the varlist must be either numeric or string. If it is given a numeric variable list of several types or a string variable list of different lengths, it will recast all the variables in the list to the largest type using decompress.
This requires Stata 9 since it uses Mata to perform the sorting.
Option
replace specifies that the sorted values should replace those of the existing variables.
generate(newvarlist) specifies the new variables to hold the sorted values.
missing move all missing values or "" to the last variables.
descending sort in descending order.
Example
. list a b c d
+---------------+ | a b c d | |---------------| 1. | 9 3 0 2 | 2. | 2 3 8 0 | 3. | 2 9 2 1 | 4. | 1 5 4 2 | 5. | 7 7 1 6 | +---------------+
. sortrows a b c d, replace
. list a b c d
+---------------+ | a b c d | |---------------| 1. | 0 2 3 9 | 2. | 0 2 3 8 | 3. | 1 2 2 9 | 4. | 1 2 4 5 | 5. | 1 6 7 7 | +---------------+
Notes
This is a similar command to Nicholas Cox's sortrows.
Author
Jeffrey Arnold jeffrey.arnold@gmail.com
Also see
Online: sort, gsort, egen, rowsort