[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: Linking legend text to the value of a variable

From   "Nick Cox" <>
To   <>
Subject   st: RE: Linking legend text to the value of a variable
Date   Thu, 1 Oct 2009 19:16:20 +0100

It seems you need to "look up" string values. One way to approach this
is as follows:

Outside your loop: 

gen long obsno = _n 

Inside your loop you find the smallest observation numbers satisfying
various conditions, e.g. 

su obsno if idvar == "`i'" & idvar2 == 1 & idvar3 == 1, meanonly 
local name1 = idvar2_name[`r(min)'] 
su obsno if idvar == "`i'" & idvar2 == 2 & idvar3 == 1, meanonly 
local name2 = idvar2_name[`r(min)']

... legend(order(1 "`name1'" 2 "`name2'"))  

The largest observation numbers will work as well. (By the way, I never
use repeated -label()- calls given scope to call -order()- once.) 


Dorothy Bridges

I have a loop creating twoway graphs along the lines of the following:

levels idvar, local(ID)
foreach i of local ID{
di "`i'";
twoway (line yvar xvar if idvar=="`i'" & idvar2==1 & idvar3==1,
(line yvar xvar if idvar=="`i'" & idvar2==2 & idvar3==1, lpattern(dash))
(line yvar2 xvar2 if idvar=="`i'" & idvar2==1 & idvar3==1, color(navy)
yaxis(2) lpattern(dash))

And I would like the legend to be: legend(label(1 =idvar2_name if
idvar=="`i'" & idvar2==1 & idvar3==1) label(2 =idvar2_name if
idvar=="`i'" & idvar2==2 & idvar3==1))

How might I accomplish this?  I found this
( in the
archive but couldn't quite get from there to where I would like to be.

*   For searches and help try:

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