Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • forvalues-loop neglects last value, why?

    Hey guys,
    in the context of my master thesis, I need to run some quantile regressions. However, when I run the following section of my code
    Code:
    forvalues qq = .05(.05).95 {
    qreg yt_1 nfci yt, quantile(`qq') vce(robust)
    }
    STATA runs the quantile regressions up to the .9 regression but not the .95 regression. How could this be?

    Thanks in advance,
    Mario

  • #2

    It is a precision problem. For the explanation and the remedy, see https://www.stata-journal.com/articl...article=pr0051

    Let's show more detail.

    Code:
    forval qq = .05(.05).95 { 
    di %23.18f `qq' 
    } 
       0.050000000000000003
       0.100000000000000006
       0.149999999999999994
       0.200000000000000011
       0.250000000000000000
       0.299999999999999989
       0.349999999999999978
       0.400000000000000022
       0.450000000000000011
       0.499999999999999889
       0.549999999999999933
       0.599999999999999978
       0.650000000000000022
       0.700000000000000067
       0.750000000000000111
       0.800000000000000155
       0.850000000000000200
       0.900000000000000244
    Why doesn't Stata (*) show an equivalent of 0.95? Because in effect you are asking for something closer to
    Code:
    . di %23.18f (0.90 + 0.05)
       0.950000000000000067
    rather than a direct display. of


    .
    Code:
     di %23.18f 0.95
       0.949999999999999956
    You would be better off with

    Code:
    forvalues q = 1/19 {
         local qq = `q' * 0.05 
         qreg yt_1 nfci yt, quantile(`qq') vce(robust)
    }
    (*) https://www.statalist.org/forums/help#spelling

    Comment


    • #3
      Thanks a lot for this detailed explanation, Nick. Appreciate that much!

      Comment

      Working...
      X