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: by prefix


From   William Buchanan <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: by prefix
Date   Mon, 4 Jun 2012 08:22:34 -0700

So you're basically saying that the difference between typing:

by var1: cmd

And 

bys var1: cmd

Is "overkill"?  I would hardly define the additional letter as overkill, and would further argue that it is an intelligent design since it help to ensure that the end user will get what they want, rather than assuming things are not sorted by default.

-Billy

Sent from my iPhone

On Jun 4, 2012, at 8:46, Richard Williams <[email protected]> wrote:

> At 09:35 AM 6/4/2012, tashi lama wrote:
> 
>> Hello,
>> 
>>  Here is sth I found Stata very unintelligent. A by prefix has to be preceded by sort command although the dataset is already sorted by design. Take a look at this
>> 
>> 
>> 
>> var1    var2
>> 
>> A         3
>> 
>> A         4
>> 
>> A         1
>> 
>> B         2
>> 
>> B         5
>> 
>> 
>> 
>> 
>> 
>> The dataset is already sorted by var1 as you all can see. Now when I apply by prefix
>> 
>> by var1: summ var2    says not sorted.
>> 
>> Stata obliges you to write
>> 
>> bysort var1: summ var2    which I think is overkill. Any thoughts?
> 
> Yes, but Stata doesn't know it is already sorted. The data manual entry for -sort- says this:
> 
> "Stata does not track changes in the sort order and will sometimes decide that a dataset is not sorted when, in fact, it is. For instance, if we were to change the first observation of our auto dataset from 12 miles per gallon to 10, Stata would decide that the dataset is "Sorted by:" nothing, just as it did above when we changed mpg from 12 to 13. Our change in example 2 did change the order of the data, so Stata was correct. Changing mpg from 12 to 10, however, does not really affect the sort order.
> 
> "As far as Stata is concerned, any change to the variables on which the data are sorted means that the data are no longer sorted, even if the change actually leaves the order unchanged. Stata may be dumb, but it is also fast. It sorts already-sorted datasets instantly, so Stata's ignorance costs us little."
> 
> 
> -------------------------------------------
> Richard Williams, Notre Dame Dept of Sociology
> OFFICE: (574)631-6668, (574)631-6463
> HOME:   (574)289-5227
> EMAIL:  [email protected]
> WWW:    http://www.nd.edu/~rwilliam
> 
> *
> *   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/

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index