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, statalist.org is already up and running.


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

Re: st: looping with tolerance level


From   Maarten Buis <maartenlbuis@gmail.com>
To   statalist@hsphsun2.harvard.edu
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 <asilvam@uc.cl> 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index