Announcement

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

  • problem using spmap with US States map

    Hello everyone,

    I wanted to plot a very basic map, namely the US map with states boundaries. Here is the code I am using:


    cd "some directory path"

    shp2dta using s_16de14, database(us_states_db) coordinates(us_states_crds) genid(id)

    use "us_states_db.dta", clear

    spmap using "us_states_crds.dta", id(id)



    This does not work on my computer: there is no error message but I waited for several minutes without having an output so that I stopped the command. On the other hand I have been able to run much more complex maps fairly quick without any trouble. What is more, the coordinates are expressed in the same unit in both files. Is there something wrong with my code?

    Thanks in advance,

    Yannick Guyonvarch

  • #2
    After the files are downloaded and unzipped from http://www.census.gov/geo/maps-data/data/cbf/cbf_state.html this works fine:


    Code:
    clear*
    cd "C:\Users\Scott\Desktop\tmp\cb_2015_us_state_500k"
    shp2dta using cb_2015_us_state_500k, database(state) ///
        coordinates(statexy) genid(id) gencentroids(c) replace
    use state,clear
    quietly destring STATEFP, generate(st)
    //keep contiguous US
    drop if st==2 | st==15 | st>56
    spmap using statexy, id(id)

    Comment


    • #3
      Also, let me point out that if you are making a map using geographic coordinates (lat/lon), you should first project them to (x,y) before calling spmap. You can use geo2xy (from SSC) to do that. See some examples here and a US map example here.

      Comment


      • #4
        Thanks a lot it definitely works. I cannot figure out what was the problem with my initial example. I won't forget to project geographic coordinates from now on.

        Comment

        Working...
        X