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]
st: Stata treatment of sort order
From
Andrew Maurer <[email protected]>
To
"[email protected]" <[email protected]>
Subject
st: Stata treatment of sort order
Date
Thu, 6 Mar 2014 19:36:12 +0000
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/