Statalist The Stata Listserver


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

st: RE: Mata logical operators


From   Jesper Kjr Hansen <jkh-stata@msecon.eu>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Mata logical operators
Date   Wed, 25 Oct 2006 20:53:39 +0200

AbdelRahmen El Lahga wrote:
> Dear all,
> I've written a loop that maximize a given function. In order to
> control convergence i use 3 critereon
> iteration number and 2 scalars for tolerance
> My statement is :
> ...
> while ((critb > eps) || (crita > eps^2) || (iter <= 31)) {
> ....stmts
> iter=iter+1
> }
> I expect that Mata must stop the loop when at least one of 
> the three critereon is reached. But the problem is:  Mata 
> goes untill iteration 112 (for example) and it doesn't stop 
> the loop at iteration 31 as expected.
> My output portion is given below:
> End iteration    112.00
> Stepsize:      0.02
> Criterion:      1.35
> Percent variation:      0.00
> ....
> Even when i replace (||) by (|) I get the same results
> any ideas to resolve this problem? Waht is the logic of mata 
> to evaluate 3 or more condition in the while loop?

If only one of the three criterion's need to be met, 
I think you ought to use the & (or &&) operator instead,

i.e.  while ((critb > eps) & (crita > eps^2) & (iter <= 31)) {
              ....stmts
              iter++
      }

The while loop continues as long as the expression 
is true (non-zero). See -help [M-2] while-

-- Jesper Kjr Hansen
mailto:jkh-stata@msecon.eu


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