Bookmark and Share

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: Superimposed graphs / selected data / if & by


From   Eric Booth <[email protected]>
To   "<[email protected]>" <[email protected]>
Subject   Re: st: Superimposed graphs / selected data / if & by
Date   Mon, 4 Jul 2011 17:59:12 +0000

<>
On Jul 4, 2011, at 6:17 AM, Allan Reese (Cefas) wrote:
> [G] manual states || and  ( ) notations for superimposed graphs are
> equivalent.  Here they are not.

I haven't found that statement in the manual; however, in an example similar to the one you show, the help file for -twoway-  (-help twoway-) points out that:

 "We have chosen to show these two examples with the ()-binding notation because it makes the scope of each -if-
    exp so clear.  In ||-separator notation, the commands would read"  [examples here]

which is tells me that:

> scatter  high low date if size<3, by(size) ||  rbar high low date if
> size<3, by(size) barwidth(.6) name(g3)

doesnt work because Stata doesnt know where to apply the if and and by.  ()-binding provides that guidance.  However, the examples in -help twoway- that follow the quote above point out that you can still use || in this case.  Changing your last example from:

> twoway (scatter  high low date  ) ( rbar high low date , barwidth(.6))
> if size<3, by(size) name(g4)


to: 

tw scatter  high low date ||  rbar high low date , barwidth(.6) || if size<3, by(size) name(g4, replace)

the last || tells Stata to apply the if and by to the scatter and rbar without ().  

However, in these cases I still use ()-binding just to help me keep all the plots and qualifiers straight. Any if/by/etc inside each plot's ()  applies strictly to that plot and anything outside the () for each plot applies to all plots (which is what your last example shows).

- Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
Office: +979.845.6754




On Jul 4, 2011, at 6:17 AM, Allan Reese (Cefas) wrote:

> Got the solution for this from Tech Support and it's worth reporting to
> make it searchable. 
> 
> Tried to add bars to a scatterplot and found this effect with the by()
> option using || notation:
> Each plot separately obeyed the selection and shows only the requested
> levels for the by() variable, but when the two plots are superimposed,
> it shows all levels for by().  
> 
> [G] manual states || and  ( ) notations for superimposed graphs are
> equivalent.  Here they are not.
> 
> However, solution is to use ( ) notation and put -if- and -by- outside
> the ( ).
> 
> Nonsense example:
> 
> sysuse sp500
> recode volume (min/9999=1) (10000/20000=2) (20000/max=3),  gen(size) 
> twoway rbar high low  date  if size<3, by(size) barwidth(.6) name(g1)
> scatter     high low  date  if size<3, by(size)              name(g2)
> scatter  high low date if size<3, by(size) ||  rbar high low date if
> size<3, by(size) barwidth(.6) name(g3)
> twoway (scatter  high low date  ) ( rbar high low date , barwidth(.6))
> if size<3, by(size) name(g4)
> 
> Allan
> 
> 
> *
> *   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/




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