I am not sure I understand.
The variable "key" could take on 6 values, but in this particular
realization you have 4 values = 2, 3, 4, 6
But you want -spmap- to only use the 2nd, 3rd, 4th, and 6th values
from your predfined -fcolor()- list. Is this correct?
For example:
use "Italy-RegionsData.dta", clear
keep id relig1
gen x = id*20
xtile key = relig1, cutpoints(x)
replace key = 6 if id >18
spmap key using "Italy-RegionsCoordinates.dta", id(id) ///
clmethod(unique) fcolor( "215 25 28" "253 174 97" ///
"255 255 191" "171 217 233" "44 123 182" "225 225 225" ) ///
name(gr1,replace)
This would produce a map with the "wrong colors." If you were doing
by hand you could eliminate the colors that do not match the "key"
spmap key using "Italy-RegionsCoordinates.dta", id(id) ///
clmethod(unique) fcolor( "253 174 97" ///
"255 255 191" "171 217 233" "225 225 225" ) ///
name(gr1,replace)
You could automate this by looping through your "key" values to match
them with your predefined -fcolor()- list:
levelsof key, local(levels)
local a "215 25 28" "253 174 97" "255 255 191" "171 217 233" "44 123
182" "225 225 225"
foreach l of local levels {
local b: word `l' of "`a'"
local colorlist "`colorlist' "`b'" "
}
spmap key using "Italy-RegionsCoordinates.dta", id(id) ///
clmethod(unique) fcolor(`colorlist') ///
name(gr2,replace)
Scott
On 9/5/07, Friedrich Huebler <[email protected]> wrote:
> When I draw a choropleth map with -spmap- from SSC, the regions have
> the wrong colors. I define a variable called "key" with the values 1
> to 6, recoded from a variable with the range 0 to 100 percent. 1 to 5
> identify quintiles and 6 identifies regions with missing data. My
> -spmap- command is shown below, with fill colors specified with RGB
> values.
>
> #delimit ;
> spmap key using map.dta,
> id(id)
> clmethod(unique)
> fcolor("215 25 28" "253 174 97" "255 255 191" "171 217 233" "44 123
> 182" "225 225 225")
> ;
>
> None of the regions have a value below 20 and none have a value
> between 60 and 80, so that the first and fourth color in the list
> above ("215 25 28" = dark red and "171 217 233" = light blue) should
> not appear on the map. However, the map is drawn with the first three
> colors from the fcolor list instead of the second, third and fifth
> color. All regions with the value 2 are filled with the color "215 25
> 28", all regions with the value 3 are filled with the color "253 174
> 97", and all regions with the value 5 are filled with the color "255
> 255 191".
>
> What am I doing wrong?
>
> Friedrich
*
* 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/