# That thing where you have a lot of little graphs (single-parent edition)

Yesterday I was on an author-meets-critics panel for The Triple Bind of Single-Parent Families: Resources, Employment, and Policies to Improve Well-Being, a new collection edited by Rense Nieuwenhuis and Laurie Moldonado. The book is excellent — and it’s available free under Creative Commons license.

Most of the chapters are comparative, with data from multiple countries. I like looking at the figures, especially the ones like this, which give a quick general sense and let you see anomalies and outliers. I made a couple, too, which I share below, with code.

Here’s an example, showing the proportion of new births to mothers who aren’t married, by education, for U.S. states.  For this I used the 2012-2016 combined American Community Survey file, which I got from IPUMS.org. I created an sample extract that included only women who reported having a child in the previous year, which gives me about 177,000 cases over the five years. The only other variables are state, education, and marital status. I put the raw data file on the Open Science Framework here. Code below.

My first attempt was bar graphs for each state. This is easiest because Stata lets you do graph means with the bar command (click to enlarge).

The code for this is very simple. I made a dummy variable for single, so the mean of that is the proportion single. Edcat is a four-category education variable.

gr bar (mean) single [weight=perwt], over(edcat) bar(1,color(green)) yti(“Proportion not married”) by(state)

The bar graph is easy, and good for scanning the data for weird cases or interesting stories. But maybe it isn’t ideal for presentation, because the bars run from one state to the next. Maybe little lines would be better. This takes another step, because it requires making the graph with twoway, which doesn’t want to calculate means on the fly. So I do a collapse to shrink the dataset down to just means of single by state and edcat.

collapse (mean) single psingle=single [fw=perwt], by(state edcat)

Then I use a scatter graph, with line connectors between the dots. I like this better:

You can see the overall levels (e.g., high in DC, low in Utah) as well as the different slopes (flatter in New York, steeper in South Dakota), and it’s still clear that the single-mother incidence is lowest in every state for women with BA degrees.

Here’s the code for that graph. Note the weights are now baked into the means so I don’t need them in the graph command. And to add the labels to the scatter plot you have to specify you want that. Still very simple:

gr twoway scatter single edcat , xlab(1 2 3 4, valuelabel) yti(“Proportion not married”) lcolor(green) msymbol(O) connect(l) by(state)

Sadly, I can’t figure out how to put one title and footnote on the graph, rather than a tiny title and footnote on every state graph, so I left titles out of the code and I then added them by hand in the graph editor. Boo.

Here’s the full code:

