Announcement

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

  • SPMAP and Stata 14.1 compatibility?

    Is there an issue with SPMAP in Stata 14.1? I have used SPMAP frequently in earlier versions of stata without any trouble - but this evening, wanting to update an old graph, I ran *exactly* the same spmap command as previously worked, only to find an error message

    invalid 'Moultrie'
    r(198)


    A truly bizarre error, as somewhere my surname is being passed across as a variable / macro????! The only thing that has changed is a new version of Stata.



    After opening the UNfertdata.dta file (which has the appropriate id for the worldcoord.dta file - it used to work!) - and using the command line

    spmap TFR1970 using "E:\My Documents\Applications\ShapeFiles\worldcoord.dta", id(id) fcolor(Rainbow) clmethod(custom) clbreaks(1 2 3 4 5 6 7 8) legcount

    (Which also used to work).

    Most grateful for any clues/hints - the two necessary files are attached should anyone want to attempt to reproduce the error....
    Attached Files
    Last edited by Tom Moultrie; 25 Jan 2016, 16:38.

  • #2
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	20.2 KB
ID:	1324187

    After downloading your files I ran the following commands in Stata 14.1:

    Code:
    use "C:\Users\rwilliam\Downloads\UNfertdata.dta" 
    spmap TFR1970 using "C:\Users\rwilliam\Downloads\worldcoord.dta", id(id) fcolor(Rainbow) clmethod(custom) clbreaks(1 2 3 4 5 6 7 8) legcount
    No error messages and I got the graphic above. Is that correct? If so, I suggest you make sure your Stata and copy of spmap are up to date. If I did it wrong, let me know what the commands should be, as this is the first time I have used spmap.
    -------------------------------------------
    Richard Williams, Notre Dame Dept of Sociology
    StataNow Version: 19.5 MP (2 processor)

    EMAIL: [email protected]
    WWW: https://www3.nd.edu/~rwilliam

    Comment


    • #3
      Tom,
      1) change your current folder to something like C:\temp\ before running spmap (this may or may not help);
      2) run your commands with set trace on and you will see the erroneous line.

      I suspect that Richard can run the code since his user name is rwilliam, and you can't because your user name is something like "tom moultrie". Hence due to mishandling the quotes somewhere the filename gets broken down into several names. Like the following illustrates:

      Click image for larger version

Name:	198.png
Views:	1
Size:	2.8 KB
ID:	1324192


      Best, Sergiy Radyakin

      Comment


      • #4
        Thanks Sergiy - indeed it was a changed user account name on the laptop with a space in it. Let others take note!

        Comment


        • #5
          dear Richard Williams when i ran these commands
          (use "C:\Users\rwilliam\Downloads\UNfertdata.dta"
          spmap TFR1970 using "C:\Users\rwilliam\Downloads\worldcoord.dta", id(id) fcolor(Rainbow) clmethod(custom) clbreaks(1 2 3 4 5 6 7 8) legcount )
          it doesn't show names of each country on the map, would you please give me some information how to solve this problem?

          Comment


          • #6
            Hi Fahim. I don't know anything about the program -- I just tried it to see if I got errors too. Perhaps someone else can help you.
            -------------------------------------------
            Richard Williams, Notre Dame Dept of Sociology
            StataNow Version: 19.5 MP (2 processor)

            EMAIL: [email protected]
            WWW: https://www3.nd.edu/~rwilliam

            Comment


            • #7
              Fahim: It seems unlikely that you can use the files on Richard's C: drive, so you need to give more details on the exact commands you used, and the dataset.

              Comment


              • #8
                A suggestion for Tom Moultrie: I think the map would look nicer without Antarctica. You can exclude Antarctica by adding if id!=13 to the command.
                Code:
                spmap TFR1970 using "worldcoord.dta" if id!=13, id(id) fcolor(Rainbow) clmethod(custom) clbreaks(1 2 3 4 5 6 7 8) legcount

                Comment


                • #9
                  You can make an even prettier map if you use geo2xy (from SSC) to convert the shapefile's coordinates to the same projection used in Google Maps (otherwise, since spmap does not do map projections, you are plotting raw lat/lon coordinates). You can install geo2xy by typing in Stata's Command window:

                  Code:
                  ssc install geo2xy
                  To create a world map without Antartica as Friedrich suggested:

                  Code:
                  use "worldcoord.dta", clear
                  
                  * fix overflow errors in the shapefile data
                  replace _X = -180 if _X < -180
                  replace _X = 180 if _X > 180
                  
                  * convert coordinates using a Google Map projection using -geo2xy- (from SSC)
                  geo2xy _Y _X, replace
                  save "worldcoord_google.dta", replace
                  
                  * the map without Antartica
                  use "UNfertdata.dta"
                  spmap TFR1970 using "worldcoord_google.dta" if id!=13, id(id) fcolor(Rainbow) clmethod(custom) clbreaks(1 2 3 4 5 6 7 8) legcount

                  Comment


                  • #10
                    Robert Picard, I am unable to create usable maps with three of the seven projections mentioned in help geo2xy:
                    • Mercator projection - Spherical model
                    • Equidistant Cylindrical projection - Spherical model
                    • Albers Equal-Area Conic Projection - Spherical model
                    I modified your code in post #9 as shown below at the example of the Equidistant Cylindrical projection.

                    The first problem is that the spmap command without the ysize() option leads to an error. For the projections not listed above, the ysize() option is not required.
                    Code:
                    use "worldcoord.dta", clear
                    
                    * fix overflow errors in the shapefile data
                    replace _X = -180 if _X < -180
                    replace _X = 180 if _X > 180
                    
                    * convert coordinates using -geo2xy-
                    geo2xy _Y _X, projection(equidistant_cylindrical) replace
                    save "worldcoord_equidistant_cylindrical.dta", replace
                    
                    * create map
                    use "UNfertdata.dta"
                    spmap TFR1970 using "worldcoord_equidistant_cylindrical.dta" if id!=13, ///
                      id(id) fcolor(Rainbow) clmethod(custom) clbreaks(1 2 3 4 5 6 7 8) legcount
                    
                    ysize must be between 1.000 and 20.000
                    r(198);
                    When I add the ysize() option, I can create a map but it is far too small and doesn't fill the graph area.
                    Code:
                    spmap TFR1970 using "worldcoord_equidistant_cylindrical.dta" if id!=13, ///
                      id(id) fcolor(Rainbow) clmethod(custom) clbreaks(1 2 3 4 5 6 7 8) legcount ysize(10)
                    graph export "tiny map.png", width(600) replace
                    Click image for larger version

