Announcement

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

  • How to create State outlines on a county level map

    I have a county level map of 8 states. I wanted to add a darker border around each state, so it's more visually appealing. I have the county ID and state fip but wasn't sure whether it is possible or not. Thanks!

  • #2
    Liam Marrinan You need shapefiles for both the counties and the states. Below is an example:

    Code:
    copy "https://www2.census.gov/geo/tiger/GENZ2022/shp/cb_2022_us_state_5m.zip" us_states.zip, replace
    copy "https://www2.census.gov/geo/tiger/GENZ2022/shp/cb_2022_us_county_5m.zip" us_counties.zip , replace
    
    unzipfile us_counties.zip , replace
    unzipfile us_states.zip , replace
    
    spshape2dta cb_2022_us_county_5m, saving(counties) replace
    spshape2dta cb_2022_us_state_5m, saving(states) replace
    
    use counties_shp,clear
    geo2xy _Y _X, proj (albers) replace 
    use counties
    geo2xy _CY _CX, proj (albers) replace 
    use states_shp
    geo2xy _Y _X, proj (albers) replace 
    use states
    geo2xy _CY _CX, proj (albers) replace 
    
    use counties,clear
    keep if inlist(STATEFP, "16", "41","53")
    save nw_counties,replace
    merge 1:m _ID using counties_shp.dta 
    sort _ID shape_order
    keep if _m == 3
    drop _m rec_header
    save nw_counties_shp, replace
    
    use states,clear
    keep if inlist(STATEFP, "16", "41","53")
    save nw_states,replace
    merge 1:m _ID using states_shp.dta 
    keep if _m == 3
    sort _ID shape_order
    keep if _m == 3
    drop _m rec_header
    save nw_states_shp,replace
    
    use nw_counties,clear
    gen awater = AWATER/100000
    format awater %9.2f
    spmap awater  using nw_counties_shp , id(_ID)  legend(pos(2)) osize(.05 ..) /// 
         fcolor(Blues) cln(7)  /// 
        polygon(data(nw_states_shp) ocolor(black) osize(.5))
    Click image for larger version

Name:	map2.png
Views:	1
Size:	188.6 KB
ID:	1721438

    Comment

    Working...
    X