Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: looping with tolerance level


From   Maarten Buis <[email protected]>
To   [email protected]
Subject   Re: st: looping with tolerance level
Date   Fri, 7 Sep 2012 15:56:49 +0200

On Fri, Sep 7, 2012 at 3:27 PM, Andres Silva <[email protected]> wrote:
> 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.


line 4-8 need to be a while loop, see -help while-


---------------------------------
Maarten L. Buis
WZB
Reichpietschufer 50
10785 Berlin
Germany

http://www.maartenbuis.nl
---------------------------------
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index