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

st: RE: Re: Trouble with " if"


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Re: Trouble with " if"
Date   Fri, 12 Mar 2004 14:23:15 -0000

An answer is that Stata has no idea of what is 
sensible, misleading, silly, etc. or generally any idea 
of meaning or semantics. 

It only has rules of syntax. What you wrote is 
legal syntax, but not what you mean, given order
of evaluation rules in particular. 

Nick 
n.j.cox@durham.ac.uk 

> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu
> [mailto:owner-statalist@hsphsun2.harvard.edu]On Behalf Of Jan 
> Pettersson
> Sent: 12 March 2004 13:54
> To: statalist@hsphsun2.harvard.edu
> Subject: st: Re: Trouble with " if"
> 
> 
> Shouldn't
> 
>              if `i'==`j' & `j' ==`k' {
> 
> work?
> /Jan
> 
> ----- Original Message ----- 
> From: "Christophe Bontemps" <bontemps@toulouse.inra.fr>
> To: <statalist@hsphsun2.harvard.edu>
> 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/
> 

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