Name:	tiny map.png
Views:	1
Size:	6.5 KB
ID:	1324439


                    Please note the large empty space around the map, which disappears behind the legend. I get the same result for all three projections listed above.

                    What am I doing wrong?

                    Comment


                    • #11
                      Sorry my bad. I kind of rushed to prepare my example and introduced an error while correcting longitudes that were not inrange(-180,180). The error does not show when using the default projection. Here's the corrected code

                      Code:
                      use "worldcoord.dta", clear
                      
                      * fix overflow errors in the shapefile data
                      replace _X = -180 if _X < -180
                      replace _X = 180 if _X > 180 & !mi(_X)
                      
                      * convert coordinates using a Google Map projection using -geo2xy- (from SSC)
                      geo2xy _Y _X, replace
                      save "worldcoord_google.dta", replace
                      
                      * the map without Antartica
                      use "UNfertdata.dta"
                      spmap TFR1970 using "worldcoord_google.dta" if id!=13, id(id) fcolor(Rainbow) clmethod(custom) clbreaks(1 2 3 4 5 6 7 8) legcount
                      
                      graph export "world.png", width(600) replace
                      And here is the world according to Google Maps:

                      Click image for larger version

Name:	world.png
Views:	1
Size:	308.0 KB
ID:	1324462


                      When selecting other projections, it's important to remember that they often have a "point of view" which can be specified using projection parameters. If none are specified, then geo2xy will use some values that appear sensible given the overall set of points in the shapefile. For the equidistant_cylindrical projection, this means that if you are going to skip Antartica, you must also skip it when calculating the projection. For example:

                      Code:
                      use "worldcoord.dta", clear
                      
                      * fix overflow errors in the shapefile data
                      replace _X = -180 if _X < -180
                      replace _X = 180 if _X > 180 & !mi(_X)
                      
                      * convert coordinates using -geo2xy-
                      geo2xy _Y _X if _ID!=13, projection(equidistant_cylindrical) replace
                      save "worldcoord_equidistant_cylindrical.dta", replace
                      
                      * create map
                      use "UNfertdata.dta"
                      spmap TFR1970 using "worldcoord_equidistant_cylindrical.dta" if id!=13, ///
                        id(id) fcolor(Rainbow) clmethod(custom) clbreaks(1 2 3 4 5 6 7 8) legcount
                      
                      graph export "world2.png", width(600) replace
                      which looks like:

                      Click image for larger version

Name:	world2.png
Views:	1
Size:	196.3 KB
ID:	1324463



                      Some projections are just not appropriate to create maps that span the complete surface of the earth. Here's what an albers will look like with default parameters:

                      Code:
                      use "worldcoord.dta", clear
                      
                      * fix overflow errors in the shapefile data
                      replace _X = -180 if _X < -180
                      replace _X = 180 if _X > 180 & !mi(_X)
                      
                      * convert coordinates using -geo2xy-
                      geo2xy _Y _X if _ID!=13, projection(albers) replace
                      save "worldcoord_albers.dta", replace
                      
                      * create map
                      use "UNfertdata.dta"
                      spmap TFR1970 using "worldcoord_albers" if id!=13, ///
                        id(id) fcolor(Rainbow) clmethod(custom) clbreaks(1 2 3 4 5 6 7 8) legcount
                      
                      graph export "world2albers.png", width(600) replace
                      Click image for larger version

