Statalist The Stata Listserver

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

st: Re: Mata logical operators

From   "Michael Blasnik" <>
To   <>
Subject   st: Re: Mata logical operators
Date   Wed, 25 Oct 2006 14:48:34 -0400

I think you need to check your logic. When you use "or" conditions, the loop will continue while any of the conditions are true. You should use "and" conditions to make it terminate when any are false.

Michael Blasnik

----- Original Message ----- From: "U.A.QU.AP" <>
To: <>
Sent: Wednesday, October 25, 2006 3:18 PM
Subject: st: Mata logical operators

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)) {
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?
Thank you
AbdelRahmen El Lahga
*   For searches and help try:

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