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

st: RE: Query: Adding yline()

From   "Nick Cox" <>
To   <>
Subject   st: RE: Query: Adding yline()
Date   Mon, 18 Aug 2003 17:44:02 +0100
> I need help with adding a yline to a graph - the value of 
> the yline comes
> from a variable "med1" as follows
> egen med1=median(midobs1)
> graph box midobs1 rmidobs1, over(site) yline(`med1') 
> The graph command runs but does not show the required yline().
> I would very much appreciate your suggestions.

This doesn't work for the following reason. 

`med1' says get the local macro -med1- and 
put its contents _here_. 

Evidently you never defined such a local macro, 
so there is no reason to expect it to work. 

This should work: 

su midobs1, detail 
graph box midobs1 rmidobs1, over(site) yline(`r(p50)') 

Note that there is no need to create a variable 
containing a constant again and again. 


egen med1 = median(midobs1) 
graph box midobs1 rmidobs1, over(site) yline(`=med1[1]') 

would also work. 

`=med1[1]' says work out -med1[1]- and put its value _here_. 
As by construction all the values of -med1- are the same, 
we could pick any one of them. 

As said, this will work, but I suggest that the first
method is better. 


*   For searches and help try:

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