```set more off

clear
quietly infix ///
byte statefip 1-2 ///
double perwt 3-12 ///
byte marst 13-13 ///
byte fertyr 14-14 ///
byte educ 15-16 ///
int educd 17-19 ///
using "[PATHNAME]\usa_00366.dat"

/* the sample is all women who reported having a child in the previous year, FERTYR==2 */

replace perwt = perwt / 100

format perwt %10.2f

label var statefip "State (FIPS code)"
label var perwt "Person weight"
label var marst "Marital status"
label var educd "Educational attainment [detailed version]"

label define statefip_lbl 01 "Alabama"
label define statefip_lbl 04 "Arizona", add
label define statefip_lbl 05 "Arkansas", add
label define statefip_lbl 06 "California", add
label define statefip_lbl 09 "Connecticut", add
label define statefip_lbl 10 "Delaware", add
label define statefip_lbl 11 "District of Columbia", add
label define statefip_lbl 12 "Florida", add
label define statefip_lbl 13 "Georgia", add
label define statefip_lbl 15 "Hawaii", add
label define statefip_lbl 16 "Idaho", add
label define statefip_lbl 17 "Illinois", add
label define statefip_lbl 18 "Indiana", add
label define statefip_lbl 19 "Iowa", add
label define statefip_lbl 20 "Kansas", add
label define statefip_lbl 21 "Kentucky", add
label define statefip_lbl 22 "Louisiana", add
label define statefip_lbl 23 "Maine", add
label define statefip_lbl 24 "Maryland", add
label define statefip_lbl 25 "Massachusetts", add
label define statefip_lbl 26 "Michigan", add
label define statefip_lbl 27 "Minnesota", add
label define statefip_lbl 28 "Mississippi", add
label define statefip_lbl 29 "Missouri", add
label define statefip_lbl 30 "Montana", add
label define statefip_lbl 33 "New Hampshire", add
label define statefip_lbl 34 "New Jersey", add
label define statefip_lbl 35 "New Mexico", add
label define statefip_lbl 36 "New York", add
label define statefip_lbl 37 "North Carolina", add
label define statefip_lbl 38 "North Dakota", add
label define statefip_lbl 39 "Ohio", add
label define statefip_lbl 40 "Oklahoma", add
label define statefip_lbl 41 "Oregon", add
label define statefip_lbl 42 "Pennsylvania", add
label define statefip_lbl 44 "Rhode Island", add
label define statefip_lbl 45 "South Carolina", add
label define statefip_lbl 46 "South Dakota", add
label define statefip_lbl 47 "Tennessee", add
label define statefip_lbl 48 "Texas", add
label define statefip_lbl 49 "Utah", add
label define statefip_lbl 50 "Vermont", add
label define statefip_lbl 51 "Virginia", add
label define statefip_lbl 53 "Washington", add
label define statefip_lbl 54 "West Virginia", add
label define statefip_lbl 55 "Wisconsin", add
label define statefip_lbl 56 "Wyoming", add
label define statefip_lbl 61 "Maine-New Hampshire-Vermont", add
label define statefip_lbl 62 "Massachusetts-Rhode Island", add
label define statefip_lbl 64 "Maryland-Delaware", add
label define statefip_lbl 65 "Montana-Idaho-Wyoming", add
label define statefip_lbl 67 "Arizona-New Mexico", add
label define statefip_lbl 72 "Puerto Rico", add
label define statefip_lbl 97 "Military/Mil. Reservation", add
label define statefip_lbl 99 "State not identified", add
label values statefip statefip_lbl

label define educd_lbl 000 "N/A or no schooling"
label define educd_lbl 001 "N/A", add
label define educd_lbl 002 "No schooling completed", add
label define educd_lbl 011 "Nursery school, preschool", add
label define educd_lbl 012 "Kindergarten", add
label define educd_lbl 063 "Regular high school diploma", add
label define educd_lbl 064 "GED or alternative credential", add
label define educd_lbl 065 "Some college, but less than 1 year", add
label define educd_lbl 070 "1 year of college", add
label define educd_lbl 071 "1 or more years of college credit, no degree", add
label define educd_lbl 080 "2 years of college", add
label define educd_lbl 081 "Associates degree, type not specified", add
label define educd_lbl 082 "Associates degree, occupational program", add
label define educd_lbl 090 "3 years of college", add
label define educd_lbl 100 "4 years of college", add
label define educd_lbl 101 "Bachelors degree", add
label define educd_lbl 110 "5+ years of college", add
label define educd_lbl 111 "6 years of college (6+ in 1960-1970)", add
label define educd_lbl 112 "7 years of college", add
label define educd_lbl 113 "8+ years of college", add
label define educd_lbl 114 "Masters degree", add
label define educd_lbl 115 "Professional degree beyond a bachelors degree", add
label define educd_lbl 116 "Doctoral degree", add
label define educd_lbl 999 "Missing", add
label values educd educd_lbl

recode educd (0/61=1) (62/64=2) (65/90=3) (101/116=4), gen(edcat)

label define edlbl 1 "<HS"
label define edlbl 2 "HS", add
label define edlbl 3 "SC", add
label define edlbl 4 "BA+", add
label values edcat edlbl

label define marst_lbl 1 "Married, spouse present"
label define marst_lbl 2 "Married, spouse absent", add
label define marst_lbl 3 "Separated", add
label define marst_lbl 4 "Divorced", add
label define marst_lbl 5 "Widowed", add
label define marst_lbl 6 "Never married/single", add
label values marst marst_lbl

gen married = marst==1 /* this is married spouse present */
gen single=marst>3 /* this is divorced, widowed, and never married */

gr bar (mean) single [weight=perwt], over(edcat) bar(1,color(green)) yti("Proportion not married") by(state)

collapse (mean) single psingle=single [fw=perwt], by(state edcat)

gr twoway scatter single edcat , xlab(1 2 3 4, valuelabel) yti("Proportion not married") lcolor(green) msymbol(O) connect(l) by(state)```

## 5 thoughts on “That thing where you have a lot of little graphs (single-parent edition)”

1. Maik Hamjediers says:

Hey Philip,
I love your graphs and especially that you transparentlly share the code of most of the statistics in this blog!
Just as a short hint: If you want to change the “global” title or notes of twoway-graphs when using the by-option, you would have to specify the title -and note-options as suboptions of the by-option. For instance:
gr twoway scatter single edcat , xlab(1 2 3 4, valuelabel) yti(“Proportion not married”) lcolor(green) msymbol(O) connect(l) by(state, note(“Source: ACS2012-16”))
Best

Like

2. Nik says:

Hi, I don’t know if this is still helpful or if you’ve found this in the mean time, but the thing where you show lots of little graphs for comparison is a Design concept called “small multiples”. It’s detailed by Edward TUFTE in his books: