|
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: what does Stata do when I type "var1==var2==0"?
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
var1==var2==1
is perfectly legitimate, but you must understand that it is interpreted as
(var1==var2)==1
or maybe it is
var1==(var2==1)
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
(var1==var2)
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.
HTH
--David
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/