[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: what does Stata do when I type "var1==var2==0"?

From   David Kantor <[email protected]>
To   [email protected]
Subject   Re: st: what does Stata do when I type "var1==var2==0"?
Date   Thu, 25 Sep 2008 22:26:41 -0400

At 09:18 PM 9/25/2008, Hau wrote:

I have 4 observations for two variables that look like this:
var1 var2
0    0
0    1
1    0
1    0

when I type:
-assert var1==var2==1-
Stata returns:
-3 contradictions in 4 observations-

I realize I need to type:
-assert var1==1 & var2==1- to get the right answer.

I have a vague idea as to why Stata prefers the second one. But what's
intrinsically wrong with the first one?
The expression
is perfectly legitimate, but you must understand that it is interpreted as
or maybe it is

Actually, I don't know which one of those is the actual interpretation; I could look somewhere and find out, but it doesn't really matter. The important matter is that it is intrinsically ambiguous, but it will be grouped one way or the other when it is evaluated. Also, be aware that a subexpression such as
is evaluated as 1 or 0 -- corresponding to true and false.

The other thing to remember is that if you ever truly want to use an expression such as...
a == b == c
(rather than it being a mistake), then you would be best to insert parentheses to indicate which way you want it grouped. Without parentheses, one of the possible interpretations will be taken, and it might not be the one you wanted.

Note that your expression var1==var2==1 is generally ambiguous, but the two possible interpretations, when applied to your particular data, yield the same results. It happens to work out that way, but might not, on other data.


* For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index