Latest unemployment-rate numbers

Here is the latest unemployment rate from the Employment Situation:

library(tidyquant)
library(ggplot2)
library(ggthemes)

ur <- tq_get("UNRATE", get = "economic.data", from = "2010-01-01")
ur <- ur %>% 
  mutate(series = "Unemployment rate")
last_date <- max(ur$date)
last_lvl <- ur$price[[which(ur$date == max(ur$date))]]
ggplot(data = ur) +
  geom_line(mapping = aes(x = date, y = price, color = series)) +
  xlab("") + ylab("Percent") +
  guides(color = FALSE) + ggtitle("Civilian unemployment rate") +
  annotate("text", x = last_date, y = 6.5, label = paste0(last_lvl), color = "white") +
  annotate("segment", 
           x = last_date, xend = last_date, 
           y = last_lvl, yend = 6.25, 
           color = "white") +
  theme_hc(bgcolor = "darkunica") 

A just-for-fun example using R

Professor House discussed several key time series in macroeconomics on the first day of class. This handout discusses how to access and manipulate those series in R, focusing on the Employment Situation Summary published by the Bureau of Labor Statistics.

It is important to know that doing R in ECON 402 is just for fun and has nothing to do officially with the class. That said, however, data visualization is increasingly part of everyday life: The NY Times increasingly features data visualizations on its website; “advanced metrics” is taking over sports; the Nightly Business Report on Detroit Public TV always features charts.

Or let me put it a different way: I was a GSI for ECON 401 and I would be shocked if the differences between Marshalian and Hicksian demand came up in a job interview; on the other hand, I would wager that most entry-level jobs in economics deal directly with data manipulation.1

I was actually in charge of the data work for Professor House’s handbook chapter on macroeconomics. Getting asked to write a handbook chapter is a huge, huge honor—for the author, not the person doing the data work—and when I would tell Professor House that I was “assistant professor” he would yell back: “NO!!!! You are assistant to the professor.”

Getting R up and running

An introduction to R is beyond the scope of this presentation. On the off chance that someone is super interested in R, just let me know and we’ll get you going.

I had no problem installing a working copy of R from the website for The R Project for Statistical Computing, which you can navigate to here. Perhaps the easiest way to interact with R code is through RStudio. You can get a copy of RStudio here. Again, I had no problems installing R and using RStudio.

Once in RStudio you can use the “Session” dropdown menu to set the working directory, which should be where you save the code that you write to go along with this handout. More on this below.

You can install packages using install.packages.

A site that has been mentioned on R-bloggers, an aggregator of R blogs, that may be useful in getting R up and running is found here.

R setup

It’s a good idea to begin by restarting the R session. This can be done, for example, in RStudio by issuing the command Ctrl+Shift+F10. Next we want to load libraries that R uses. The tidyverse package was written by R guru Hadley Wickham. The tidyquant package allows us to access data from FRED. Most macroeconomic time series are available in the FRED database.

library(tidyverse)
library(tidyquant)
library(ggplot2)
library(emo)

Retrieving data from FRED

Here’s R code that retrives data from the FRED database. It gets the series UNRATE.

ur <- tq_get("UNRATE", get = "economic.data", from = "1940-01-01")
head(ur)
## # A tibble: 6 x 2
##   date       price
##   <date>     <dbl>
## 1 1948-01-01   3.4
## 2 1948-02-01   3.8
## 3 1948-03-01   4  
## 4 1948-04-01   3.9
## 5 1948-05-01   3.5
## 6 1948-06-01   3.6
tail(ur)
## # A tibble: 6 x 2
##   date       price
##   <date>     <dbl>
## 1 2017-11-01   4.1
## 2 2017-12-01   4.1
## 3 2018-01-01   4.1
## 4 2018-02-01   4.1
## 5 2018-03-01   4.1
## 6 2018-04-01   3.9

Note that the data start in 1948m1.

