Logical operators
This really should go under "more gems from the User's Guide". If you come to Stata like I did, with minimal previous experience with any kind of computer programming, you might not know this:
When you combine !, & and | (the logical operators NOT, AND and OR) in an expression you will want to make sure that they are properly nested in parentheses that follow your thinking about how you want to use them. This is because there is an order of precedence to these operators similar to the order of precedence in arithmetics. Left to its own devices, Stata will follow that proper order. In other words, in the same way that in the code a=b+c*d the multiplication will be executed before the addition, any code where !, & and | show up without any parentheses, Stata will execute in the following order:
1. NOT (!)
2. AND (&)
3. OR (|)
At the top of page 137 in the Stata 10 User's Guide there's a one-sentence section on the order of evaluation of all operators. It's a handy reference.