Thanks Nick!
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Nick Cox
Sent: sexta-feira, 22 de Fevereiro de 2008 18:10
To: [email protected]
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
[email protected]
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/