Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: looping with tolerance level

From   Andres Silva <>
Subject   st: looping with tolerance level
Date   Fri, 7 Sep 2012 15:27:43 +0200

Dear Stata Users,

I want to do a loop per observation with a tolerance level. In concrete, I
want to increase the payment (k) until I get a probability (prob) close to 0.5

program med, rclass
set trace on
forvalues j=1/33         {/* looping across observations*/
forvalues k=1/1          {/* looping across level of payment starting from 1*/
scalar prob`j'_`k'=(probability expression including `j' and `k')
scalar tolerance=abs(0.5-prob`j'_`k')

if tolerance<=0.001 {continue} else {k=`k'+1}


However, line 4 and 8 are causing me problems. I appreciate any advice.
Thank you,

*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index