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

From |
"Nuno" <liststata@gmail.com> |

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

Subject |
st: RE: RE: Strange problem with forvalues |

Date |
Sat, 23 Feb 2008 14:13:45 -0000 |

Thanks Nick! -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox Sent: sexta-feira, 22 de Fevereiro de 2008 18:10 To: statalist@hsphsun2.harvard.edu Subject: st: RE: Strange problem with forvalues What you are observing is nothing to do with -forvalues- as such. It is a consequence of your attempt to do decimal arithmetic on a computer that uses binary. The keyword here is precision. . search precision points to documentation -- but misses the choicest item of all, namely SJ-6-4 pr0025 . . . . . . . . . . . . . . . . . . . Mata matters: Precision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . W. Gould Q4/06 SJ 6(4):550--560 (no commands) looks at programming implications of the floating-point, base-2 encoding that modern computers use I would re-code as follows: forvalues j= 1/9{ statsby _b, by(year) saving(c:\qreg`j'.dta, replace): qreg y x1 x2 x3 x4, quantile(.`j') Note the last detail: The loop is over the integers 1 to 9. -qreg- will see in turn quantile(.1) quantile(.2) and so forth. Then everyone and everything should be happy. Nick n.j.cox@durham.ac.uk Nuno I'm having an issue with Stata and a small routine I've written. The code is the following: forvalues j=.1(.1).9{ statsby _b, by(year) saving(c:\qreg`j'.dta, replace): qreg y x1 x2 x3 x4, quantile(`j') } The objective run the qreg for the deciles .1-.9 and get save the coefficient estimates in a file. The problem is that, when Stata reaches quantile .8 and .9 it seems to assum that j=.7999999999999 or j=.89999999999. This doesn't happen with the other js. command: qreg y x1 x2 x3 x4, quantile(.7999999999999999) by: year (note: file c:\qreg.7999999999999999.dta not found) Statsby groups ----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5 ................ (running qreg on estimation sample) command: qreg y x1 x2 x3 x4, quantile(.8999999999999999) by: year (note: file c:\qreg.8999999999999999.dta not found) Statsby groups ----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5 ................ If I then restart the code with j=.8(.1).9 everyhing runs fine. Any ideas for this to happen? * * 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/ * * 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/

**References**:**st: Strange problem with forvalues***From:*"Nuno" <liststata@gmail.com>

**st: RE: Strange problem with forvalues***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

- Prev by Date:
**st: AW: store means as a new variable** - Next by Date:
**st: Solution to include scaled Stata output in LaTeX presentation (beamer)** - Previous by thread:
**st: RE: Strange problem with forvalues** - Next by thread:
**[no subject]** - Index(es):

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