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

st: RE: Overlapping variable labels


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Overlapping variable labels
Date   Mon, 22 Aug 2005 18:18:10 +0100

I would phrase this in terms of text labels. 

Ulrich Kohler has written an -egen- function -gmlabvpos- 
using another approach to this problem, which is 
downloadable from SSC. 

Nick 
[email protected] 

RJ Harris
 
> Have been having a problem of my own with the above as I'm 
> often getting
> groups of observations clustered together. The way I thought 
> to deal with
> this is to use the mlabvposition() option so that a variable 
> can be used to
> set the position of the label on a clock face.
> 
> Of course, this is rather tedious to set by hand, so the 
> solution I came up
> with was to do a cluster analysis on the co-ordinates so they're in
> sensible groups, then do some trigonometry to set the clock 
> positions such
> that labels are spread out around each group of observations. 
> It doesn't
> work perfectly and takes a bit of fiddling with cluster sizes 
> sometimes,
> but might be worth a try. I don't know if anyone's had a go at this
> approach before and already done a far better job, but here 
> is some example
> code:
> 
> 
> gen temp = _N/5
> recast int temp, force
> replace temp = 1 if temp == 0
> local num = temp
> drop temp
> 
> cluster kmeans x y, k(`num') gen(clNo)
> summ clNo
> local max = r(max)
> gen xx = .
> gen yy = .
> 
> forvalues i = 1/`max'{
>  	summ x if clNo == `i'
>  	replace xx = x-r(mean) if clNo == `i'
>  	summ y if clNo == `i'
>  	replace yy = y-r(mean) if clNo == `i'
> 
>  	replace xx = 1 if xx == 0	// some clusters only 1 obs
>  	replace yy = -1 if yy == 0
> }
> 
> gen clockVar = .
> replace clockVar = 3-12*atan(yy/2*xx)/(2*_pi) if xx > 0 & yy > 0
> replace clockVar = 3-12*atan(yy/2*xx)/(2*_pi) if xx > 0 & yy < 0
> replace clockVar = 9-12*atan(yy/2*xx)/(2*_pi) if xx < 0 & yy < 0
> replace clockVar = 9-12*atan(yy/2*xx)/(2*_pi) if xx < 0 & yy > 0
> recast int clockVar, force
> replace clockVar = 12 if clockVar == 0
> sort clNo clockVar
> list
> 
> scatter y x, mlabel(name) mlabvposition(clockVar)

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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