[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Svend Juul" <SJ@SOCI.AU.DK> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
Re: st: loops |

Date |
Sun, 23 Sep 2007 10:16:45 +0200 |

Arun wrote: I am dealing with huge datasets for which I have to estimate percentile exposure time within two to three subsets. I noticed something that happened there and tried duplicating it with a stata example dataset [webuse beetle] and I noticed it again. Attached below is the do file modified for beetle dataset. /* Stata/IC 10.0 for Macintosh */ /* Do file to assess LD10-90 for beetle.dta */ /* Obtain beetle from webuse beetle */ use ~/desktop/beetle.dta gen p=r/n forvalues i=1/3 { glm p ldose if beetle==`i', f(b) forvalues j=0.1(0.1)0.9 { local k=`j'*100 display as text "LD `k' = " as result (log(`j'/(1-`j'))-_b[_cons])/_b [ldose] } } A part of the result for beetle.dta looks like this... ... LD 10 = 1.7169257 LD 20 = 1.7389921 LD 30 = 1.7536588 LD 40 = 1.7656816 LD 50 = 1.7767148 LD 60 = 1.787748 LD 70 = 1.7997708 LD 80 = 1.8144375 LD 89.99999999999999 = 1.8365039 Why is this last LD 90 showing as 89.99... ... . Am I doing something odd (bad math) in the do file? -------------------------------------------------------------- You do things right, but computers (not only Stata) do have limited precision; see, e.g., http://www.stata.com/support/faqs/data/prec.html <http://www.stata.com/support/faqs/data/prec.html> . Take a look at this: . local k=1/3 . display `k' .33333333 . display "`k'" .3333333333333333 If a macro is expanded to a text string it contains the result in double precision. If you let -display- display it, you see fewer digits. This means that you could write display "LD " `k' " = ..." rather than display "LD `k' = ..." to get: LD 90 = 1.8365039 Hope this helps Svend ________________________________________________________ Svend Juul Institut for Folkesundhed, Afdeling for Epidemiologi (Institute of Public Health, Department of Epidemiology) Vennelyst Boulevard 6 DK-8000 Aarhus C, Denmark Phone, work: +45 8942 6090 Phone, home: +45 8693 7796 Fax: +45 8613 1580 E-mail: sj@soci.au.dk _________________________________________________________ * * For searches and help try: * http://www.stata.com/support/faqs/res/findit.html * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

- Prev by Date:
**st: CLAD and estout** - Next by Date:
**Re: st: Simple Question - Use of rndbin** - Previous by thread:
**st: loops** - Next by thread:
**Re: st: loops** - Index(es):

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