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: How Can I Add Different Titles to Multiples Graphs Created in a Loop


From   "Eric Booth" <[email protected]>
To   <[email protected]>
Subject   st: RE: How Can I Add Different Titles to Multiples Graphs Created in a Loop
Date   Wed, 7 Apr 2010 13:46:54 -0500

>

Try using the variable labels to accomplish this task.  So, you would label variable A "Bronchitis" using:

label var A "Bronchitis"
...etc...

then use the extended function in the "title()" part of your loop to reference the variable label.  So, using the auto.dta, something like:

*****
clear

webuse auto

**create dummy categories for the loop**
dummies mpg
ds mpg*
label var mpg1 "Test"

/*
note that the variable labels are automatically created (e.g. ""mpg==    14.0000"")
*/


foreach z in `r(varlist)'  {
  graph pie, over(`z')  title(`:variable label `z'')
}

*****
For more tips on using graphs in loops, check out Gabi Huiber's posting here:

http://enoriver.net/index.php/2009/04/14/another-use-for-local-macros-stata-graphs/


__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]




-----Original Message-----
From: [email protected] on behalf of Nicolás Rojas
Sent: Wed 4/7/2010 1:30 PM
To: [email protected]
Subject: st: How Can I Add Different Titles to Multiples Graphs Created in a Loop
 
Hello everyone,
                        *I am making descriptive statistics from a
data base about people who get sick and have to decide whether they go
to an hospital or not within the last twelve months. Therefore, people
can get sick of more than one sickness.

                       * My problem is how to make pie graphs with a
loop and put titles to every graph in the loop.

                        *Thus, imagine I have 15 dummy variables
indicating whether people go to a hospital for 15 different kind of
sickness (say A, B, C D .. O ) . If they didn't get sick the variable
has a missing value.
then I could use the following:

local sickness "A B C D ... O"

foreach z of local sickness {
  graph pie, over (`z') saving(`z')
}

However, what I want to do is to put titles with the real name of the
sickness while running the loop. That is, I want to put titles like
Bronchitis for variable A Sinusitis for variable B etc.
Obviusly it would be easy to write:
local sickness "A B C D ... O"
foreach z of local sickness {
  graph pie, over (`z') saving(`z') title(`z')
}

But the problem is that woud put titles that are not the real name of
the variable (A B C instead of bronchitis sinusitis). I could rename
the variables so thar instead of A B C they are named bronchitis
sinusitis etc. The problem with that is that there are sickness that
have compund names so the would be named, for example, common_cold .
I don't want to have graphs with titles that have an underscore. Also,
as people can get more than one sickness by() and labels would not
help either.
Does anybody know what to do??

Thanks,
Nicolas Rojas
Pontifical Catholic University of Chile

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

<<winmail.dat>>



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