Name:	world2albers.png
Views:	1
Size:	235.8 KB
ID:	1324464

                      Comment


                      • #12
                        All crazy, but definitely +1!

                        Comment


                        • #13
                          As an expat from Canada, I should perhaps like the aggrandized representation that Google Maps creates:

                          Code:
                          use "worldcoord.dta", clear
                          
                          * fix overflow errors in the shapefile data
                          replace _X = -180 if _X < -180
                          replace _X = 180 if _X > 180 & !mi(_X)
                          
                          * convert coordinates using -geo2xy-
                          geo2xy _Y _X if _ID == 40, replace
                          save "worldcoord_canada2.dta", replace
                          
                          * create map
                          use "UNfertdata.dta"
                          spmap TFR1970 using "worldcoord_canada2" if id==40, ///
                            id(id) fcolor(Rainbow) clmethod(custom) clbreaks(1 2 3 4 5 6 7 8) legcount
                          
                          graph export "worldcoord_canada2.png", width(600) replace
                          which looks like

                          Click image for larger version

Name:	worldcoord_canada2.png
Views:	1
Size:	335.2 KB
ID:	1324468
                          But the following is in many ways a better representation

                          Code:
                          use "worldcoord.dta", clear
                          
                          * fix overflow errors in the shapefile data
                          replace _X = -180 if _X < -180
                          replace _X = 180 if _X > 180 & !mi(_X)
                          
                          * convert coordinates using -geo2xy-
                          geo2xy _Y _X if _ID == 40, projection(albers) replace
                          save "worldcoord_canada.dta", replace
                          
                          * create map
                          use "UNfertdata.dta"
                          spmap TFR1970 using "worldcoord_canada" if id==40, ///
                            id(id) fcolor(Rainbow) clmethod(custom) clbreaks(1 2 3 4 5 6 7 8) legcount
                          
                          graph export "worldcoord_canada.png", width(600) replace
                          Click image for larger version

Name:	worldcoord_canada.png
Views:	1
Size:	234.1 KB
ID:	1324469

                          Comment


                          • #14
                            Is there any way to create each country's map with the provinces too? Robert Picard

                            Comment


                            • #15
                              Robert, thank you for the revised code.

                              When I draw world maps (with Antarctica) with the two versions of the Albers projection listed in help geo2xy, the results don't look as I had expected.

                              Map 1: Albers Equal-Area Conic Projection - Ellipsoid model
                              Code:
                              use "worldcoord.dta", clear
                              
                              * fix overflow errors in the shapefile data
                              replace _X = -180 if _X < -180
                              replace _X = 180 if _X > 180 & !mi(_X)
                              
                              * convert coordinates using -geo2xy-
                              geo2xy _Y _X, projection(albers) replace
                              save "worldcoord_albers.dta", replace
                              
                              * create map
                              use "UNfertdata.dta"
                              spmap TFR1970 using "worldcoord_albers", ///
                                id(id) fcolor(Rainbow) clmethod(custom) clbreaks(1 2 3 4 5 6 7 8) legcount
                              
                              graph export "Albers 1 map.png", width(600) replace
                              Click image for larger version

Name:	Albers 1 map.png
Views:	1
Size:	61.5 KB
ID:	1324549


                              Map 2: Albers Equal-Area Conic Projection - Spherical model
                              Code:
                              use "worldcoord.dta", clear
                              
                              * fix overflow errors in the shapefile data
                              replace _X = -180 if _X < -180
                              replace _X = 180 if _X > 180 & !mi(_X)
                              
                              * convert coordinates using -geo2xy-
                              geo2xy _Y _X, projection(albers_sphere) replace
                              save "worldcoord_albers_sphere.dta", replace
                              
                              * create map
                              use "UNfertdata.dta"
                              spmap TFR1970 using "worldcoord_albers_sphere", ///
                                id(id) fcolor(Rainbow) clmethod(custom) clbreaks(1 2 3 4 5 6 7 8) legcount
                              
                              graph export "Albers 2 map.png", width(600) replace
                              Click image for larger version

Name:	Albers 2 map.png
Views:	1
Size:	61.3 KB
ID:	1324550


                              These maps don't look like the map in the Wikipedia entry "Albers projection" that is cited at help geo2xy_proj##albers and help geo2xy_proj##albers_sphere. The description in the geo2xy help file also doesn't match the maps created with Stata. Quote from help geo2xy_proj##albers:

                              This projection transfers locations on the spheroid to a cone that intersects the spheroid at the two standard parallels. The parallels are circles whose center is the intersection of the meridians.
                              Image from Wikipedia entry "Albers projection":
                              Click image for larger version

Name:	Albers_projection_SW.png
Views:	1
Size:	212.5 KB
ID:	1324551

                              Last edited by Friedrich Huebler; 28 Jan 2016, 08:17.

                              Comment

                              Working...
                              X