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

st: Re: Trouble with " if"


From   "Jan Pettersson" <[email protected]>
To   <[email protected]>
Subject   st: Re: Trouble with " if"
Date   Fri, 12 Mar 2004 14:53:34 +0100

Shouldn't

             if `i'==`j' & `j' ==`k' {

work?
/Jan

----- Original Message ----- 
From: "Christophe Bontemps" <[email protected]>
To: <[email protected]>
Sent: Friday, March 12, 2004 2:45 PM
Subject: st: Trouble with " if"


> Hi Everybody,
> I find strange the way stata handle a double equality condition in "if"
> statements
>
> Running  the following trible loop on i, j and k with a condition like"
if
> `i'==`j'==`k'   " gives a wrong answer, no warnings, no errors.
> Of course i know the solution for this problem but why does Stata accept
> these misleading  statements  in "if" ?
> running  on Stata 8 SE the following :
> forvalues i = 1/3 {
>     forvalues j = 1/3 {
>        forvalues k = 1/3 {
>             display in yellow " i=`i'  j=`j'  k=`k' "
>
>              if `i'==`j'==`k' {
>                  di in green " case 1"
>              }
>              else {
>               di in red "case 2"
>              }
>         }
>     }
> }
> Gives
>  i=1  j=1  k=1
>  case 1
>  i=1  j=1  k=2
> case 2
>  .
>  .
>  i=2  j=2  k=1
>  case 1
>  i=2  j=2  k=2
> case 2
>  i=2  j=2  k=3
> .
> .
>  i=3  j=3  k=1
>  case 1
>  i=3  j=3  k=2
> case 2
>  i=3  j=3  k=3
> case 2
>
>
> Thanks
>
> *
> *   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/
>

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