Announcement

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

  • MAPTILE: a Stata program that makes mapping easy. Available in SSC.

    maptile makes it easy to map a variable in Stata. It is now available in the SSC, with thanks to Kit Baum.

    maptile generates choropleth maps. It divides the areas on the map into groups and shades them in increasing intensity according to the value of the variable being plotted. The map itself is drawn using geography templates, which can be downloaded here. These templates are easy to create and share.

    Check out the maptile website for further details!



    maptile is built on top of Maurizio Pisati’s spmap. spmap is an outstanding program which runs behind-the-scenes to draw each map when you run maptile. Without spmap, maptile would not exist.

    A key contribution of maptile is its very accessible syntax. As its help file states, “spmap gives the user full control over the formatting of almost every map element, thus allowing the production of highly customized maps”. When using maptile, most of these customizations are stored away in the geography template. As a result, the syntax for making highly customized maps using maptile can be very simple. Additionally, the geography templates can be easily shared and used by others.



  • #2
    maptile is updated in the SSC, with thanks to Kit Baum. If you've already installed maptile, you can update it by running adoupdate. To install it for the first time, run ssc install maptile.

    This update (v1.02) has a couple improvements, listed below. Thank you to Ashish Shenoy for prompting them!



    Minor bugfix:
    • maptile is now able to run on datasets containing multiple observations with the same geoid, as long as the geoid is a unique identifier after the if/in options are applied.

    Minor feature improvement:
    • Add a twopt() option to pass standard twoway options to spmap. This could always be done (and can still be done) using spopt(), but this was never sufficiently clear.



    Comment


    • #3
      maptile is updated once more in the SSC, with thanks to Kit Baum. If you've already installed maptile, you can update it by running adoupdate. To install it for the first time, run ssc install maptile. Check out the maptile website, and the first post in this thread for more details.

      This update (v1.04) fixes some bugs, listed below. Thank you to Derrek Grunfelder-McCrank and Jon Petkun for reporting them!

      Minor bugfix:
      • maptile can now handle RGB color values within the fcolor() option. Doing so also requires installing updated geo template files: all of the templates on the maptile website have been updated.
      This update also fixed some issues with running maptile on Stata 12, as reported and tested by Jon Petkun.

      Comment


      • #4
        This is awesome and just what I need for a project I'm currently working on! brilliant!

        Comment


        • #5
          In the past few weeks, maptile has received a number of new geo templates which can be used to create new types of maps. All are available from the maptile website:
          • Meru Bhanot submitted templates for U.S. CBSAs, MSA/CMSAs and MSA/PMSAs
          • I created a template for dartmouthatlas.org HRRs
          • Chieko Maene submitted templates for vintage 2000, 2010 and 2014 U.S. counties

          Comment


          • #6
            A geo new template is available for maptile, which creates hexagon tile maps of U.S. state data:

            Click image for larger version

