**Due:** 2020/11/06 6pm EST

## Introduction

In this assignment, we explore data on college majors and earnings, specifically the data in the FiveThirtyEight story ["The Economic Guide To Picking A College Major"](https://fivethirtyeight.com/features/the-economic-guide-to-picking-a-college-major/).

These data originally come from the American Community Survey (ACS) 2010-2012 Public Use Microdata Series. While this is outside the scope of this assignment, if you are curious about how raw data from the ACS were cleaned and prepared, see [the code](https://github.com/fivethirtyeight/data/blob/master/college-majors/college-majors-rscript.R) FiveThirtyEight authors used.

We should also note that there are many considerations that go into picking a major. Earnings potential and employment prospects are two of them, and they are important, but they don't tell the whole story. Keep this in mind as you analyze the data.

The data we are going to use is called `college_recent_grads` in the `fivethirtyeight` package.

## Exercises

### A note on expectations

-   In general, your solution to each exercise should include a code chunk, its output (tables, summary statistics, plots), and a written summary of your findings that answer the questions.
-   You will receive full points on the question if (1) there are no errors in your solution (both codes and summary) AND (2) the summary is written in highly articulate Statistical and English language. Points will be taken off if there are
    errors in your codes, writing or organization.
-   Submit your finished work (in .pdf format) on Gradescope. Each groups only needs to submit once.

### Required packages

In this project, we will be using the packages `tidyverse` and [`fivethirtyeight`](https://cran.r-project.org/web/packages/fivethirtyeight/vignettes/fivethirtyeight.html) . [FiveThirtyEight.com](https://fivethirtyeight.com/) is a data-driven journalism website founded by Nate Silver and owned by ESPN. FiveThirtyEight has been very forward thinking in making the data used in many of their articles open and accessible on [GitHub](https://github.com/fivethirtyeight/data), a web-based repository for collaboration on code and data. The `fivethirtyeight` package goes one step further by pre-processing the original data sets as they exist in the [538 GitHub repository](https://github.com/fivethirtyeight/data) into "tidy data". You can check out all 128 datasets on the `fivethirtyeight` web. This is also a great resource getting data for your final project.

```{r include=FALSE}
# you only need to do this once: after you finish downloading the fivethirtyeight package, you can remove this code chunk
# install.packages("fivethirtyeight")
```

```{r message = FALSE, output = FALSE}
# load the following packages
library(tidyverse)
library(fivethirtyeight)
```

### Problem 1

Use the `glimpse()` function to print out an overview of this dataset `college_recent_grads`, and answer the following questions. What are the observational units in this dataset? For each of the following variables, explain what kind of variable is it, numerical or categorical

-   `unemployment_rate`
-   `women`
-   `median`
-   `major_category`

#### Solution to Problem 1

(Type your answer here. )

### Problem 2

Which major has the lowest unemployment rate? Use the `arrange()` function to sort the `unemployment_rate` variable.

#### Solution to Problem 2

(Type your answer here. )

### Problem 3

Which major has the highest percentage of women? Use the `mutate()` function to create a new variable called `sharewomen_percentage` that describes the **percentage** of women in that major, and then use the `arrange()` function to sort the `sharewomen_percentage` variable.

#### Solution to Problem 3

(Type your answer here. )

### Problem 4

There are three types of incomes reported in this data frame: `p25th`, `median`, and `p75th`. These correspond to the 25th, 50th, and 75th percentiles of the income distribution of individuals for a given major. Use `ggplot` to make a histogram to look at the distribution of all median incomes. Choose an appropriate binwidth.Describe the shape of the histogram.

#### Solution to Problem 4

(Type your answer here. )

### Problem 5

Use the `summarise()` function to calculate summary statistics for the distribution of `median`. Please include `min`, `max`, `mean`, `median`, `sd`, the 25th quartile, the 75th quartile and the IQR.

#### Solution to Problem 5

(Type your answer here. )

### Problem 6

Based on the shape of the histogram you created in the previous exercise, determine which of these summary statistics is useful for describing the distribution.

#### Solution to Problem 6

(Type your answer here. )

### Problem 7

Plot the distribution of `median` income using a histogram, **faceted** by `major_category`. Use the `binwidth` you chose in the earlier exercise.

#### Solution to Problem 7

(Type your answer here. )

### Problem 8

Which major category has the highest typical (you'll need to decide what this means) median income? Use the partial code below, filling it in with the appropriate statistic and function. First explain why you chose that statistic. Also note that we are looking for the highest statistic, so make sure to arrange in the correct direction. Once you are done, remove the argument `, eval=FALSE` in the codeblock.

```{r, eval=FALSE}
college_recent_grads %>%
  group_by(major_category) %>%
  summarise(typical_median_income = ____(median)) %>%
  arrange(___________)
```

#### Solution to Problem 8

(Type your answer here. )

### Problem 9

Which major category is the least popular in this sample? To answer this question we use a new function called `count`, which first groups the data and then counts the number of observations in each category (see below). Add to the pipeline appropriately to arrange the results so that the major with the lowest observations is on top. Once you are done, remove the argument `eval=FALSE` in the codeblock.

```{r eval=FALSE}
college_recent_grads %>%
  count(major_category) ____
  ________________
```

#### Solution to Problem 9

(Type your answer here. )

### Problem 10

One of the sections of the [FiveThirtyEight story](https://fivethirtyeight.com/features/the-economic-guide-to-picking-a-college-major/) is "All STEM fields aren't the same". Let's see if this is true.

First, let's create a new vector called `stem_categories` that lists the major categories that are considered STEM fields.

```{r}
stem_categories <- c("Biology & Life Science",
                     "Physical Sciences",
                     "Computers & Mathematics",
                     "Engineering")
```

Then, we can use this to create a new variable in our data frame indicating whether a major is STEM or not.

```{r}
college_recent_grads <- college_recent_grads %>%
  mutate(major_type = ifelse(major_category %in% stem_categories, "stem", "not stem"))
```

Let's unpack this: with `mutate` we create a new variable called `major_type`, which is defined as `"stem"` if the `major_category` is in the nector called `stem_categories` we created earlier, and as `"not stem"` otherwise.

`%in%` is a **logical operator**. Other logical operators that are commonly used are

| Operator            | Operation                |
|:--------------------|:-------------------------|
| `x < y`             | less than                |
| `x > y`             | greater than             |
| `x <= y`            | less than or equal to    |
| `x >= y`            | greater than or equal to |
| `x != y`            | not equal to             |
| `x == y`            | equal to                 |
| `x %in% y`          | contains                 |
| <code>x \| y</code> | or                       |
| `x & y`             | and                      |
| `!x`                | not                      |

We can use the logical operators to also `filter` our data for STEM majors whose median earnings is less than median for all majors's median earnings, which we found to be \$36,000 in Problem 5.

```{r}
college_recent_grads %>%
  filter(
    major_type == "stem",
    median < 36000
  )
```

Use the `count()` function you learned from Problem 9 and the code here is Problem 10, decide which STEM category ("Biology & Life Science", "Physical Sciences", "Computers & Mathematics", or "Engineering") has the highest number of majors whose median earning is less than \$36,000 (the median for all major's median earnings.)

#### Solution to Problem 10

(Type your answer here. )

## Some tips

-   Make sure each team member is contributing, both in terms of quality and quantity of contribution

-   Set aside time to work together and apart.

-   Teamwork: You are to complete the assignment as a team. All team members are expected to contribute equally to the completion of this assignment and group assessments will be given at its completion - anyone judged to not have sufficient contributed to the final product will have their grade penalized. While different teams members may have different backgrounds and abilities, it is the responsibility of every team member to understand how and why all code and approaches in the assignment works.

## Data codebook

The description of the variables, i.e. the **codebook**, is given below.

+---------------------------------+----------------------------------------------------------------------------+
| Header                          | Description                                                                |
+:================================+:===========================================================================+
| `rank`                          | Rank by median earnings                                                    |
+---------------------------------+----------------------------------------------------------------------------+
| `major_code`                    | Major code, FO1DP in ACS PUMS                                              |
+---------------------------------+----------------------------------------------------------------------------+
| `major`                         | Major description                                                          |
+---------------------------------+----------------------------------------------------------------------------+
| `major_category`                | Category of major from Carnevale et al                                     |
+---------------------------------+----------------------------------------------------------------------------+
| `total`                         | Total number of people with major                                          |
+---------------------------------+----------------------------------------------------------------------------+
| `sample_size`                   | Sample size (unweighted) of full-time, year-round ONLY (used for earnings) |
+---------------------------------+----------------------------------------------------------------------------+
| `men`                           | Male graduates                                                             |
+---------------------------------+----------------------------------------------------------------------------+
| `women`                         | Female graduates                                                           |
+---------------------------------+----------------------------------------------------------------------------+
| `employed`                      | Number employed (ESR == 1 or 2)                                            |
+---------------------------------+----------------------------------------------------------------------------+
| `employed_full_time`            | Employed 35 hours or more                                                  |
+---------------------------------+----------------------------------------------------------------------------+
| `employed_part_time`            | Employed less than 35 hours                                                |
+---------------------------------+----------------------------------------------------------------------------+
| `employed _full_time_yearround` | Employed at least 50 weeks (WKW == 1) and at least 35 hours (WKHP \>= 35)  |
+---------------------------------+----------------------------------------------------------------------------+
| `unemployed`                    | Number unemployed (ESR == 3)                                               |
+---------------------------------+----------------------------------------------------------------------------+
| `unemployment_rate`             | Unemployed / (Unemployed + Employed)                                       |
+---------------------------------+----------------------------------------------------------------------------+
| `median`                        | Median earnings of full-time, year-round workers                           |
+---------------------------------+----------------------------------------------------------------------------+
| `p25th`                         | 25th percentile of earnigns                                                |
+---------------------------------+----------------------------------------------------------------------------+
| `p75th`                         | 75th percentile of earnings                                                |
+---------------------------------+----------------------------------------------------------------------------+
| `college_jobs`                  | Number with job requiring a college degree                                 |
+---------------------------------+----------------------------------------------------------------------------+
| `non_college_jobs`              | Number with job not requiring a college degree                             |
+---------------------------------+----------------------------------------------------------------------------+
| `low_wage_jobs`                 | Number in low-wage service jobs                                            |
+---------------------------------+----------------------------------------------------------------------------+
