Statalist


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

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


From   Antoine Terracol <[email protected]>
To   [email protected]
Subject   Re: AW: st: -if- and r() in -histogram-
Date   Thu, 04 Feb 2010 15:08:10 +0100

So I guess that to be on the safe side one should use `r()' in every -if- statement. That should be made clearer in [U]18, section 18.8. There might be technical reasons, but why not mark the relevant subsample right after parsing the command, rather than when the content of the -if- statement could have been modified by subroutines?

Antoine



Nick Cox wrote:
`r(95)' is evaluated before -histogram- even opens: -histogram- sees only the numeric result. That's not true of r(95). In the first instance the text "r(95)" is used and only later it is evaluated. That is, you want -histogram- to work with a pre-existing r(95), but inside -histogram- other r-class results are produced and that undermines your aim. Nick [email protected]
Antoine Terracol

True, but I find it strange that references to r() work with -kdensity- (or commands like -summarize-), but hot with -histogram- (nor with -graph box-) where `r()' seems to be required.

Martin Weiss wrote:
<>
You do get the correct graph with:

*************
clear
cap graph drop _all
set obs 1000
g x=exp(rnormal())
su x, de
hist x if x<`r(p95)', name(ha)
*************



HTH
Martin

-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Antoine
Terracol
Gesendet: Donnerstag, 4. Februar 2010 13:24
An: [email protected]
Betreff: Re: st: -if- and r() in -histogram-

<>

of course, all the "hist" below should be "kdensity", and the correct piece of code is

/**********************/
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)
/************************/

Antoine Terracol wrote:
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)
hist x if x<r(p95), name(ka)
hist x if x<`p95', name(kb)
hist x, name(kc)
/************************/

*
*   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/


--
Ce message a ete verifie par MailScanner
pour des virus ou des polluriels et rien de
suspect n'a ete trouve.

*
*   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