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: adding different text to each of a set of graphs


From   Phil Schumm <[email protected]>
To   <[email protected]>
Subject   Re: st: adding different text to each of a set of graphs
Date   Fri, 26 Apr 2013 15:53:59 -0500

On Apr 26, 2013, at 2:30 PM, [email protected] wrote:
> I am producing a set of line graphs (e.g., via -twoway line o time, by(id)-) and I want to add the value of a fourth variable as a "note" (or other form of text) to each of the graphs; is this possible? if yes, how?


There are probably better ways to do this, but one approach would be


    tempvar obs
    gen `obs' = _n
    qui levelsof id, loc(ids)
    foreach id of loc ids {
        qui sum `obs' if id==`id'
        line o time if id==`id', t1title(`id') note(`"`=note[`r(min)']'"') ///
            name(p`id', replace)
        loc plots "`plots' p`id'"
    }
    gr combine `plots', ycommon xcommon note("Graphs by id")


As you can see, this assumes that the var id is numeric and that the value of note (i.e., your 4th variable) is constant within unique values of id.  Note that the graph this generates will not look *exactly* like that you get with the -by()- option, but you can make it so with a few additional graph options if you'd like.


-- Phil


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index