help vorter

Title

vorter -- Reorder variables in dataset based on sorted
values

Syntax

Order variables by values in observation

vorter [+|-] varlist
[in #]
[, not order-options]

Order variables by statistic

vorter [+|-]
(statspec) varlist
[if] [in]
[, not order-options]

Order variables randomly

vorter [+|-] (random) varlist
[, not order-options]

where statspec is stat [, missing],
and stat is one of mean, count, max,
min, sum, sd or variance. If
suboption missing is specified with mean,
max, min or sum, missing values are
treated as such. Default is to ignore missing values. Option
missing may not be specified with any other stat.

Description

vorter reorders variables in the dataset based on sorted
values. Values are sorted in ascending order if + or nothing
is typed in front of varlist or (statspec),
and in descending order if - is typed.

The first syntax orders variables according to the sorted values
in the #th observation. If no observation is specified, the
first observation is used.

The second syntax orders variables according to the specified
stat. Think of this as adding one observation to the
dataset, holding the specified stat for the respective
variables in varlist. vorter sorts on the values of
this additional observation. String variables are not allowed.

The third syntax orders variables randomly. Technically, each
variable is assigned a random number between 0 and (nearly) 1
(see runiform()). vorter sorts on this random
number.

Options

not does not change the order of variables in the dataset,
but still returns the reordered list of variable names in
r(varlist).

order-options are options used with
order. Options alphabetic and sequential
are ignored.

Examples

Set up

. clear

. input str5 othervar v1 v2 v3 v4 v5

"obs1" 1 3 2 5 4

"obs2" 2 3 6 . 0

end

Reorder variables v1-v5 in descending order of the
values in the first observation

. vorter - v1-v5 in 1

Reorder variables staring with v according to their mean,
placing them after othervar

. vorter (mean) v* , after(othervar)

Reestablish the original order

. order `r(corder)'

Saved results

vorter saves the following in r():

Macros

r(varlist) varlist reordered

r(oorder) varlist in original order

r(corder) complete list of variable names in
original order

Matrices

r(stat) specified statistic for varlist

Acknowledgments

Tamás Keller suggested ordering variables randomly.

A question from an anonymous poster and answers by Joseph Coveney
and Jorge Eduardo Perez Perez to
Statalist
stimulated sorting on statistics.

A first draft of the program appeared as an answer to a question on
Statalist
posted by Pedro Nakashima.

Author

Daniel Klein

klein.daniel.81@gmail.com

Also see

Online: order, sort, gsort