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
"Joseph Coveney" <[email protected]>
To
<[email protected]>
Subject
st: Re: RE: if qualifier
Date
Thu, 11 Jul 2013 05:37:46 +0900
Sarah Edgington wrote:
It appears to be just ignoring the <20.
That is, it's that same result as -count if 10<mpg-
I'm also surprised it doesn't give an error (I'd expect "invalid <20").
--------------------------------------------------------------------------------
Stata is not ignoring the <20. Stata is evaluating the entire expression. It's
doing so according to conventional rules of operator precedence, and
left-to-right rules of expression evaluation. There is no error in the
expression. The expression is cogent, and it evaluates to "true".
If you're accustomed to SAS, you'd think that the statement and its expression
ought to mean the equivalent to SQL's
SELECT COUNT (*) FROM auto WHERE mpg BETWEEN 10 AND 20;
But this isn't what "expression" means to Stata. Stata uses formal Boolean
logic, it substitutes intermediate result into the remaining part of the
expression for further evaluation, and it follows conventional rules of operator
precedence in its expression evaluation.
If it helps, you can rewrite the expression equivalently as:
count if ((1 < mpg) < 20)
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/