---
title: "The US Labor Force"
author: "K. Gwet"
date: "11/1/2021"
output: word_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(readr)
library(ggplot2)
library(tidyverse)
fra.lforce <- read_csv("./data/labor-force-stats.csv",show_col_types = FALSE)
by.all <-fra.lforce%>%
  summarise(across(where(is.numeric),sum))
by.all.sex <- mutate(by.all,gender="All")[,c(5,1:4)]
by.gender <- fra.lforce%>%
  group_by(gender)%>%
  summarise(across(where(is.numeric),sum))
by.gender <- rbind(by.all.sex,by.gender)
```

## Some Labor Force Statistics

The labor force is expected to increase by **`r round(by.all.sex$LF2030/1000 - by.all.sex$LF2020/1000,1)`** million, from **`r round(by.all.sex$LF2020/1000,1)`** million in 2020 to **`r round(by.all.sex$LF2030/1000,1)`** million in 2030. 

For males aged 16 or older, the labor force is projected to increase by 
**`r round((by.gender$LF2030[2]-by.gender$LF2020[2])/1000,1)`** million  from **`r round(by.gender$LF2020[2]/1000,1)`** million in 2020 to **`r round(by.gender$LF2030[2] / 1000,1)`** million in 2030. 

For females aged 16 or more, that increase is higher and estimated at **`r round((by.gender$LF2030[3]-by.gender$LF2020[3])/1000,1)`** million  from **`r round(by.gender$LF2020[3]/1000,1)`** million in 2020 to **`r round(by.gender$LF2030[3] / 1000,1)`** million in 2030.

Here is the summary table of the size of the **US Labor Force** by gender:

```{r lfbysex,echo=FALSE}
knitr::kable(by.gender)
```

## Including Plots

You can also embed plots in your Word document.  However, the approach we recommend for creating plots requires that you transform the previous table into the long format as follows:

```{r pressure, echo=FALSE}
df.LF <- tibble(year=character(),gender=character(),laborforce=double())
cnames <- colnames(by.gender)
for (i in 1:nrow(by.gender)) {
    for (j in 2:ncol(by.gender)){
      year <- substr(cnames[j],3,6)
      gender <- by.gender$gender[i]
      laborforce <- by.gender[[j]][i]
      df.LF <- add_row(df.LF,year,gender,laborforce)
    }
}
```

```{r bardata, echo=FALSE}
knitr::kable(df.LF)
```

A key advantage that the long format (second table) has over the wide format (first table) is the possibility to add variables to the table other than the labor force. You could add employment or labor force participation and so on.


Creating the second table from the first in R, requires basic-level programming. But you may also decide to do it in Excel and read it in R to generate the the barplot shown below.


```{r barplot, echo=FALSE}
ggplot(df.LF, aes(x=year, y=laborforce, fill=gender)) + 
  geom_bar(stat="identity", position=position_dodge()) +
  theme_bw() +
  ylab("Labor Force (x1000)")
```

Note that you can include in the Word document, the R code that created the second table and generated the barplot. 
