Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

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

# Re: st: RE: graph rarea optical illusion or coding error?

 From Nick Cox To statalist@hsphsun2.harvard.edu Subject Re: st: RE: graph rarea optical illusion or coding error? Date Wed, 11 May 2011 18:41:59 +0100

```No-one seemingly noticed a quite different problem with the code.

The values for alpha will never include .95. Why not? Precision problems again.

. forv alpha = .05(.06).95 {
2. di `alpha'
3. }
.05
.11
.17
.23
.29
.35
.41
.47
.53
.59
.65
.71
.77
.83
.89

That looks a puzzle until you look more closely

. forv alpha = .05(.06).95 {
2. di %23.18f  `alpha'
3. }
0.050000000000000003
0.110000000000000000
0.170000000000000010
0.230000000000000010
0.289999999999999980
0.349999999999999980
0.409999999999999980
0.469999999999999970
0.530000000000000030
0.590000000000000080
0.650000000000000130
0.710000000000000190
0.770000000000000240
0.830000000000000290
0.890000000000000350

Adding .06 to that last will take the result past .95.

It is better to loop over the integers and do non-integer arithmetic
inside the loop:

. forval i = 1/16 {
2. local alpha = 0.05 + (`i'  - 1) * 0.06
3. di %23.18f `alpha'
4. }
0.050000000000000003
0.110000000000000000
0.170000000000000010
0.230000000000000010
0.289999999999999980
0.349999999999999980
0.409999999999999980
0.469999999999999970
0.530000000000000030
0.590000000000000080
0.650000000000000020
0.709999999999999960
0.770000000000000020
0.830000000000000070
0.890000000000000010
0.949999999999999960

or

forval i = 0/15 {
local alpha = 0.05 + `i' * 0.06
...
}

For more discussion, see

SJ-10-1 pr0051  . . . . . . . . . . . . Stata tip 85: Looping over nonintegers
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
Q1/10   SJ 10(1):160--163                                (no commands)
tip on using forvalues to loop over numbers

Nick

On Wed, May 11, 2011 at 1:44 PM, philippe van kerm
<philippe.vankerm@ceps.lu> wrote:
> Nice picture, Uli!
>
> My own bet would be that the lines are visible on your graph because the area and lines are drawn in the same color but not the same intensity. To me it looks like adding the -fintensity(100)- option works ok:
>
>  forv i = 15(-1)1 {
>          local rarea `rarea'          ///
>          || rarea ub`i' lb`i' rep78,  ///
>          lcolor(gs`i') fcolor(gs`i') fintensity(100) lwidth(none) sort
>  }
>
> Philippe
>
>
>> -----Message d'origine-----
>> De : owner-statalist@hsphsun2.harvard.edu [mailto:owner-
>> statalist@hsphsun2.harvard.edu] De la part de Ulrich Kohler
>> Envoyé : Wednesday, May 11, 2011 2:04 PM
>> À : statalist
>> Objet : st: graph rarea optical illusion or coding error?
>>
>> Listers,
>>
>> I try to create a figure of shaded areas for 5%, 10%, 15% ... 95%
>> confidence intervals. The resulting areas seem to have a lines around
>> the areas that are darker than both neighbouring areas. Is it possible
>> to get rid of this, or is this just an optical illusion?
>>
>> Here is a minimal example of my code. Note that I tried various
>> settings
>> for -lwidht()- , -lcolor()-, -fintensity()-. Most surprisingly
>> -lcolor(none)- removes areas completely, btw.
>>
>> -----------------------------------------------------illusion.do
>> sysuse auto, clear
>>
>> collapse (mean) mean=mpg (semean) se=mpg, by(rep78)
>>
>> local pen 15
>> forv alpha = .05(.06).95 {
>>       gen ub`pen' = mean + invnormal(1-`alpha'/2)*se
>>       di "gen ub`pen' = mean + `=invnormal(1-`alpha'/2)'*se"
>>       gen lb`pen' = mean - invnormal(1-`alpha'/2)*se
>>       local pen = `pen'-1
>> }
>>
>> forv i = 15(-1)1 {
>>         local rarea `rarea'          ///
>>         || rarea ub`i' lb`i' rep78,  ///
>>         lcolor(gs`i') fcolor(gs`i') lwidth(none) sort
>> }
>>
>> graph twoway `rarea' || , legend(off)
>>
>> exit
>> -------------------------------------------------------------------

*
*   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–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index