Skip Navigation Links
Link to the last RSS article here: New Developments With R - version 2.6.2 - Ed.
Mapping And Data Representation In Stata: Part 1
By Patrick McLeod, Research and Statistical Support Services Consultant
Dealing with geographic components in social science research can take many forms. Data often have some geographic component to them (the distribution of responses to a survey or the location of nations suffering through civil war, for example). Accounting for these geographic components often takes the form of dummy coding variables or employing techniques such as geographically weighted regression. The most commonly encountered geographic component is in the display of data or the display of results. Whether your research deals in national level data, U.S. state level data, Congressional district level data or any other data that can be displayed within boundaries, maps offer an excellent way to display spatial data that are organized in ways that are visually compelling and easy for readers to comprehend.
Stata offers a user contributed package called spmap to generate maps with data as graphs. spmap will work with both Stata 9 and Stata 10. In order to use spmap, you’ll need to install spmap, shp2dta and mif2dta using Stata’s internet functionality. If this is your first time to install something via the internet from within Stata, the easiest thing to do is to type the following three commands into the command line:
and then click on the blue text items (blue text means an internet linkage, exactly like an embedded web link on a web page) to download and install these three packages within your Stata installation.
From the help file for spmap, here’s an overview of the package:
The help file for spmap is extensive; instead of replicating the whole file in this article, I suggest that as soon as you finish reading this article you install spmap and then view and/or print the help file.
The spmap package allows users to create choropleth maps (link opens a file in PDF). A choropleth map displays data values or phenomena across different regions in shades of color or different gradients. The example we’re going to work with in this article will map homicides per capita onto a map of the United States with different levels of homicides per capita displayed in different shades of red; lighter red reflects lower homicide levels while darker red reflects higher homicide levels.
Before we can get down to brass tacks in Stata, however, we need find a boundary file (a map) that is in either .shp (shapefile) or .mif (MapInfo interchange format). The best way to find one of these files is via the web; for instance, Googling “United States” shapefile or “United States shapefile” returns loads of possibilities. Per the Stata FAQ page for working with spmap, I’m going to use the U.S. shapefile from the National Weather Service’s website.
Shapefiles come from ESRI, Environmental Systems Research Institute, one of the leading firms in the field of GIS software and development. ESRI produces the widely-used ArcGIS software platform which can be found on some computers here at UNT. A shapefile is an ESRI-specific map. Shapefiles are generally easier to find than MapInfo format files. The Stata package shp2dta converts polygon shapefiles into Stata data format. Note the restriction to polygon shapefiles!
MapInfo interchange format files work with the MapInfo suite of software products. In my experience, *.mif files are not as common as shapefiles but are worth looking for if your shapefile options are limited or if you cannot find a shapefile for your particular needs. The Stata package mif2dta converts a *.mif file into a Stata dataset for processing.
At this point in the process of generating your map as a graph in Stata, you should have the following things: spmap, shp2dta, mif2dta, a shapefile format map of your intended Stata map or a MapInfo format map of your intended Stata map. In Part 2 of the article we will walk through the Stata code involved in mapping data to a map and producing a graph figure of that map.