RATS 11.1
RATS 11.1

BREAK    (no parameters)

Breaks program flow out of the innermost DO, DOFOR, LOOP, WHILE or UNTIL loop. You need to use a GOTO in order to break out of a more complicated looping structure.

Example

This does iterated weighted least squares, allowing for up to 40 iterations, but breaking out of the loop if the slope coefficient changes by less than .00001 from one iteration to the next. (This is excerpted from the Greene textbook example GRN7P281.RPF).

 

set resids = %resids

*

* Iterated. We'll allow up to forty iterations. Each time, we'll check

* to see if the new value of c2 is very close to the last one. Once the

* (absolute value) of the gap is small enough, we break the loop. Inside

* the loop, we suppress the regression output. We show the result with

* the last value once we exit the loop.

*

do iters=1,40

   set logusq = log(resids^2)

   linreg(noprint) logusq

   # constant lf

   if abs(%beta(2)-c2)<.00001

      break

   compute c2=%beta(2)

   prj logvar

   linreg(equation=base,spread=exp(logvar),noprint)

   set resids = %resids

end do iters

disp "Convergence achieved after" iters "iterations"

disp "Estimated c2 is" c2


 


Copyright © 2026 Thomas A. Doan