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]

st: RE: RE: RE: RE: Graphing: How to suppress labels on second y axis


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: RE: RE: RE: Graphing: How to suppress labels on second y axis
Date   Fri, 1 Oct 2010 11:20:32 +0100

Sorry, but I don't follow. I suggest posting the entire segment of code that is relevant to your questions. Show us code that gets what you want, and people can say whether it can be improved. Or show us code that doesn't get what you want. 

Also, it would make it much simpler to answer questions if, as suggested in the FAQ, you use one of Stata's provided datasets or a simple concocted dataset that you include in your posting.

If you wish to -replace- a variable by 1, = 1 on the right-hand side is surely simplest. But somehow I doubt that is necessary at all. 

Nick 
[email protected] 

McDermaid, Cameron

I wasn't clear, Nick. The comments for resetting to one said "for the next loop" but it isn't clear that this meant a different loop.

The lev`alert' value is plotted twice against different measures: normalized counts and raw counts.  That's why it must be reset to one in order to scale properly for the next measure (the first is a proportion, the second can be any number) and the rationale for storing the value of r(max) within the foreach loop to do so.

Another option for the reset to 1 is simply to replace alert`lev'=alert`lev'/alert`lev' and save one line of code.

I must admit, I'm still puzzled by my inability to suppress labelling on a second axis. It isn't clear to me from the documentation why this would fail with ylabel(none, axis(2)).

Nick Cox
 
> That's correct. The maximum is put in r(max) after -summarize- but all
> r-class results are ephemeral and the next r-class command will
> overwrite or obliterate them. So, make all the use you want of r(max)
> before it is lost.
> 
> (Since many graphics commands do some computation internally they may
> well use an r-class command.)
> 
> The other side of the coin from my previous advice is that if you want
> to keep hold of a result you should indeed store it. Your code didn't
> show that you wanted to do that.
> 
> That said, it is not clear why you want to repeat exactly the same
> calculations. Don't you have the results stored in the variable you
> generated?
> 
> If they are not really the same calculations, then it is natural that
> the same command might need to be repeated on different data.
> 
> For a start on documentation, see help on -saved results-.
 
McDermaid, Cameron
 
> Having tested this a little more thoroughly, unless I'm doing something
> wrong (script below) it appears r(max) isn't maintained in the loop so
> is missing when the alert`lev' is to be reset to 1, resulting in a
> missing values for the operation.
> 
> The solution is to use the local macro assignment of r(max) as I did
> previously or insert sum `lev'normalized, meanonly  before
> alert`lev'=alert`lev'/r(max) when the alert`lev' is to be reset to 1.
 
> loc levels=" Respiratory Asthma ILI"
> foreach lev of loc levels {
> sum `lev'count, meanonly
> replace alert`lev'= alert`lev'* r(max)
> <<GRAPHING ACTIVITY>>
> replace alert`lev'=alert`lev'/r(max)
> }
 
Nick Cox

> > Two small points. It's a smidgen quicker and shorter to write
> >
> > sum `lev'normalized, meanonly
> > replace alert`lev'= alert`lev'* r(max)  /*adjusts alert to maximum
> value
> > in line plot */
> >
> > 1. -su, meanonly- despite its name yields the maximum (and some other
> > stuff you can ignore). This is discussed at excruciating length in
> >
> > SJ-7-3  st0135  . . . . . . . . . . . Stata tip 50: Efficient use of
> > summarize
> >         . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
> N.
> > J. Cox
> >         Q3/07   SJ 7(3):438--439                                 (no
> > commands)
> >         tip on using the meanonly option of summarize to more
> >         quickly determine the mean and other statistics of a
> >         large dataset
> >
> > 2. The business of putting r(max) in a local, and then reading from
> the
> > local, can be shortened. This has been called "cutting out the middle
> > macro".

McDermaid, Cameron

> > I've made a tweak to Nick's suggestion below.  One rationale for using
> 2
> > axes was that the primary Y axis is one scale that can vary with the
> > data and the second Y axis is fixed from 0 -1 . Using Nick's suggested
> > script below uses the alert's actual value (missing, 1) is plotted on
> > the primary Y axis and is often out of scale as to be not easily seen,
> > depending on the line graph data.
> >
> > What I've done is adjust the alert value (1) to the maximum value of
> the
> > data in the line plot then back to 1 once the plot is done.
> >
> > e.g.
> >
> > quietly: sum `lev'normalized
> > local maxval: display `r(max)'
> > replace alert`lev'= alert`lev'*`maxval'  /*adjusts alert to maximum
> > value in line plot */
> >
> > do the plot with || dropline `lev'normalized adm_date if alert`lev'<.,
> > ms(i)
> >
> > replace alert`lev'=alert`lev'/`maxval'  /*adjusts back to 1 for the
> next
> > plot loop*/
> >
> > This seems to be working.  Thanks again to Nick for a kick in the
> right
> > direction.

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