At 03:26 PM 2/12/2004 -0500, Danielle Ferry wrote:
Can anyone please explain when the if command requires quotes around
the expression and when it does not?
For example, I've found the following seemingly quirky behavior:
1) if "`1'"=="aRate" | "`1'"=="bRate" | "`1'"=="pRate" --> requires
quotes
2) if `1'==aRate --> does not require quotes
3) if "`1'"=="apRatio" --> requires quotes
As far as I know, if you are comparing to a string constant, you need
quotes.
Example 2 probably ought to have quotes if it is meant to test a
string value. It would, however, pass as a legitimate expression
if...
aRate happens to be a variable name and...
it is numeric and so is `1' (that is the contents of the local 1),
or
it is string, and `1' contains enclosing quotes (I haven't tried
this), or
it is either numeric or string, and `i' is also a variable name of
a compatible type.
But in these cases, you are implicitly testing observation 1, which
you might not have intended.
Example 2 would also pass if aRate is a scalar and `1' is numeric (and
if `1' is a variable name, then you are testing observation 1).
In any case, while Example 2 might sometimes pass, it is probably not
doing what you intended.
I hope this helps.
-- David
David Kantor
Institute for Policy Studies
Johns Hopkins University
[email protected]
410-516-5404
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/