Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: adding US state outlines using SPMAP


From   "Scott Merryman" <[email protected]>
To   <[email protected]>
Subject   st: RE: adding US state outlines using SPMAP
Date   Mon, 12 Mar 2007 15:31:06 -0500

As already mentioned, the files are in different coordinate systems.
However you can use the US Census state files
(http://www.census.gov/geo/www/cob/st2000.html) - they will have the same
coordinate system as the metropolitan areas.

The code below will produce the following graph:

http://docs.google.com/Doc?id=dcpv7s6q_8drqqgk


Scott

clear
//From http://www.census.gov/geo/www/cob/mmsa2003.html

cd "C:\Documents and Settings\Scott_2\Desktop\foo"
shp2dta using cb99_03b.shp, database(usdatabase2) ///
  coordinates(uscoordinates2) genid(id) replace 

use usdatabase2 

gen x = uniform()
rename CBSA cbsa
keep cbsa id x
sort cbsa
save, replace

insheet using "cb99_03ba.dat",clear
egen index2 = fill(1 2 3 4 5  1 2 3 4 5 ) 
egen index = seq(), block(5) 
reshape wide v1, i(index)  j(index2) 
compress 
drop v11 
rename v12 cbsa 
rename v13 cbsa_name 
rename v14 type 
rename v15 geocode 
gen state = substr(cbsa_name,-2, 2) 
gen type2 = "micro" if type == "2"
replace type2 = "metro" if type =="1"
drop if cbsa==" "
duplicates drop cbsa cbsa_name type, force 
sort cbsa 
save "cbsa.dta", replace 

merge cbsa using usdatabase2.dta 
tab _m 
drop index _m 
sort id 
mark conterminous if state != "HI" & state != "AK" & state != "PR"
save, replace

//Download from http://www.census.gov/geo/www/cob/st2000.html
shp2dta using st99_d00.shp, database(usstate_names)  coordinates(usstates)
genid(_ID) replace
use usstates,clear
gen order = _n
merge _ID using usstate_names
drop _m
sort order
sort _ID
save, replace
use cbsa

spmap x if conterminous & type2 == "metro" using "uscoordinates2" , ///
   id(id) ndfc(white) fc(Blues)  ocolor(gs12 ..) /// 
   polygon(select(drop if STATE =="02" | STATE =="15" | STATE =="72") ///  
   data("usstates.dta" ) )
      




> -----Original Message-----
> From: [email protected] [mailto:owner-
> [email protected]] On Behalf Of Julie Susan Darnell
> Sent: Saturday, March 10, 2007 6:41 PM
> To: [email protected]
> Subject: st: adding US state outlines using SPMAP
> 
> I attempted to execute the syntax kindly offered by Maurizio
> Pisati, but the graph that resulted showed ONLY the outlines
> of the states but with the correct legend (showing the custom
> breaks 0 1 2 3 4 32 and selected color palette). It did not
> display within each state outline the shaded cbsa/metro
> areas.
> 
> use uscoordinates2
> sort _ID
> save uscoordinates2, replace
> use usdatabase3
> delimit;
> spmap numberoffreeclinics if conterminous & type2=="metro"
> using "uscoordinates2",
> id(id) ndfc(white) fc(Blues) ocolor(gs12 ..) clmethod(custom)
> clbreaks (0 1 2 3 4 32)
> polygon(data(us-stateoutline.dta));
> 
> Note: uscoordinates2 is the base map with the x and y
> coordinates for the cbsa metropolitan areas and us-
> stateoutline is the base map with x and y coordinates for the
> 48 contiguous states. usdatabase3 contains the id,
> numberoffreeclinics, type2, and conterminous variables.
> 
> Also (I'm not sure if this is relevant), the graphs that are
> produced have very different shapes. The map of cbsa/metro
> areas is stretched out and takes up the entire graph area and
> the map of the US states is small and is positioned in the
> upper lefthand corner. The US state map does not include
> Alaska or Hawaii.
> 
> Any suggestions would be greatly appreciated.
> 
> Thank you,
> Julie Darnell
> 
> *
> *   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/


*
*   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