Statalist


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

Re: st: if syntax parser


From   "Joseph Coveney" <jcoveney@bigplanet.com>
To   "Statalist" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: if syntax parser
Date   Sun, 30 Mar 2008 00:54:40 +0900

Hiroyuki Kawakatsu wrote:

am i the only one who finds the following "feature" of the stata if
syntax parser worrying? (i observed a student doing this and was
expecting stata to correct him...):

[code redacted and run below]

--------------------------------------------------------------------------------

Stata is behaving predictably, logically and correctly.

2 < t is either true (1) or false (0).  Either way, the result of the
logical test is always less than 5.

2 < t is either true (1) or false (0).  Either way, the result of the
logical test is never greater than 5.

2 == 5 is either true (1) or false (0).  Either way, the result of the
logical test is never equal to 5.

Joseph Coveney

.
. set obs 10
obs was 0, now 10

. gen x = 1

. gen t = _n

.
. sum x if 2<t<5    /*what do you expect?*/

   Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
          x |        10           1           0          1          1

.
. /*further experiments*/
. sum x if 2<t>5    /*?*/

   Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
          x |         0

. sum x if 2==t==5  /*correct?*/

   Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
          x |         0

. sum x if 2|t|5    /*ok*/

   Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
          x |        10           1           0          1          1

.
. /*end sample code*/


*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index