Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: Stata treatment of sort order


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Stata treatment of sort order
Date   Thu, 6 Mar 2014 19:51:15 +0000

On your first question: I don't know a way to change what is shown by

di "`: sortedby'"

except by -sort-ing on permanent variables. Notwithstanding your
intended application, that strikes me as a feature. In fact, the
ability to mess with this would create the potential for more
mysterious behaviour than could possibly be justified by one possible
use, however far it is intended as legitimate. Indeed I would never
trust what one previously knows about sort order over objective fact.

Nick
[email protected]


On 6 March 2014 19:36, Andrew Maurer <[email protected]> wrote:
> Hi Statalist,
>
> I'm wondering if anyone can help explain some details about Stata and sorting
>
> First, where does Stata hold information about current sort order? Ie, the extended macro function --`: sortedby'-- returns the current sort order. However, looking at --char dir-- and --macro dir-- I don't see the information there. In particular, I want to overwrite the value, so that --`: sortedby'-- will return the value that I insert. One use might be if I -infile-, and I already know the sort order of the data, but don't want to have to run sort just to populate `: sortedby'. (In --help dta--, I see where it's stored in a physical dta file [<sortlist>sortlist</sortlist>], but it doesn't explain where it is put in memory.
>
> Second, the help file for sort seems somewhat misleading. --help sort-- explains, "Without the stable option, the ordering of observations with equal values of varlist is randomized." What does "randomized" here mean? I interpret it to mean that each residual observation has an equal probability of being in any of the slots specified by the sort list (eg that --sort var1-- is equivalent to --gen rand = runiform()-- --sort var1 rand-- --drop rand-- However, residual sort order doesn't always appear random. For example, if I --sysuse auto--, --sort foreign--, then copy the data to clipboard, --clear--, then use data editor to paste the data back, and finally --sort foreign--, the ordering is always the same as the original ordering (ie: the ordering of observations with equal values of varlist was /not/ randomized.
>
> Is anyone able to explain these observations?
>
> Thank you,
>
> Andrew Maurer
>
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/

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


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index