gsort
Sorts with a direction you choose for each column.
What we have
- a direction per variable, with
+and-
Coming later
Nothing known to be missing.
How you write it
gsort [+|-]var [[+|-]var ...]
Square brackets mean optional. A vertical bar means choose one.
What it does
gsort -mpce puts the biggest spender first; gsort -state +mpce sorts states downwards and, within each, spending upwards. The - and + in front of each name are the whole point of the command.
The quickest way to answer "who are the top ten?" — gsort -salary then list in 1/10.
Try it
Every example below was run after sysuse vira.sample02, clear.
. gsort -mpce
The same thing in pandas and in R
pandas
df = df.sort_values(['mpce'], ascending=[False], kind="stable").reset_index(drop=True)
R
library(dplyr) df <- df %>% arrange(desc(mpce)) # This R was run in a real R (4.6.1) and gave the same numbers.