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]

st: RE: Re: if qualifier


From   "Sarah Edgington" <[email protected]>
To   <[email protected]>
Subject   st: RE: Re: if qualifier
Date   Wed, 10 Jul 2013 13:31:37 -0700

Thanks Joseph. That's a much better explanation.  
Since 10<mpg is true for all observations in the data I completely missed
that nuance and just assumed it was stopping after it got to an expression
it could evaluate.
-count if 15<mpg<20- makes it clearer that it's always counting all the
observations because for each one the final if condition ends up being
either 0<20 or 1<20.
I wonder how often that particular problem bites SAS programmers new to
Stata?

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Joseph Coveney
Sent: Wednesday, July 10, 2013 12:56 PM
To: [email protected]
Subject: st: Re: if qualifier

Elan Cohen wrote:

I'm not sure what to make of the following:

sysuse auto
count if 10<mpg<20

A SAS-using colleague of mine typed this into Stata.  Much to her
astonishment, it returned a valid yet incorrect answer.  Much to my
astonishment, it did not return an error.

What is Stata doing here?  Is this behavior documented anywhere?

----------------------------------------------------------------------------
----

There is no error for Stata to report, and yes the precedence rules for
expression evaluation are documented.  

Here, the operators are the same and therefore of the same precedence, and
so the order of expression evaluation is left-to-right:  first "10<mpg",
which is true, that is, "1".  And then (continuing), it's "1<20", which is
also true.

Thus, the expression evaluates as "count if true".  

Joseph Coveney

*
*   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