Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: looping graph and changing title

From   "R.E. De Hoyos" <>
To   <>
Subject   st: looping graph and changing title
Date   Tue, 3 Aug 2004 20:37:48 +0100

How can I change the title of a graph that it is being generated by a loop.

I want to define "titlename" as the string value of another variable. My
data looks like the following

country         code       var1      var2      year
France            1            x1        y1         t
UK                 2           x2         y2         t
US                  3           x3        y3          t
.                                                          ...

What I created is a graph for each country using the following loop:

levels cty, local(lev)
qui foreach y of local lev {
 local name "country1[`y']"
 noi di `name'
 #delimit ;
 tw line var1 year if cty==`y', yaxis(1) clp(solid)  || line var2 year if
cty==`y', yaxis(2) clp(dash)
 title("`name'") ytitle("mytitle", axis(1)) ytitle("mytitle2", axis(2))
 legend(label(1 "label1") label(2 "label2"))
 noi di "Graph cty`y' Saved" ;
 #delimit cr

Although each local macro `name' displays the desired country name obtained
from the variable "country1", the graphs appear with the title "country[1]"
instead of its string (e.g. France).

Any thoughts?

Many thanks,


*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index