[Stata] How to create the bivariate map: bimap package

In the previous post, we learned how easy it is to map a map of the United States using maptile. In this post, I will introduce how to draw a bivariate map using the bimap command, which was recently (September 2022) developed by Dr. Asjad Naqvi. This package translates multiple lines of codes using geo2xy package into simple code (like maptile did, which translates multiple lines of codes using spmap command into simple code). Here is the example map produced by using bimap package.

Baum et al. (2022) Drivers of COVID-19 waves in U.S. counties, 2020–2022

The how-to-guide for bimap is quite well-explained in the Github repository, bimap v1.51 (Github), so you can refer to it. Here is my summary of doing it with ACS variables (using getcensus package).

Step 1: Install the package

Stata
ssc install bimap, replace

// install the packages to run the command 
ssc install spmap, replace 
ssc install palettes, replace
ssc install colrspace, replace
ssc install schemepack, replace

Step 2: Prepare the dataset that you would love to create the bivariate maps

Before we start, it is recommended to set up the scheme with a white background.

Stata
set scheme white_tableau

Then, please prepare the dataset with fips codes (state, county, or any other geographic unit of your interest).

Step 3: Prepare the base map

Then, you need to prepare the base map. You can download the cleaned dta file for the base map of the US county and state in Dr. Naqvi’s repository: https://github.com/asjadnaqvi/stata-bimap/tree/main/GIS. Please download the files for the geographic unit you are interested in and then put them in the same working directory you are working on.

For other maps, you could create your one using clipgeo or shp2dta package.

Step 4: Merge your dataset with base map

The next step is to merge your dataset with the base maps.

Stata
use usa_state, clear
destring _all, replace

rename STATEFP statefips // make the variable name same for both your dataset and base map 
merge 1:1 statefips using "ACS bimapping.dta" // put the dataset you want to draw the bimap 
keep if _m==3
drop _m

Step 5: Draw the bivariate maps

Now you are ready to create the bimap! Here are some options available:

  • cut: cut(pctile) for terciles, cut(equal) for equal intervals, or cut(custom) for custom cut-offs.
    • cut(custom) is specified, then either cutx(), or cuty(), or both need to be defined.
  • palette: pinkgreen, bluered, greenblue, purpleyellow, yellowblue, orangeblue, brew1, brew2, brew3, census, rgb, viridis, gscale. You can see the example in the Github of the developer.
  • note: you can put the note if you have one
  • texty and textx: you can put the customized name of x and y variables.
  • texts and textlabs: You can change the size of the text for the variable name (texts) and label (textlabs).
  • values: If you put this option, the map will display the cut-off values on the legend axes.
  • count or percent: the map will display either the count or percent of categories in each box in the map legend.
  • ocolor: Outline color of polygons with data.
  • osize: Line width of polygons.

Here is the sample code and map 🙂 I have downloaded the old-age dependency rate and child dependency rate from 2021 ACS (see this post if you are interested in downloading ACS using Stata).

Stata
bimap polddepnd pchilddepnd using usa_state_shp_clean, cut(pctile)  palette(orangeblue)    ///
		 note("Data from ACS 2017-2021 5-year estimates") ///	
		 texty("Old age dependency rate") textx("Child dependency rate") texts(2.5) textlabs(3) values count  ///
		 ocolor() osize(0.2) ///
		 polygon(data("usa_state_shp_clean") ocolor(black) osize(0.2)) 
  • February 10, 2023