Solution

First of all, the reason you get no output is that no observation fulfills the if condition. But how can that be, given that many cars get 25 miles per gallon or less?

The trouble is that, once you apply the proper order of operations, this condition has nothing to do with "25 miles per gallon or less." The original version,

l make mpg if !(mpg>25)

first checks to see if mpg is greater than 25 or not, then reverses the result. But precedence rules say the not operator (!) is evaluated before the greater than operator (>). Thus this version,

l make mpg if !mpg>25

is actually equivalent to:

l make mpg if (!mpg)>25

The quantity !mpg is evaluated first, using the rule "zero is false and anything else is true." Since mpg is never zero, mpg by itself is always true. That means !mpg is always false.

Stata then evaluates the greater than condition. False is zero, and zero is not greater than 25. Thus the final result is always false. Actually, it doesn't matter whether !mpg is true or false, since true (one) isn't greater than 25 either.

This particular example may be less confusing if you think like Stata: always use 1 and 0 instead of true and false, and think of the ! and > operators as functions. !x is defined as 1 if x=0 and 1 otherwise, and x>y is defined as 1 if x>y and 0 otherwise. But regardless of how you think about it, the moral of this story is to always use parentheses to control the order things are evaluated in.

Last Revised: 11/19/2009