To get different series, go to FRED and search for whatever series you want. For example, I typed in “inflation”, which generated several series. Then I picked “Consumer Price Index for All Urban Consumers: All Items”. Clicking on that series reveals the mnemonic CPIAUCSL. Replacing UNRATE with CPIAUCSL will download the CPI price index. This is the “headline” index; the “core” index is CPILFESL, which is less food and energy prices.

Including Plots: Macroeconomic time-series data

Plotting the data is easy. For example:

ggplot(data = ur) +
  geom_line(aes(x = date, y = price)) +
  xlab("") + 
  ylab("Percent")

A subset of the series mentioned in the Employment Situation Summary

The Employment Situation Summary draws on a few sources of data to generate the series that we’re going to plot. The employment series comes from the Establishment Survey, which is a survey answered by firms or establishments.2

Of course firms cannot answer questions about the unemployed. Unemployment data is collected through the Household Survey. This survey calls up a household and asks questions about members of the household. (A high point of my time in Ann Arbor was when I got to answer questions about me and my roommates for a related survey, the American Community Survey.) Respondents also answer questions about household members not in the labor force, the NILFs.

dat <- tq_get(c("UNRATE", "PAYEMS", "CIVPART"), 
              get = "economic.data", from = "1940-01-01")
head(dat)
## # A tibble: 6 x 3
##   symbol date       price
##   <chr>  <date>     <dbl>
## 1 UNRATE 1948-01-01   3.4
## 2 UNRATE 1948-02-01   3.8
## 3 UNRATE 1948-03-01   4  
## 4 UNRATE 1948-04-01   3.9
## 5 UNRATE 1948-05-01   3.5
## 6 UNRATE 1948-06-01   3.6
tail(dat)
## # A tibble: 6 x 3
##   symbol  date       price
##   <chr>   <date>     <dbl>
## 1 CIVPART 2017-11-01  62.7
## 2 CIVPART 2017-12-01  62.7
## 3 CIVPART 2018-01-01  62.7
## 4 CIVPART 2018-02-01  63  
## 5 CIVPART 2018-03-01  62.9
## 6 CIVPART 2018-04-01  62.8

You can see that the data are in “long” form. At this point you could reshape the data into “wide” form, but we’ll skip that and simply plot the different series.

ggplot(data = subset(dat, symbol == "PAYEMS")) +
  geom_line(aes(x = date, y = price)) +
  xlab("") + 
  ylab("Thousands of persons") + 
  ggtitle("All employees: Total nonfarm payrolls")

ggplot(data = subset(dat, symbol == "CIVPART")) +
  geom_line(aes(x = date, y = price)) +
  xlab("") +
  ylab("Percent") +
  ggtitle("Civilian labor force participation rate")

ggplot(data = subset(dat, symbol == "UNRATE")) +
  geom_line(aes(x = date, y = price)) +
  xlab("") +
  ylab("Percent") +
  ggtitle("Civilian unemployment rate")

A million-dollar policy question

I’ll leave you with a million-dollar policy question: Why is the labor-force participation rate of men declining so much?

dat <- tq_get(c("LNS11300002", "LNS11300001"), 
              get = "economic.data",
              from = "1940-01-01")
dat <- dat %>% 
  mutate(series = case_when(
    symbol == "LNS11300001" ~ "Men",
    symbol == "LNS11300002" ~ "Women"
  )) 

ggplot(data = dat) +
  geom_line(mapping = aes(x = date, y = price, color = series), size = 1.5) +
  xlab("") +
  ylab("") +
  ggtitle("Labor force participation rates of men and women") +
  labs(color = "")

First, this is one of the most striking figures in labor–macro. Just think about this figure in the context of the TV show Mad Men. Second, of late, the participation rates of men and women have been declining. This coincides with the drop-off in the growth rate of output that Professor House was commenting on yesterday in class. Are these patterns linked? Why? This is what policy-oriented economists are trying to figure out.


  1. Authorial conjecture: You’ll be hiring me in a couple of year after you get a job making R markdown reports based on the Employment Situation Summary.

  2. Which is a creative name. No, but, a firm can be made up of several establishments, so there’s an important distinction. The takeaway is that firms are responding to the survey.