I am creating several maps showing hospitals using the spmap command in Stata 12. I have a problem related to the legend. Each hospital gets a score, A-E, (the variable Pd1_n in my code example) and the associated marker is assigned a colour. I am creating these maps for several different scoring variables and regions I want the legend to look the same in all maps (eg. “A” should always be green and “C” always orange). My problem is that for some regions not all scores will be represented in the data set and when this happens the legend changes. For example, if there is no hospital with a “B” score then my legend will show “C” scores in dark green instead of orange and the labels will no longer be correct (“C”s will look like “B”s). Is there a way of making sure that the legend always looks a certain way (always shows A-E with the right colours)?
Here is a simplified example of my code.
use scndta, clear
spmap using scncoor, id(id) ///
legend(on label(3 "A (90+)") label(4 "B (80-99)") label(5 "C (75-79)") label(6 "D (65-74)") label(7 "E<65") label(8 "Insufficient records") order(3 4 5 6 7 8 )) ///
point(data("merged_hospitals.dta") x(Easting) y(Northing) ") by(Pd1_n) ///
fcolor(green dkgreen orange dkorange cranberry black) shape(O D O S T X) size(small))
At the moment the only way I can think of to solve this problem is to add fake data with all scores to the data set I use in the point option (merged_hospitals) and give my fake data points coordinates that will be hidden behind the legend but this is really time consuming. Is there a better way of doing it?
Here is a simplified example of my code.
use scndta, clear
spmap using scncoor, id(id) ///
legend(on label(3 "A (90+)") label(4 "B (80-99)") label(5 "C (75-79)") label(6 "D (65-74)") label(7 "E<65") label(8 "Insufficient records") order(3 4 5 6 7 8 )) ///
point(data("merged_hospitals.dta") x(Easting) y(Northing) ") by(Pd1_n) ///
fcolor(green dkgreen orange dkorange cranberry black) shape(O D O S T X) size(small))
At the moment the only way I can think of to solve this problem is to add fake data with all scores to the data set I use in the point option (merged_hospitals) and give my fake data points coordinates that will be hidden behind the legend but this is really time consuming. Is there a better way of doing it?
Comment