#Packages List
library(ipumsr)
library(readr)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.3 ✔ purrr 1.0.2
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.3 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(dplyr)
library(psych)
##
## Attaching package: 'psych'
##
## The following objects are masked from 'package:ggplot2':
##
## %+%, alpha
library(ggplot2)
Probability sampling: it is a sampling method that involves randomly selecting a sample out of your population. All entities or objects from the population have a equal probability of being selected.
Non-probability sampling: it is a sampling method that involves using certain criteria to create a sample out of your population. Some of the criteria could be characteristics of the population, availability, geography location. Not all entities or objects have the same probability of being selected.
Probability random sampling methods
Simple random sampling: everyone in the population has an equal chance of being selected and the samples are generated randomly.
stratified random sampling: a population is divided in subgroups and a sample is selected from each subgroup.
systematic sampling: every k^th item is selected to produce the sample.
cluster sampling: divides the population into non-overlapping clusters and then randomly select entire clusters to produce the sample.
Non-probability random sampling methods
convenience sampling: involves creating a sample out of convenience for the researcher.
purposive sampling: items are selected based on their characteristics.
quota sampling: selecting a predetermined number of items or observations.
snowball sampling: the selected items or units will then select more items.
The population of interest is the whole population of the US. The main objective of the CPS is to measure unemployment and other aspects of the labor market.
Some of the criteria that it uses in collecting data:
People over 16 years old.
It excludes people living in institutions and those on active duty in the armed forces.
The CPS is a probability sample and uses cluster sampling to create the different geographic areas and strata sampling to create subgroups based on independt information obtained from the decennial census within the selected geographic areas.
For the CPS, all of the counties and independent cities are in the country are grouped into 2000 geographic areas (primary sampling units PSU). Then, about 800 are selected to represent each state and the district of Columbia.
The original sample consists in 60,000 eligible households, which translates into 110,000 individuals each month.
Something interesting I found that relates to our class is that the interviewers don’t ask if a person is unemployed and they also don’t classify the status of a person, a computer program takes the recorded responses and classifies the person as either employed, unemployed or not in the labor force.
I think it is a representative sample of the US population because of the way the CPS is designed.
ddi <- read_ipums_ddi("cps_00002.xml")
data2 <- read_ipums_micro(ddi)
## Use of data from IPUMS CPS is subject to conditions including that users should cite the data appropriately. Use command `ipums_conditions()` for more details.
#cleaning data
data3 <- data2 %>% filter(INCWAGE != 99999999)
Income by labor force status
ggplot(data = data3,
mapping = aes(x = LABFORCE ,
y = INCWAGE )) + geom_point()
data3 %>%
group_by(LABFORCE) %>%
summarize(mean_income = mean(INCWAGE),
median_income = median(INCWAGE))
## # A tibble: 3 × 3
## LABFORCE mean_income median_income
## <int+lbl> <dbl> <dbl>
## 1 0 [NIU] 59852. 54650
## 2 1 [No, not in the labor force] 2388. 0
## 3 2 [Yes, in the labor force] 56369. 40000
People that are unemployed have a significant lower income than people who are not in the labor force. Since people that are not the labor force don’t work, it makes sense for them to have a lower income than people who are part of the labor force.
#Unemployment rate
unemployed <- nrow(data3[data3$EMPSTAT == 20,]) +
nrow(data3[data3$EMPSTAT == 21,]) +
nrow(data3[data3$EMPSTAT == 22,])
ur <- unemployed / nrow(data3[data3$LABFORCE == 2,])
print(ur)
## [1] 0.04362239
Income by state
data4 <- data3 %>%
group_by(data3$STATECENSUS) %>%
summarize(mean_income = mean(INCWAGE),
median_income = median(INCWAGE))
print(data4)
## # A tibble: 51 × 3
## `data3$STATECENSUS` mean_income median_income
## <int+lbl> <dbl> <dbl>
## 1 11 [Maine] 30130. 12800
## 2 12 [New Hampshire] 40533. 20000
## 3 13 [Vermont] 36188. 17000
## 4 14 [Massachusetts] 47610. 22000
## 5 15 [Rhode Island] 38578. 20000
## 6 16 [Connecticut] 43162. 17000
## 7 21 [New York] 38210. 14000
## 8 22 [New Jersey] 44808. 20000
## 9 23 [Pennsylvania] 36856. 15000
## 10 31 [Ohio] 32974. 13000
## # ℹ 41 more rows
ggplot(data3, aes(x= STATECENSUS, y = INCWAGE)) +
stat_summary(fun = "mean" , geom = "bar" , fill = "black") +
labs( x = "State" , y = "Average Income") +
ggtitle("Average Income by State")
This is just me playing around with the data by year
data_2019 <- subset(data3, YEAR == "2019")
data_2020 <- subset(data3, YEAR == "2020")
data_2021 <- subset(data3, YEAR == "2021")
data_2022 <- subset(data3, YEAR == "2022")
data_2023 <- subset(data3, YEAR == "2023")
#Income average and median income by year
data_2019 %>%
group_by(LABFORCE) %>%
summarize(mean_income = mean(INCWAGE),
median_income = median(INCWAGE))
## # A tibble: 3 × 3
## LABFORCE mean_income median_income
## <int+lbl> <dbl> <dbl>
## 1 0 [NIU] 59877. 52000
## 2 1 [No, not in the labor force] 2040. 0
## 3 2 [Yes, in the labor force] 51561. 37000
data_2020 %>%
group_by(LABFORCE) %>%
summarize(mean_income = mean(INCWAGE),
median_income = median(INCWAGE))
## # A tibble: 3 × 3
## LABFORCE mean_income median_income
## <int+lbl> <dbl> <dbl>
## 1 0 [NIU] 54600. 50000
## 2 1 [No, not in the labor force] 2645. 0
## 3 2 [Yes, in the labor force] 55505. 40000
data_2021 %>%
group_by(LABFORCE) %>%
summarize(mean_income = mean(INCWAGE),
median_income = median(INCWAGE))
## # A tibble: 3 × 3
## LABFORCE mean_income median_income
## <int+lbl> <dbl> <dbl>
## 1 0 [NIU] 60797. 54000
## 2 1 [No, not in the labor force] 2456. 0
## 3 2 [Yes, in the labor force] 54982. 40000
data_2022 %>%
group_by(LABFORCE) %>%
summarize(mean_income = mean(INCWAGE),
median_income = median(INCWAGE))
## # A tibble: 3 × 3
## LABFORCE mean_income median_income
## <int+lbl> <dbl> <dbl>
## 1 0 [NIU] 63039. 55681
## 2 1 [No, not in the labor force] 2424. 0
## 3 2 [Yes, in the labor force] 58378. 42000
data_2023 %>%
group_by(LABFORCE) %>%
summarize(mean_income = mean(INCWAGE),
median_income = median(INCWAGE))
## # A tibble: 3 × 3
## LABFORCE mean_income median_income
## <int+lbl> <dbl> <dbl>
## 1 0 [NIU] 61268. 56000
## 2 1 [No, not in the labor force] 2409. 0
## 3 2 [Yes, in the labor force] 62668. 45000