Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Missing values in logical expressions in Mata


From   "Jann Ben" <[email protected]>
To   <[email protected]>
Subject   st: Missing values in logical expressions in Mata
Date   Tue, 20 Sep 2005 13:16:57 +0200

Hi, I am very much confused by how Mata treats missing 
values in logical expression. Long time ago, I learned 
that "." used in logical expressions evaluates to TRUE 
in Stata. However, look at this:

	. mata
	: if (.) 1
	> else 2
	  1
	
	: if (!.) 1
	> else 2
	  1
	
	: end

This behavior does not make sense to me. Furthermore,
it is in contrast to -help m2_op_logical-: "!a, when 
a is a scalar, evaluates to 1 if a is not equal to 
zero and 1 otherwise." Clearly, "." is not zero.

Note, that in Stata code, the expression evaluates as 
expected:

	. if . di 1
	1
	
	. else di 2
	
	. if !. di 1
	
	. else di 2
	2

What could be the reason for this inconsitency?

ben

*
*   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/



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