Statalist


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

Re: st: -if- and r() in -histogram-


From   [email protected] (Jeff Pitblado, StataCorp LP)
To   [email protected]
Subject   Re: st: -if- and r() in -histogram-
Date   Thu, 04 Feb 2010 09:40:07 -0600

Antoine Terracol <[email protected]> is using an -if- condition
with -histogram- that depends on an -r()- result, but -histogram- isn't
behaving as expected:

> I am puzzled by the fact that -histogram- does not seem to properly 
> select cases based on a comparison with a saved result after -summarize-:
> 
> /**********************/
> clear
> cap graph drop _all
> set obs 1000
> g x=exp(rnormal())
> su x, de
> local p95=r(p95)
> di r(p95)
> hist x if x<r(p95), name(ha)
> hist x if x<`p95', name(hb)
> hist x, name(hc)
> /**********************/
> 
> the first histogram (with the -if- statement and the reference to 
> r(p95)) is identical to the last histogram (without the -if- statement). 
> When r(p95) is saved to a local macro which is then used in an -if- 
> statement, it works fine (second graph).
> 
> Now, I have not tried all types of graphs, but -kdensity- seems to 
> behave as expected:
> 
> /**********************/
> clear
> cap graph drop _all
> set obs 1000
> g x=exp(rnormal())
> su x, de
> local p95=r(p95)
> di r(p95)
> kdensity x if x<r(p95), name(ka)
> kdensity x if x<`p95', name(kb)
> kdensity x, name(kc)
> /************************/

This is unintended behavior and will be fixed in a future update to Stata.

--Jeff
[email protected]
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index