-
Notifications
You must be signed in to change notification settings - Fork 0
/
Final Draft.Rmd
133 lines (115 loc) · 4.92 KB
/
Final Draft.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
---
title: "Final Draft"
author: "Lucy Ding"
date: "5/2/2022"
output: html_document
---
# Loading Packages
```{r, warning = FALSE}
library(tidyverse)
library(janitor)
library(readxl)
library(usmap)
library(stargazer)
library(haven)
library(tigris)
library(rio)
library(standardize)
library(effsize)
library(ggthemes)
```
# Load Datasets
```{r, output = FALSE, warning = FALSE}
df_immi <- read_excel("migration_df.xls")
df_emi <- read_excel("migration_df2.xls")
```
# Immigration
```{r, output = FALSE, warning = FALSE}
# Basic linear regression
stargazer(lm(dem_prop ~ avg_immi_rate, data = df_immi, weight = total_pop),
type = "text")
```
```{r, warning = FALSE, message = FALSE}
# Visualization of relationship between immigration rate and dem percent
ggplot(df_immi, aes(x = avg_immi_rate, y = dem_prop, size = total_pop)) +
geom_point(alpha = .3) +
geom_smooth(method = "lm", aes(weight = total_pop), show.legend = FALSE) +
labs(title = "Fall in Democratic Voting with Increase in Rate of Immigration",
x = "Immigration Rate",
y = "Two-Party Democratic Vote Share",
subtitle = "2020 Presidential Election",
caption = "Weighted by County Population")
```
```{r, warning = FALSE, message = FALSE}
# Regression with controls
stargazer(lm(dem_prop ~ avg_immi_rate + percent_white + percent_hispanic +
percent_bachelors + avg_wage + poverty + unemp + med_household_income, data = df_immi,
weight = total_pop),
lm(dem_prop ~ avg_immi_rate + percent_white + percent_hispanic +
percent_bachelors, data = df_immi,
weight = total_pop),
lm(dem_prop ~ avg_immi_rate + avg_wage + poverty + unemp + med_household_income, data = df_immi,
weight = total_pop),
type = "text")
```
```{r, warning = FALSE, message = FALSE}
# Regression standardized
df_immi$dem_prop_scaled <- scale(df_immi$dem_prop)[, 1]
df_immi$avg_immi_rate_scaled <- scale(df_immi$avg_immi_rate)[, 1]
df_immi$percent_white_scaled <- scale(df_immi$percent_white)[, 1]
df_immi$percent_bachelors_scaled <- scale(df_immi$percent_bachelors)[, 1]
df_immi$med_household_income_scaled <- scale(df_immi$med_household_income)[, 1]
df_immi$percent_hispanic_scaled <- scale(df_immi$percent_hispanic)[, 1]
df_immi$avg_wage_scaled <- scale(df_immi$avg_wage)[, 1]
df_immi$poverty_scaled <- scale(df_immi$poverty)[, 1]
df_immi$unemp_scaled <- scale(df_immi$unemp)[, 1]
stargazer(lm(dem_prop_scaled ~ avg_immi_rate_scaled + percent_white_scaled + percent_bachelors_scaled +
med_household_income_scaled + percent_hispanic_scaled +
avg_wage_scaled + poverty_scaled + unemp_scaled, data = df_immi,
weight = total_pop), type = "text")
```
# Emigration
```{r, output = FALSE, warning = FALSE}
# Basic linear regression
stargazer(lm(dem_prop ~ avg_emi_rate, data = df_emi, weight = total_pop),
type = "text")
```
```{r, warning = FALSE, message = FALSE}
# Visualization of relationship between immigration rate and dem percent
ggplot(df_emi, aes(x = avg_emi_rate, y = dem_prop, size = total_pop)) +
geom_point(alpha = .3) +
geom_smooth(method = "lm", aes(weight = total_pop), show.legend = FALSE) +
labs(title = "Fall in Democratic Voting with Increase in Rate of Immigration",
x = "Immigration Rate",
y = "Two-Party Democratic Vote Share",
subtitle = "2020 Presidential Election",
caption = "Weighted by County Population")
```
```{r, warning = FALSE, message = FALSE}
# Regression with controls
stargazer(lm(dem_prop ~ avg_emi_rate + percent_white + percent_hispanic +
percent_bachelors + avg_wage + poverty + unemp + med_household_income, data = df_emi,
weight = total_pop),
lm(dem_prop ~ avg_emi_rate + percent_white + percent_hispanic +
percent_bachelors, data = df_emi,
weight = total_pop),
lm(dem_prop ~ avg_emi_rate + avg_wage + poverty + unemp + med_household_income, data = df_emi,
weight = total_pop),
type = "text")
```
```{r, warning = FALSE, message = FALSE}
# Regression standardized
df_emi$dem_prop_scaled <- scale(df_emi$dem_prop)[, 1]
df_emi$avg_emi_rate_scaled <- scale(df_emi$avg_emi_rate)[, 1]
df_emi$percent_white_scaled <- scale(df_emi$percent_white)[, 1]
df_emi$percent_bachelors_scaled <- scale(df_emi$percent_bachelors)[, 1]
df_emi$med_household_income_scaled <- scale(df_emi$med_household_income)[, 1]
df_emi$percent_hispanic_scaled <- scale(df_emi$percent_hispanic)[, 1]
df_emi$avg_wage_scaled <- scale(df_emi$avg_wage)[, 1]
df_emi$poverty_scaled <- scale(df_emi$poverty)[, 1]
df_emi$unemp_scaled <- scale(df_emi$unemp)[, 1]
stargazer(lm(dem_prop_scaled ~ avg_emi_rate_scaled + percent_white_scaled + percent_bachelors_scaled +
med_household_income_scaled + percent_hispanic_scaled +
avg_wage_scaled + poverty_scaled + unemp_scaled, data = df_emi,
weight = total_pop), type = "text")
```