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: graph pie with variable label as title


From   Maarten Buis <[email protected]>
To   [email protected]
Subject   Re: st: graph pie with variable label as title
Date   Fri, 7 Mar 2014 11:13:21 +0100

I guess you know that pie charts are not a good idea, and that you are
somehow forced to use these. So I will tell you what you want to know,
but this should not be considered as an endoursement of pie charts.

*------------------ begin example ------------------
// prepare some example data
sysuse nlsw88, clear

gen byte marst = !never_married + married  ///
    if !missing(never_married, married)
label variable marst "marital status"
label define marst 0 "never married"       ///
                   1 "divorced or widowed" ///
                   2 "married"
label value marst marst

gen byte occat = cond(occupation < 3                 , 1,      ///
                 cond(inlist(occupation, 5, 6, 8, 13), 2, 3))  ///
                 if occupation < .
label variable occat "occupation in categories"
label define occat 1 "high"   ///
                   2 "middle" ///
                   3 "low"
label value occat occat

gen byte edcat = cond(grade <  12, 1,     ///
                 cond(grade == 12, 2, 3)) ///
                 if grade < .
label define edcat 1 "less than high school" ///
                   2 "high school"           ///
                   3 "more than high school"
label value edcat edcat
label variable edcat "education in categories"

// the graphs in a loop
foreach var of varlist marst edcat occat race {
    graph pie wage, over(`var') ///
    title(`:var label `var'')   ///
    name(`var', replace)
}
*------------------- end example -------------------
* (For more on examples I sent to the Statalist see:
* http://www.maartenbuis.nl/example_faq )

On Fri, Mar 7, 2014 at 10:31 AM, Nick Bornschein
<[email protected]> wrote:
> Hi,
>
> I want to create a lot of pie charts with a loop. The loop itself works fine
> but I want to add a title to each pie chart which should be the variable
> label of each variable. How could I get that to work?
>
> -Nick
> *
> *   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/



-- 
---------------------------------
Maarten L. Buis
WZB
Reichpietschufer 50
10785 Berlin
Germany

http://www.maartenbuis.nl
---------------------------------
*
*   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