Name:	statehex_noopt.png
Views:	1
Size:	466.8 KB
ID:	1360272


            The template was created by Paul Goldsmith-Pinkham, based on the design of Brian Boyer, Danny DeBelius and Alyson Hurt at NPR. The team at NPR described their design process in an NPR Visuals Team blog post.

            You can install the template (and learn more about maptile) from the maptile website.

            Comment


            • #7
              maptile is updated once more in the SSC, with thanks to Kit Baum. If you've already installed maptile, you can update it by running adoupdate. To install it for the first time, run ssc install maptile. Check out the maptile website, and the first post in this thread for more details.

              This update (v1.0.5) fixes a small bug for folks using Stata interactively on a unix-based console. Thank you to dalek2point3 for reporting this issue and wbuchanan for helping me find the solution.
              Minor bugfix:
              • maptile_geohelp can now display help files for maptile geography templates in console Stata.

              Comment


              • #8
                Michael Stepner - I'm trying to use -maptile- to map values for a subset of the national zip code level data from the website. (I know there are mentions of tutorials to create new maptile geographies in the presentation on the website, but I dont wish to write a program to make a new geographic template at this point)

                I downloaded the zip5 dataset from the maptile website. I merged a 5 digit zip code level file containing Texas housing values to the zip5 geography template (the database file) and kept only the zip codes related to Texas (_merge == 3) and then did the same for the coordinates file (via _ID, keeping only if _merge ==3) however, when I save the resulting file (in place of the full zip5 maptile geographies data) and then plot of the resulting data the map is garbled (it looks like a mis-sorted spmap, but I wonder if in merging _ID to the polygon ID in the last step I've misunderstood how those files are joined and so my selection of the polygon IDs in the coords.dta file was incorrect (?) ).

                Is there a straightforward process for using one of your national-level maptile geography files (e.g., zip code, county, etc) and restricting it to plot only one state or sub-state area (e.g., just cities in the DFW metro area) as definited by the zip codes (or counties) in the master file (or otherwise feeding it a set of zip codes or counties to include) when using the maptile command?


                Last edited by eric_a_booth; 27 Jun 2017, 19:00.
                Eric A. Booth
                Senior Research Scientist, Gibson Consulting Group

                eric.a.booth@gmail.com | http://www.eric-a-booth.com

                Comment


                • #9
                  eric_a_booth: Mapping a subset of a full geography template is a lot easier than you think! See "Example 4: Subsets of regions" under -help maptile- for a clickable walk-through of how to do it. You'll use the full geography and apply if and mapif() statements. The appropriate combination will depend on the analysis you want to display, as illustrated in Example 4.

                  Comment


                  • #10
                    Michael Stepner Thanks - this is helpful. The trick for me was adding a variable to the master dataset (the TX housing dataset in my previous example) that allowed for selection in the [if] condition and the mapif() option (I had tried each 'if' before, but not together).

                    Extending my example and questions a bit: I was able to map the subset of data however, when I use the spopt to graph the points data, it projects as a separate plot rather than overlay on the same plot. Any idea what's going on here? I cannot tell if this is due to something I'm specifying in -maptile- or if the x and y coordinates in my Texas points dataset need to be adjusted/manipulated in some way to align with the installed maptile geography dataset.
                    See the example/questions below:


                    Code:
                    **maptile subset**
                    
                    
                    **zip code info - get data & geo template 
                    
                    maptile_install using "http://files.michaelstepner.com/geo_zip5.zip", replace
                        ** zip5_coords.dta
                        ** zip5_database.dta
                        ** zip5_maptile.ado
                        ** zip5_maptile.smcl
                    copy "https://opendata.arcgis.com/datasets/059432fd0dcb4a208974c235e837c94f_0.csv?session=1319598347.1472053984;%20_gid=GA1.2.1946990559.1498653437;%20_gat=1"  "tx_schools.csv", replace public
                    
                    
                    **create master texas file:
                    insheet using "tx_schools.csv", clear
                    rename *, lower
                    drop if mi(zip)
                    sa "points.dta", replace //makes the POINTS data
                    
                    collapse (mean) gradegrp, by(zip)
                    rename zip zip5
                    destring zip5, replace
                    g state = "TX"
                    sa "tx_schools.dta", replace
                    
                    
                    
                    *maps
                    u "tx_schools.dta", clear
                    
                    maptile gradegrp, geo(zip5)  stateoutline(medium) conus 
                    maptile gradegrp, geo(zip5) mapif(state=="TX")
                    maptile gradegrp if state=="TX", geo(zip5) mapif(state=="TX") fcolor(Blues) nq(4)
                    
                    
                    
                    **fails
                    maptile gradegrp if state=="TX", geo(zip5) mapif(state=="TX") fcolor(Blues) nq(4) ///
                    spopt(point(data("points.dta") xcoord(x)  ycoord(y) size(tiny)  fcolor(gs8)))  
                    
                    //by the way, if I turn on this option stateoutline(medium) for the last graph, all the outlines for the US are activated (ignoring the [if] condition) is there a way to have it just outline and show TX with this option?



                    Eric A. Booth
                    Senior Research Scientist, Gibson Consulting Group

                    eric.a.booth@gmail.com | http://www.eric-a-booth.com

                    Comment


                    • #11
                      eric_a_booth, good questions:

                      when I use the spopt to graph the points data, it projects as a separate plot rather than overlay on the same plot
                      The issue with the points appearing in the wrong place is due to the points and the maptile geography being in a different projection (projection being a mapping from latitude,longitude to x,y). You can refer to this do-file to see the projection used by the zip5 geo (also included in the source files for the zip5 geo).

                      if I turn on this option stateoutline(medium) for the last graph, all the outlines for the US are activated (ignoring the [if] condition) is there a way to have it just outline and show TX with this option?
                      It's impossible for stateoutline() to respond to if conditions because the scope is different. But you can add a state outline for Texas using spopt(polygon(...)), which is what maptile is doing automatically when stateoutline() is specified: see line 30 here.

                      Comment


                      • #12
                        [QUOTE=Michael Stepner;n1399658]eric_a_booth, good questions:


                        The issue with the points appearing in the wrong place is due to the points and the maptile geography being in a different projection (projection being a mapping from latitude,longitude to x,y). You can refer to this do-file to see the projection used by the zip5 geo (also included in the source files for the zip5 geo).

                        Thanks for the responses. I've got the outlines working now.

                        Sorry, I'm a mapping novice -- do you know a way to convert the projection of the maptile zip5 geo or the Tx data from within Stata? Or is the solution to find a zip code geography file that is the same coordinate system as my Texas file and manually create that geography template? (I see you've noted the maptile zip5 coordinate system is WGS1984, but I don't see any mention of the type of coordinate system for my Texas data, so I'm not sure what I'm looking for).

                        Eric A. Booth
                        Senior Research Scientist, Gibson Consulting Group

                        eric.a.booth@gmail.com | http://www.eric-a-booth.com

                        Comment


                        • #13
                          do you know a way to convert the projection of the maptile zip5 geo or the Tx data from within Stata?
                          eric_a_booth: the projection of the maptile zip5 geo is changed within Stata. The reshape_us.do file I linked to in my previous post is the Stata code that projects from lat-long coordinates into the x-y coordinates used by the zip5 geo. Your texas state outline shapefile is almost certainly in lat-log when you import it using shp2dta. You could modify the reshape_us.do file to project it into the same x-y coordinates as the zip5 geo. Or you could use the maptile state geo, select texas from the coords file, and use that subsettted coords file with spopt(polygon(...)).

                          For more details about applying projections in Stata, I highly recommend Robert Picard's program -geo2xy-.

                          Comment


                          • #14
                            Michael Stepner - this is helpful, thank you for the detailed response. I'll look into these solutions to see which one works best.
                            Eric A. Booth
                            Senior Research Scientist, Gibson Consulting Group

                            eric.a.booth@gmail.com | http://www.eric-a-booth.com

                            Comment


                            • #15
                              Michael Stepner I have a simple mapping task, but can't seem to "crop" the graph in a way to get only the zip codes in which I have data for. I have a simple table with info:
                              Zip5 Count
                              77433 57
                              77429 357
                              77084 69
                              77484 2
                              The zip codes I have are zip codes in Harris County, TX. The count is the number of stray dog reports for that area. I want to produce a prevalence map like this: (a fellow student was able to make this using the same data that I have, but I don't know how she did it)

                              Click image for larger version

Name:	Stray Graph.PNG
Views:	1
Size:	162.8 KB
ID:	1401283



                              BUT, this is the map I keep getting:

                              Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	65.6 KB
ID:	1401282

                              I don't want the entire US map! How can I get rid of the zip codes with no data? I've been searching for HOURS trying to figure this out. I know it can be done, I just can't seem to figure it out.

                              This is what I have looked at that is similar in what I am trying to do, but instead of states in a region, I want zip codes within a County:

                              "Suppose we want to focus on the Northeast. Using an if statement controls
                              what data are used.
                              . maptile medage if region==1, geo(state)

                              All the observations outside the Northeast were treated as if they were
                              missing. Only the Northeastern data was used to compute the quantiles.

                              Now let's zoom in on the Northeast. Using mapif() controls what data are
                              shown.
                              . maptile medage, geo(state) mapif(region==1)

                              Only the Northeast is shown on the map. But all observations were used to
                              compute the quantiles.

                              To generate a map of only Northeastern data, we need to combine an if
                              statement with mapif()
                              . maptile medage if region==1, geo(state) mapif(region==1)

                              This map shows the Northeast, categorized using the quantiles of the
                              Northeastern states."



                              Please help. Thanks,

                              --DT
                              Last edited by Danielle Teran; 10 Jul 2017, 15:03.

                              Comment

                              Working...
                              X