Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: Including variable labels in graph titles

From   "Nick Cox" <>
To   <>
Subject   RE: st: Including variable labels in graph titles
Date   Sun, 22 Oct 2006 18:17:47 +0100

You can do this in one step and cut out the middle macro. 

foreach v of var <varlist> { 
	twoway (scatter `v' xvar, sort), title(Scatter plot for `: variable label `v'')

However, in general various problems are foreseeable. 

1. No variable label exists. 

2. The variable label includes a comma that will be misinterpreted without 
binding the title text in double quotes. 

3. The variable label includes double quotes that will be misinterpreted without 
binding the title text in compound double quotes. 

4. The title text will seem long and repetitive. 

4. is easy to fix. The others are fixed by this 

foreach v of var <varlist> { 
	local vtext : variable label `v' 
	if `"`vtext'"' == "" local vtext "`v'" 
	twoway (scatter `v' xvar, sort), title(`"Scatter plot for `vtext'"')

See also help for -macro-. 


Jeph Herrin
> . local mylabel : variable label myvar	
> will capture the variable label from -myvar- and put
> it into macro -mylabel-; you can then embed -mylabel-
> in the title string.
Dick Campbell

> > I need to produce a sequence of twoway overlay graphs for a set
> > of variables, say x1 x2 .... xk. Each variable has a label, e.g.
> > x1 "Label for variable x1" .  I have written a do file which cycles
> > through the variables nicely using a foreach command, but I want to
> > include the label of the yaxis variable in the title of the 
> variable.
> > I can't seem to find a way to capture the variable label so that it
> > can be embedded in the title. If there were some routine in Stata
> > that returned the label in a macro I could run it quietly, recover
> > the label and easily embed it in the title, but there 
> doesn't seem to
> > be one. Does anyone have any ideas as to how this might be done?
> > Essentially, I want to this:
> > 
> >  twoway (scatter mpg weight, sort), title(Scatter plot for 
> (variable 
> > label to be inserted here).)

*   For searches and help try:

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