An R function like "order" from Stata