Key the dataset by a variable list
keyby varlist [ , noorder missing fast ]
Description
keyby sorts the dataset currently in memory by the variables in a varlist, checking that the variables in the varlist uniquely identify the observations. This makes the variables in the varlist a primary key for the dataset in memory. If the user does not specify otherwise, then keyby also reorders the variables in the varlist to the start of the variable order in the dataset, and checks that all values of these variables are nonmissing. keyby can be useful if the user combines multiple datasets using merge, which may cause a dataset in memory to become unsorted.
Options
noorder specifies that the variables in the varlist are not reordered to the beginning of the variable order of the dataset in memory. If noorder is nor specified, then the variables in varlist are reordered to the beginning of the variable order (see order).
missing specifies that missing values in the variables in the varlist are allowed. If missing is not specified, then missing values in the variables in the varlist cause keyby to fail.
fast is an option for programmers. It specifies that keyby will take no action to restore the existing dataset in memory in the event of failure. If fast is not specified, then keyby will take this action, which uses an amount of time depending on the size of the dataset in memory.
Examples
. keyby foreign make
. keyby foreign make, noorder
. keyby rep78 make, missing
Author
Roger Newson, National Heart and Lung Institute, Imperial College London, UK. Email: r.newson@imperial.ac.uk
Also see
Manual: [D] sort, [D] gsort, [D] merge, [D] order, [U] 12.2.1 Missing values On-line: help for sort, gsort, merge, order, missing