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 at the end of May, and its replacement, statalist.org 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 <asilvam@uc.cl>
To   statalist@hsphsun2.harvard.edu
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}
}
}

end
med

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

Andres
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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   |   Site index