Announcement

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

  • tmap/smap USMAPS redundant lines

    Dear Statalisters,

    Although I follow the precise instructions from Maurizio Pisati (one should sort boundary files by _ID, as suggested in p. 9 from http://fmwww.bc.edu/repec/bocode/t/tmap2-UserGuide.pdf , and in http://www.stata.com/statalist/archi.../msg00715.html ), I still cannot replicate the maps from the first link above. Even though I followed the steps described in p. 10 of my link 1, I still get maps that look like the figure below.
    I tried to create my own shape file following the instructions in http://www.stata.com/support/faqs/gr...pmap-and-maps/, but from the files hosted in http://www.nws.noaa.gov/geodata/cata...l/us_state.htm, one ends up with a shapefile that contains Maryland twice!
    My third attempt was by using instead the module http://econpapers.repec.org/software...de/s448401.htm by Scott Merryman, but if one runs the .do file, after the 2bd command one gets an error (master file not sorted). Maybe the first line is what I am missing?

    Code:
    di in r "colorschemes.dta must be on the adopath" _n // I guess this line is wrong?
    use "rma_summary.dta", clear
    tmap chor lossratio , id(id) map("us_west.dta") palette(Blues) ocolor(white) osize(medium)  legtitle("Loss Ratios")
    I would appreciate your feedback.
    Click image for larger version

Name:	US map.png
Views:	1
Size:	42.1 KB
ID:	1354498
    Victor Cruz

  • #2
    This example works:

    Code:
    // Data from http://www.nws.noaa.gov/geodata/catalog/national/html/us_state.htm
    mkdir "C:\Users\Scott\Desktop\mapexample"
    cd "C:\Users\Scott\Desktop\mapexample"
    copy http://www.nws.noaa.gov/geodata/catalog/national/data/s_11au16.zip  s_11au16.zip
    unzipfile s_11au16.zip, replace 
    shp2dta using s_11au16, data("us_data")  coor("us_coordinates") /// 
     genid(id) gencentroids(c) replace
    use us_data, clear
    quietly destring FIPS, generate(fips)
    //keep contiguous US states
    drop if fips==2 | fips==15 | fips>56
    save usstates, replace
    spmap using us_coordinates, id(id)
    graph export "US map.png", as(png) replace
    Click image for larger version

Name:	US map.png
Views:	1
Size:	20.4 KB
ID:	1354512

    Comment


    • #3
      Scott Merryman thanks. However, following your (kind) command, one ends up with a usstates.dta that doesn't uniquely identify the subjects, i.e., Maryland appears twice. Accordíng to Maurizio Pisati in http://www.stata.com/support/faqs/gr...pmap-and-maps/, in order to graph a variable with smaps one needs to merge the data set that contains the variable to be graphed with the one that was created with shp2dta (usstates.dta), however this is not possible because the latter has two observations for Maryland:
      Code:
      merge m:1 fips using "C:\Users\vdcru\Desktop\mapexample\usstates"
      variable fips does not uniquely identify observations in the using data
      My solution to this is to delete one of the 2 observations of Maryland
      Code:
      drop in 52 // delete Maryland's 2nd observation
      but I guess this might be wrong because in us_coordinates.dta there is information for Marylands's two observations, indeed (_ID 56 & 57). One still gets a nice map:
      Click image for larger version

Name:	Graph.png
Views:	1
Size:	12.7 KB
ID:	1354616

      Last edited by Victor Cruz; 29 Aug 2016, 03:20.
      Victor Cruz

      Comment


      • #4
        Yes, the state of Maryland contains two distinct ids. In this example 56 and 57. If you map id == 57 you will see it is a map of the minor coastal islands and the Susquehanna river:


        Click image for larger version

Name:	Maryland2.png
Views:	1
Size:	18.1 KB
ID:	1354619
        You could drop these coastal islands or use a map with lower resolution. The Census Department has shapefiles at three different resolutions, see http://www.census.gov/geo/maps-data/...cbf_state.html


        For the example the 1:20,000,000 shapefile produces the following map of Maryland.


        Code:
        // http://www.census.gov/geo/maps-data/data/cbf/cbf_state.html
        mkdir "C:\Users\Scott\Desktop\mapexample2"
        cd "C:\Users\Scott\Desktop\mapexample2"
        copy http://www2.census.gov/geo/tiger/GENZ2015/shp/cb_2015_us_state_20m.zip  cb_2015_us_state_20m.zip
        unzipfile cb_2015_us_state_20m.zip, replace 
        shp2dta using  cb_2015_us_state_20m, data("us_data")  coor("us_coordinates") /// 
         genid(id) gencentroids(c) replace
        use us_data, clear
        quietly destring STATEFP, generate(fips)
        //keep contiguous US states
        drop if fips==2 | fips==15 | fips>56
        save usstates, replace
        spmap using us_coordinates if fips == 24, id(id)
        graph export "Maryland_20m", as(png) replace
        Click image for larger version

Name:	Maryland_20m.png
Views:	1
Size:	10.2 KB
ID:	1354620



        Comment


        • #5
          thanks a lot, Scott Merryman
          below, a graph combining the maps of Maryland, Alaska & Hawaii, from a .dta of which I deleted the second observation of Maryland.
          So I guess for my purposes, if I decide to drop the coordinates of Maryland's Islands (your suggestion #1) or use a map without them (your suggestion #2), both result in analogous graphs.

          Click image for larger version

Name:	Graph.png
Views:	1
Size:	9.2 KB
ID:	1354627
          Victor Cruz

          Comment


          • #6
            I too am having the redundant lines issue with -tmap-. Though to me, it looks more like a cubist's interpretation of the USA. I followed the instructions from the help tmap file.
            With this code:
            Code:
            tmap choropleth murder, id(id) map(us-coordinates.dta)
            I get this map: Click image for larger version

Name:	choropleth.png
Views:	2
Size:	236.6 KB
ID:	1732225
            And with this code:
            Code:
            tmap deviation murder if conterminous, x(x_coord) y(y_coord) map(Us48-Coordinates.dta) sshape(s)
            scolor(sienna) fcolor(eggshell)
            I get this map:
            Click image for larger version

Name:	choropleth 2.png
Views:	3
Size:	435.4 KB
ID:	1732224
            I did read the above thread, but I wonder if there are alternative solutions.

            Thanks in advance,
            Rich
            Attached Files

            Comment

            Working...
            X