Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • spmap of a dummy variable

    Hi, I would like to see a map of continental US counties satisfying a condition. This doesn't seem to fit into the choropleth framework, which wants to show gradations along some dimension across the sample. I simply want to have certain counties colored, and the rest be white (outlined in black). I have tried spmap, but spmap wants to color all (or most of) the counties and my information does indeed get lost. Now, I admit that of the > 3k U.S. counties, I want to see only ~ 120 of them colored, so they may get lost in the scope of information presented in a map of the (continental) U.S. A bit more detail is that my 120 counties of interest are located in only 18 states (spread widely geographically). Any suggestions on what to try would be greatly appreciated.

  • #2
    Plotting only one color should not be problem (note, using -geo2xy- from ssc):

    Code:
    copy https://www2.census.gov/geo/tiger/GENZ2018/shp/cb_2018_us_county_20m.zip uscounty.zip, replace
    copy https://www2.census.gov/geo/tiger/GENZ2018/shp/cb_2018_us_state_20m.zip usstate.zip, replace
    
    unzipfile uscounty.zip, replace
    unzipfile usstate.zip, replace
    
    spshape2dta    cb_2018_us_state_20m, saving(usstate) replace
    spshape2dta    cb_2018_us_county_20m, saving(uscounty) replace
    
    use uscounty_shp,clear
    geo2xy _Y _X, replace  proj(albers, 6378137 298.257223563 29.5 45.5 0 -95.837867)
    save , replace
    
    //Drop AK, HI, and PR from state borders 
    use usstate,clear
    drop if inlist(STATEFP, "02", "15", "72")
    keep _ID
    merge 1:m _ID using usstate_shp
    keep if _m == 3
    drop _merge
    sort _ID shape_order
    save usstate_shp,replace
    
    use usstate_shp,clear
    geo2xy _Y _X, replace  proj(albers, 6378137 298.257223563 29.5 45.5 0 -95.837867)
    save, replace
    
    use uscounty.dta , clear
    drop if inlist(STATEFP, "02", "15", "72")
    gen x = 1  if runiform() < .05
     
    spmap x using uscounty_shp, id(_ID)  ndsize(0.02 ..)  osize(0.02 ..) /// 
        fcolor("68 1 84") polygon(data(usstate_shp) osize(.2 ..))
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	473.7 KB
ID:	1681840

    Comment


    • #3
      Thanks so much Scott. This really helped.

      Comment

      Working...
      X