>
>
Nick, thanks a lot. aorder TAL* worked fine with the hundreds of variables I have. Luckily, they all have a 4 digits suffixes.
Dev
>>> [email protected] 07/26/04 05:06pm >>>
. aorder TAL*
should do this. That is, if all variables
have the same prefix, in this case
"TAL", then their sorted order is determined
by what comes next. This should work
if all suffixes are 4 digits. In that
case, alphanumeric (dictionary) order
coincides with numeric order.
How might this go wrong? You might
have a variable number of digits
TAL42, TAL123, TAL4567, TAL13, ...
but you want the order to be numeric,
not alphanumeric.
One way of getting that is something
like (untested code)
unab TAL : TAL*
local TAL : subinstr local TAL "TAL" "", all
numlist "`TAL'", sort
local tal "`r(numlist)'"
local TAL
foreach v of local tal {
local TAL "`TAL' TAL`v'"
}
order `TAL'
That is,
get the variable names into a local macro
zap the common prefix
sort the suffixes, numerically
put the prefix back in each case
Nick
[email protected]
Dev Vencappa
> Stata users, is there any command that orders a set of
> variable by numbered suffix of a variable? e.g I have the
> following set of variable names:
>
> TAL4123 TAL4568 TAL3457 TAL2397 TAL4357 etc.
>
> The numbered suffixes are not in a continuous order, but I
> would like to order them in ascending order of the suffix.
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
This message has been scanned but we cannot guarantee that it and any
attachments are free from viruses or other damaging content: you are
advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/