Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: sort within values


From   Maarten Buis <maartenlbuis@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: sort within values
Date   Wed, 26 Sep 2012 10:46:05 +0200

On Wed, Sep 26, 2012 at 10:19 AM, Michele Santacatterina  wrote:
> i was wondering how to sort a numeric variable within the values. Here an example, var1 contains 2 values (12,21) i would like to sort within var1 in order to create var2 = (12,12)

What is the sort order of two or more identical numbers? The sensible
solution to that question, and the one that is by default implemented
in Stata, is: random, as there is no way of distinguishing between
identical numbers.

Alternatively you may want to keep the order that existed before
sorting. This is strictly speaking not a sensible solution to the
question, as you assume that there is more information (the original
sort order) than was given by the question, but it can be useful
sometimes. In that case you can use the -stable- option in -sort-.
However, if you think that the original sort-order is that important,
the better solution is to create a variable that stores the original
sort order, by typing in Stata: -gen order_id = _n-, than you can sort
by typing: -sort var1 sort_id-. That way you are explicit about the
fact that you use information from the original sort order, and that
information does not get accidentally lost when you make a mistake
when sorting.

-- Maarten

---------------------------------
Maarten L. Buis
WZB
Reichpietschufer 50
10785 Berlin
Germany

http://www.maartenbuis.nl
---------------------------------
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index