library(scales)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ readr::col_factor() masks scales::col_factor()
## ✖ purrr::discard() masks scales::discard()
## ✖ 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(knitr)
library(dplyr)
library(modelr)
library(scales)
library(readr)
google_term_data <- read.csv('from_google_trends/google_3_terms_trend_data_04_20.csv', header = TRUE, sep= ",", skip = 2, col.names = c('ymd', 'immigr_report', 'immigr_crime', 'immigr_welfare'))
head(google_term_data)
## ymd immigr_report immigr_crime immigr_welfare
## 1 2004-01 0 0 0
## 2 2004-02 36 0 0
## 3 2004-03 0 0 0
## 4 2004-04 48 0 34
## 5 2004-05 66 0 0
## 6 2004-06 35 0 0
google_term_data <-
google_term_data |>
mutate(ymd = as.Date(paste0(ymd, "-01")))|>
mutate(year = year(ymd), month = month(ymd)) |>
mutate(president = ifelse(year<=2008, "bush",
ifelse(year>2008 & year <= 2016, "obama", "trump")))
google_term_data |>
ggplot(aes(x = ymd, y= immigr_report, colour = president)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
xlab("Time Line") +
ylab("Immigration Report Search Trend") +
ggtitle("Immigration Report Search Trend on Google Trend Data")
## `geom_smooth()` using formula = 'y ~ x'
google_term_data |>
ggplot(aes(x = ymd, y= immigr_crime, colour = president)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
xlab("Time Line") +
ylab("Immigration Crime Search Trend") +
ggtitle("Immigration Crime Search Trend on Google Trend Data")
## `geom_smooth()` using formula = 'y ~ x'
google_term_data |>
ggplot(aes(x = ymd, y= immigr_welfare, colour = president)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
xlab("Time Line") +
ylab("Immigration Welfare Search Trend") +
ggtitle("Immigration Welfare Search Trend on Google Trend Data")
## `geom_smooth()` using formula = 'y ~ x'
library(stargazer)
##
## Please cite as:
## Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
## R package version 5.2.3. https://CRAN.R-project.org/package=stargazer
library(fastDummies)
## Thank you for using fastDummies!
## To acknowledge our work, please cite the package:
## Kaplan, J. & Schlegel, B. (2023). fastDummies: Fast Creation of Dummy (Binary) Columns and Rows from Categorical Variables. Version 1.7.1. URL: https://github.com/jacobkap/fastDummies, https://jacobkap.github.io/fastDummies/.
google_term_data <-
google_term_data |>
mutate(president = as.factor(president),
president = relevel(president, ref = "obama"))
google_term_data_dummies <- dummy_cols(google_term_data, select_columns = "president", remove_first_dummy = FALSE)
head(google_term_data_dummies)
## ymd immigr_report immigr_crime immigr_welfare year month president
## 1 2004-01-01 0 0 0 2004 1 bush
## 2 2004-02-01 36 0 0 2004 2 bush
## 3 2004-03-01 0 0 0 2004 3 bush
## 4 2004-04-01 48 0 34 2004 4 bush
## 5 2004-05-01 66 0 0 2004 5 bush
## 6 2004-06-01 35 0 0 2004 6 bush
## president_obama president_bush president_trump
## 1 0 1 0
## 2 0 1 0
## 3 0 1 0
## 4 0 1 0
## 5 0 1 0
## 6 0 1 0
model_crime <- lm(immigr_crime ~ (ymd + president_bush + president_trump + president_obama), data = google_term_data_dummies)
model_welfare <- lm(immigr_welfare ~ (ymd + president_bush + president_trump + president_obama), data = google_term_data_dummies)
model_report <- lm(immigr_report ~ (ymd + president_bush + president_trump + president_obama ), data = google_term_data_dummies)
model_crime2 <- lm(immigr_crime ~ ymd + president, data = google_term_data_dummies)
model_welfare2 <- lm(immigr_welfare ~ (ymd + president), data = google_term_data_dummies)
model_report2 <- lm(immigr_report ~ (ymd + president), data = google_term_data_dummies)
stargazer(model_crime, model_welfare, model_report,
title = "Table 3 OLS",
dep.var.labels = c("Crime", "Welfare", "Report"),
# out = "table3_ols.html", # Save to HTML file
type = "text", # You can also use "html" or "latex"
intercept.bottom = FALSE,
omit.stat = c("ser", "adj.rsq", "f", "aic"),
notes = "Note: ∗p<0.1; ∗∗p<0.05; ∗∗∗p<0.01" )
##
## Table 3 OLS
## ===================================================
## Dependent variable:
## -----------------------------------
## Crime Welfare Report
## (1) (2) (3)
## ---------------------------------------------------
## Constant -31.598** -10.665 70.043***
## (13.669) (11.714) (17.008)
##
## ymd 0.003*** 0.001* -0.002
## (0.001) (0.001) (0.001)
##
## president_bush 3.179 1.682 -0.977
## (2.465) (2.112) (3.067)
##
## president_trump 7.206*** 4.744** 16.289***
## (2.368) (2.030) (2.947)
##
## president_obama
##
##
## ---------------------------------------------------
## Observations 192 192 192
## R2 0.332 0.196 0.191
## ===================================================
## Note: *p<0.1; **p<0.05; ***p<0.01
## Note: ∗p<0.1; ∗∗p<0.05; ∗∗∗p<0.01
stargazer(model_crime2, model_welfare2, model_report2,
title = "Table 3 OLS",
dep.var.labels = c("Crime", "Welfare", "Report"),
out = "table3_ols.html", # Save to HTML file
type = "text", # You can also use "html" or "latex"
intercept.bottom = FALSE,
omit.stat = c("ser", "adj.rsq", "f", "aic"),
notes = "Note: ∗p<0.1; ∗∗p<0.05; ∗∗∗p<0.01" )
##
## Table 3 OLS
## ==================================================
## Dependent variable:
## -----------------------------------
## Crime Welfare Report
## (1) (2) (3)
## --------------------------------------------------
## Constant -31.598** -10.665 70.043***
## (13.669) (11.714) (17.008)
##
## ymd 0.003*** 0.001* -0.002
## (0.001) (0.001) (0.001)
##
## presidentbush 3.179 1.682 -0.977
## (2.465) (2.112) (3.067)
##
## presidenttrump 7.206*** 4.744** 16.289***
## (2.368) (2.030) (2.947)
##
## --------------------------------------------------
## Observations 192 192 192
## R2 0.332 0.196 0.191
## ==================================================
## Note: *p<0.1; **p<0.05; ***p<0.01
## Note: ∗p<0.1; ∗∗p<0.05; ∗∗∗p<0.01
library(stm)
## stm v1.3.7 successfully loaded. See ?stm for help.
## Papers, resources, and other materials at structuraltopicmodel.com
load("from_replication_files/topic_model_lite.Rdata")
# document_topics <- make.dt(immigrFit, meta = out$meta)
# topic_terms <- t(exp(immigrFit$beta$logbeta[[1]]))
# rownames(topic_terms) <- out$vocab
# colnames(topic_terms) <- sprintf("Topic%d", 1:ncol(topic_terms))
document_topics_figure <- document_topics |>
mutate(date = as.Date(date),
year_month = ym(format(date, "%Y-%m")))
head(document_topics_figure)
## docnum Topic1 Topic2 Topic3 Topic4 Topic5 Topic6
## <int> <num> <num> <num> <num> <num> <num>
## 1: 1 0.004481022 0.009960933 0.004461316 0.01173189 0.055799780 0.11100898
## 2: 2 0.007721907 0.010274636 0.007847635 0.02223299 0.012992140 0.04594693
## 3: 3 0.001990162 0.036386592 0.001962287 0.03997450 0.015489060 0.02125399
## 4: 4 0.066536793 0.007539572 0.014041768 0.02412229 0.054856524 0.01472651
## 5: 5 0.007608635 0.006301671 0.008562301 0.03237121 0.005584864 0.26136304
## 6: 6 0.001472374 0.005644046 0.001495451 0.01790099 0.007050577 0.01825270
## Topic7 Topic8 Topic9 Topic10 Topic11 Topic12
## <num> <num> <num> <num> <num> <num>
## 1: 0.006210360 0.03328737 0.03705146 0.009866943 0.004249936 0.03460265
## 2: 0.009107538 0.02681331 0.04657247 0.016150845 0.015244264 0.15595228
## 3: 0.005533472 0.01596025 0.04617686 0.013243828 0.030639023 0.07490007
## 4: 0.007204676 0.02533136 0.06158577 0.019073330 0.008334470 0.06095308
## 5: 0.008460921 0.07231750 0.09063208 0.012023576 0.006875597 0.03770051
## 6: 0.005254774 0.01243526 0.06271923 0.010633550 0.015131752 0.06764035
## Topic13 Topic14 Topic15 Topic16 Topic17 Topic18
## <num> <num> <num> <num> <num> <num>
## 1: 0.007756699 0.005677329 0.42345443 0.02206642 0.016853160 0.006786136
## 2: 0.011589109 0.018271514 0.01186500 0.01135392 0.062879412 0.030123669
## 3: 0.007677318 0.006668851 0.02736504 0.02057301 0.026993109 0.011274009
## 4: 0.012310378 0.012594266 0.09564177 0.08201477 0.024324826 0.157872080
## 5: 0.007243552 0.005644923 0.01910204 0.01092138 0.009163456 0.007729616
## 6: 0.005285978 0.006097695 0.01308397 0.01464026 0.047076425 0.011468041
## Topic19 Topic20 Topic21 Topic22 Topic23 Topic24
## <num> <num> <num> <num> <num> <num>
## 1: 0.02897509 0.01867581 0.005059061 0.01049189 0.008669347 0.005460053
## 2: 0.02281589 0.01312346 0.019911887 0.09073124 0.012975511 0.011565569
## 3: 0.22863645 0.01124365 0.004194223 0.01894001 0.008787693 0.005742626
## 4: 0.01551407 0.04964885 0.023092261 0.01378088 0.014554965 0.007895687
## 5: 0.03116605 0.15256457 0.008546183 0.01516036 0.042245790 0.015449937
## 6: 0.22167403 0.01063780 0.002027293 0.02008519 0.007386427 0.005230003
## Topic25 Topic26 Topic27 Topic28 Topic29 Topic30 V1
## <num> <num> <num> <num> <num> <num> <int>
## 1: 0.034683635 0.044329741 0.005325746 0.010424776 0.009609772 0.01298825 6
## 2: 0.066554979 0.010720404 0.027492274 0.111916527 0.065141232 0.02411147 8
## 3: 0.163761556 0.016720176 0.004825996 0.093231571 0.023199065 0.01665553 12
## 4: 0.018657120 0.023390607 0.043032434 0.009640144 0.012780301 0.01894844 16
## 5: 0.008031636 0.012350854 0.050353117 0.014265918 0.006190907 0.03406780 19
## 6: 0.043571211 0.009089149 0.003065541 0.328637555 0.011419627 0.01389274 20
## start stop start_time program
## <int> <int> <char> <char>
## 1: 444 458 2019-03-31 19:00:00 Headliners
## 2: 1326 1336 2019-03-31 19:00:00 Headliners
## 3: 2069 2088 2019-04-01 02:00:00 First Look
## 4: 10366 10422 2019-04-01 03:00:00 Morning Joe
## 5: 383 435 2019-04-01 06:00:00 MSNBC Live With Stephanie Ruhle
## 6: 826 836 2019-04-01 06:00:00 MSNBC Live With Stephanie Ruhle
## title
## <char>
## 1: MSNBCW_20190401_020000_Headliners
## 2: MSNBCW_20190401_020000_Headliners
## 3: MSNBCW_20190401_090000_First_Look
## 4: MSNBCW_20190401_100000_Morning_Joe
## 5: MSNBCW_20190401_130000_MSNBC_Live_With_Stephanie_Ruhle
## 6: MSNBCW_20190401_130000_MSNBC_Live_With_Stephanie_Ruhle
## txt
## <char>
## 1: COUNTRY OF IMMIGRANTS IS A BETTER COUNTRY AND THAT THE IMMIGRANT EXPERIENCE IN THIS COUNTRY IS FUNDAMENTAL TO THE STORY OF AMERICA. >> A QUARTER OF THOSE WHO LIVE HERE WERE BORN IN ANOTHER COUNTRY. THEIR VERY PRESENCE MAKES US SAFER, MORE SUCCESSFUL, STRONGER, MORE SECURE. >> THAT'S HIS ISSUE. POSTURE OF PRIDE AND CELEBRATION OF WHAT WE HAVE HERE. >> BUT INCITING FEAR OF ILLEGAL IMMIGRANTS IS WHAT HELPED ELECT THE NATION'S 45th PRESIDENT. >> WE WILL BUILD A GREAT, GREAT WALL. AND WE WILL PUT AN END TO ILLEGAL IMMIGRATION.
## 2: >> SPEAKING IN SPANISH, BETO TRIED TO SELL THE PROPOSAL TO A SKEPTICAL AUDIENCE. >> RESIDENTS OF THE COMMUNITY HAD SAID HOW CAN YOU BE SITTING AT THE SAME DINNER TABLE WITH THE SAME PERSON, YOUR >> THEY ALSO BUTTED HEADS OVER IMMIGRATION. >> SENATOR CRUZ HAS PROMISED TO DEPORT EACH AND EVERY SINGLE DREAMER. THAT CANNOT BE THE WAY THAT TEXAS LEADS ON THIS IMPORTANT ISSUE. >> HIS FOCUS SEEMS TO BE ON FIGHTING FOR ILLEGAL IMMIGRANTS
## 3: OF IMMIGRATION AS AN IMPORTANT ISSUE FOR HIS CAMPAIGN. >> IF WE ARE REALLY SERIOUS ABOUT SECURITY, WE HAVE A GOLDEN OPPORTUNITY, REPUBLICANS, INDEPENDENTS, DEMOCRATS ALIKE TO WORK ON COMPREHENSIVE IMMIGRATION REFORM, TO REWRITE THIS COUNTRY'S IMMIGRATION LAWS
## 4: AND FEAR BY IMMIGRANTS AND FAMILIES WITH IMMIGRANTS TO THE POINT THAT THE PEOPLE WHO WORK AT THE CENSUS BUREAU WERE SO ALARGE THAT THEY BROUGHT THIS TO THE SUSTAINS OF THE IN A. >>> THEN THE ANNOUNCEMENT COMES THAT WE'RE GOING TO ASK EVERYBODY ARE YOU A CITIZEN, YES OR NO? WE NO EVERY SENTENCE HAS A CONSEQUENCE TO RESPONSE RATES. THE CHIEF SCIENTIST HIMSELF HAS TESTIFIED THAT THIS QUESTION IN PARTICULAR WILL SUPPRESS RESPONSE RATE BY LATINOS, ASIANS AND INDIVIDUALS WITH IMMIGRANTS
## 5: ACCORDING TO IMMIGRATION ADVOCATES, THE EXACT OPPOSITE STRATEGY OF WHAT SHOULD DO IF YOU WANT IT TO ACTUALLY HELP CONTROL OR ALLEVIATE THE HUMANITARIAN CRISIS THAT'S GOING ON RIGHT NOW ALONG THE SOUTHERN BORDER. ON THE CONTRARY, THE IDEA OF SHUTTING DOWN THE BORDER WILL ONLY MAKE MORE PEOPLE GO THROUGH THE ILLEGAL WAY TO GET INTO THE COUNTRY, WHICH IS IN BETWEEN PORTS OF ENTRY. THE ULTIMATE GOAL HERE, BY THE WAY, THE BOTTOM LINE IS THE SAME GOAL DURING ZERO-TOLERANCE, AND THIS IS WHAT AN ADMINISTRATION OFFICIAL TOLD ME. THE GOLD WAS TO CREATE IMAGES LIKE WE'RE SEEING UNDER THE DEL NORTE BRIDGE, AND THAT'S TO DETAIN FAMILIES, AND TO SEND BACK UNACCOMPANIED MY GRANT CHILDREN IMMEDIATELY FROM THEIR HOME COUNTRIES. AGAIN, THAT IS WHAT IMMIGRATION
## 6: COMPREHENSIVE IMMIGRATION REFORM, THE WIND WE COULD HAVE VOTED ON. >> YOU CAN'T BLAME THE PRESIDENT TO SAY PASS COMPREHENSIVE IMMIGRATION REFORM.
## trump channel date tst duration post_election post_trump
## <int> <char> <Date> <int> <num> <num> <num>
## 1: 0 msnbc 2019-03-31 1 0.2333333 1 0
## 2: 0 msnbc 2019-03-31 1 0.1666667 1 0
## 3: 0 msnbc 2019-04-01 1 0.3166667 1 0
## 4: 0 msnbc 2019-04-01 1 0.9333333 1 0
## 5: 0 msnbc 2019-04-01 1 0.8666667 1 0
## 6: 0 msnbc 2019-04-01 1 0.1666667 1 0
## time year_month
## <fctr> <Date>
## 1: post-election 2019-03-01
## 2: post-election 2019-03-01
## 3: post-election 2019-04-01
## 4: post-election 2019-04-01
## 5: post-election 2019-04-01
## 6: post-election 2019-04-01
# document_topics_figure |>
# select(year_month, channel,duration, time) |>
# group_by(year_month, channel, time) |>
# summarise(air_count= sum(duration)) |>
# ggplot(aes(x = year_month, y = air_count, colour = channel)) +
# geom_point()
time_lines <- document_topics_figure |>
select(time, year_month) |>
group_by(time) |>
summarise(year_month = min(year_month))
document_topics_figure |>
select(year_month, channel,duration, time) |>
group_by(year_month, channel, time) |>
summarise(air_count= sum(duration)) |>
ungroup() |>
group_by(channel, time) |>
ggplot(aes(x = year_month, y = air_count, color = channel, group = interaction(channel, time))) +
geom_point() + geom_smooth( se=FALSE) +
geom_vline(data = time_lines, aes(xintercept = as.numeric(year_month)), linetype = "dotted", color = "black") +
xlab("Year") +
ylab("Num Monthly Immigration Segment") +
ggtitle("Immigration news segments")
## `summarise()` has grouped output by 'year_month', 'channel'. You can override
## using the `.groups` argument.
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
document_topics_figure <- document_topics_figure |>
select(date, Topic1, Topic3, Topic13,year_month, channel, duration, time)
document_topics_figure |>
group_by(year_month, channel, time) |>
summarise(topic1_seg = sum((Topic1 +Topic3)*duration )) |>
ggplot(aes(x = year_month, y = topic1_seg, color = channel, group = interaction(channel, time))) +
geom_point() + geom_smooth( se=FALSE) +
geom_vline(data = time_lines, aes(xintercept = as.numeric(year_month)), linetype = "dotted", color = "black") +
xlab("Year") +
ylab("Immigration Crime News Coverage") +
ggtitle("Immigration news segments by Topic 'Immigration Crime'")
## `summarise()` has grouped output by 'year_month', 'channel'. You can override
## using the `.groups` argument.
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
document_topics_figure |>
group_by(year_month, channel, time) |>
summarise(topic1_seg = sum((Topic13)*duration )) |>
ggplot(aes(x = year_month, y = topic1_seg, color = channel, group = interaction(channel, time))) +
geom_point() + geom_smooth( se=FALSE) +
geom_vline(data = time_lines, aes(xintercept = as.numeric(year_month)), linetype = "dotted", color = "black") +
xlab("Year") +
ylab("Immigration Welfare News Coverage") +
ggtitle("Immigration news segments by Topic 'Immigration Welfare'")
## `summarise()` has grouped output by 'year_month', 'channel'. You can override
## using the `.groups` argument.
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
head(google_term_data_dummies)
## ymd immigr_report immigr_crime immigr_welfare year month president
## 1 2004-01-01 0 0 0 2004 1 bush
## 2 2004-02-01 36 0 0 2004 2 bush
## 3 2004-03-01 0 0 0 2004 3 bush
## 4 2004-04-01 48 0 34 2004 4 bush
## 5 2004-05-01 66 0 0 2004 5 bush
## 6 2004-06-01 35 0 0 2004 6 bush
## president_obama president_bush president_trump
## 1 0 1 0
## 2 0 1 0
## 3 0 1 0
## 4 0 1 0
## 5 0 1 0
## 6 0 1 0
google_term_data_table4 <- google_term_data_dummies|>
mutate(month= as.factor(month), president_trump= as.factor(president_trump)) |>
# filter(president_trump == 1) |>
select(ymd, month, immigr_report, president_trump)
head(google_term_data_table4)
## ymd month immigr_report president_trump
## 1 2004-01-01 1 0 0
## 2 2004-02-01 2 36 0
## 3 2004-03-01 3 0 0
## 4 2004-04-01 4 48 0
## 5 2004-05-01 5 66 0
## 6 2004-06-01 6 35 0
head(document_topics_figure)
## date Topic1 Topic3 Topic13 year_month channel duration
## <Date> <num> <num> <num> <Date> <char> <num>
## 1: 2019-03-31 0.004481022 0.004461316 0.007756699 2019-03-01 msnbc 0.2333333
## 2: 2019-03-31 0.007721907 0.007847635 0.011589109 2019-03-01 msnbc 0.1666667
## 3: 2019-04-01 0.001990162 0.001962287 0.007677318 2019-04-01 msnbc 0.3166667
## 4: 2019-04-01 0.066536793 0.014041768 0.012310378 2019-04-01 msnbc 0.9333333
## 5: 2019-04-01 0.007608635 0.008562301 0.007243552 2019-04-01 msnbc 0.8666667
## 6: 2019-04-01 0.001472374 0.001495451 0.005285978 2019-04-01 msnbc 0.1666667
## time
## <fctr>
## 1: post-election
## 2: post-election
## 3: post-election
## 4: post-election
## 5: post-election
## 6: post-election
document_topics_table4 <-
document_topics_figure |>
mutate(crime = Topic1 + Topic3, welfare = Topic13, ymd = year_month) |>
# select(crime, welfare, ymd) |>
group_by(ymd) |>
summarise(
segs = n(),
crime_prop = mean(crime),
welfare_prop = mean(welfare))
head(document_topics_table4)
## # A tibble: 6 × 4
## ymd segs crime_prop welfare_prop
## <date> <int> <dbl> <dbl>
## 1 2014-01-01 206 0.0272 0.0267
## 2 2014-02-01 249 0.0181 0.0275
## 3 2014-03-01 112 0.0428 0.0408
## 4 2014-04-01 153 0.0408 0.0206
## 5 2014-05-01 150 0.0857 0.0221
## 6 2014-06-01 613 0.0295 0.0193
df_table4_month <- left_join(document_topics_table4, google_term_data_table4, by = "ymd")
head(df_table4_month)
## # A tibble: 6 × 7
## ymd segs crime_prop welfare_prop month immigr_report president_trump
## <date> <int> <dbl> <dbl> <fct> <int> <fct>
## 1 2014-01-01 206 0.0272 0.0267 1 44 0
## 2 2014-02-01 249 0.0181 0.0275 2 45 0
## 3 2014-03-01 112 0.0428 0.0408 3 47 0
## 4 2014-04-01 153 0.0408 0.0206 4 41 0
## 5 2014-05-01 150 0.0857 0.0221 5 37 0
## 6 2014-06-01 613 0.0295 0.0193 6 38 0
set.seed (1)
model_report_table4_month <- lm(immigr_report ~ (segs + crime_prop + welfare_prop + president_trump + ymd + month ), data = df_table4_month)
summary(model_report_table4_month)
##
## Call:
## lm(formula = immigr_report ~ (segs + crime_prop + welfare_prop +
## president_trump + ymd + month), data = df_table4_month)
##
## Residuals:
## Min 1Q Median 3Q Max
## -17.3864 -3.5776 -0.7535 4.0256 22.5595
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 93.529389 54.024778 1.731 0.089340 .
## segs 0.009238 0.001929 4.789 1.44e-05 ***
## crime_prop 74.085052 45.179868 1.640 0.107087
## welfare_prop 249.775586 147.552816 1.693 0.096480 .
## president_trump1 16.527402 3.953173 4.181 0.000112 ***
## ymd -0.003784 0.003284 -1.152 0.254435
## month2 4.031612 4.555194 0.885 0.380200
## month3 -4.143145 4.686286 -0.884 0.380712
## month4 -5.105065 4.663214 -1.095 0.278670
## month5 -7.575348 4.750406 -1.595 0.116846
## month6 -6.248801 4.567795 -1.368 0.177191
## month7 -8.197419 4.675910 -1.753 0.085475 .
## month8 -11.828156 4.596504 -2.573 0.012965 *
## month9 -9.222975 4.800508 -1.921 0.060190 .
## month10 -11.489039 5.078393 -2.262 0.027882 *
## month11 -7.215063 4.851096 -1.487 0.142973
## month12 -5.096368 4.987900 -1.022 0.311631
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 7.787 on 52 degrees of freedom
## Multiple R-squared: 0.7316, Adjusted R-squared: 0.6491
## F-statistic: 8.86 on 16 and 52 DF, p-value: 7.417e-10
stargazer(model_report_table4_month,
title = "Table 4 OLS",
dep.var.labels = c("Report"),
# out = "table4_ols.html", # Save to HTML file
type = "text", # You can also use "html" or "latex"
intercept.bottom = FALSE,
omit.stat = c("ser", "adj.rsq", "f", "aic"),
notes = "Note: ∗p<0.1; ∗∗p<0.05; ∗∗∗p<0.01" )
##
## Table 4 OLS
## ==================================================
## Dependent variable:
## ---------------------------------
## Report
## --------------------------------------------------
## Constant 93.529*
## (54.025)
##
## segs 0.009***
## (0.002)
##
## crime_prop 74.085
## (45.180)
##
## welfare_prop 249.776*
## (147.553)
##
## president_trump1 16.527***
## (3.953)
##
## ymd -0.004
## (0.003)
##
## month2 4.032
## (4.555)
##
## month3 -4.143
## (4.686)
##
## month4 -5.105
## (4.663)
##
## month5 -7.575
## (4.750)
##
## month6 -6.249
## (4.568)
##
## month7 -8.197*
## (4.676)
##
## month8 -11.828**
## (4.597)
##
## month9 -9.223*
## (4.801)
##
## month10 -11.489**
## (5.078)
##
## month11 -7.215
## (4.851)
##
## month12 -5.096
## (4.988)
##
## --------------------------------------------------
## Observations 69
## R2 0.732
## ==================================================
## Note: *p<0.1; **p<0.05; ***p<0.01
## Note: ∗p<0.1; ∗∗p<0.05; ∗∗∗p<0.01
daily_report <- read.csv('from_replication_files/gt_report_daily.csv')
head(daily_report)
## X date search search_adj
## 1 1 2004-01-02 0 0.0000
## 2 2 2004-01-03 0 0.0000
## 3 3 2004-01-07 43 102.1889
## 4 4 2004-01-01 0 0.0000
## 5 5 2004-01-06 0 0.0000
## 6 6 2004-01-05 0 0.0000
daily_report_table4 <-
daily_report|>
mutate( date= as.Date(date), president_trump= ifelse(date< "2017-01-01", 0, 1), president_trump = as.factor(president_trump)) |>
select(-X)
head(daily_report_table4)
## date search search_adj president_trump
## 1 2004-01-02 0 0.0000 0
## 2 2004-01-03 0 0.0000 0
## 3 2004-01-07 43 102.1889 0
## 4 2004-01-01 0 0.0000 0
## 5 2004-01-06 0 0.0000 0
## 6 2004-01-05 0 0.0000 0
head(document_topics_figure)
## date Topic1 Topic3 Topic13 year_month channel duration
## <Date> <num> <num> <num> <Date> <char> <num>
## 1: 2019-03-31 0.004481022 0.004461316 0.007756699 2019-03-01 msnbc 0.2333333
## 2: 2019-03-31 0.007721907 0.007847635 0.011589109 2019-03-01 msnbc 0.1666667
## 3: 2019-04-01 0.001990162 0.001962287 0.007677318 2019-04-01 msnbc 0.3166667
## 4: 2019-04-01 0.066536793 0.014041768 0.012310378 2019-04-01 msnbc 0.9333333
## 5: 2019-04-01 0.007608635 0.008562301 0.007243552 2019-04-01 msnbc 0.8666667
## 6: 2019-04-01 0.001472374 0.001495451 0.005285978 2019-04-01 msnbc 0.1666667
## time
## <fctr>
## 1: post-election
## 2: post-election
## 3: post-election
## 4: post-election
## 5: post-election
## 6: post-election
document_topics_table4_day <-
document_topics_figure |>
mutate(crime = Topic1 + Topic3, welfare = Topic13) |>
group_by(date) |>
summarise(
segs = n(),
crime_prop = mean(crime),
welfare_prop = mean(welfare))
head(document_topics_table4_day)
## # A tibble: 6 × 4
## date segs crime_prop welfare_prop
## <date> <int> <dbl> <dbl>
## 1 2014-01-01 8 0.00655 0.0131
## 2 2014-01-02 2 0.0338 0.0175
## 3 2014-01-03 10 0.0382 0.119
## 4 2014-01-04 7 0.00866 0.0402
## 5 2014-01-05 2 0.00511 0.00621
## 6 2014-01-07 4 0.00945 0.0141
df_table4_day <- left_join(document_topics_table4_day, daily_report_table4, by = "date")
df_table4_day <- df_table4_day |>
mutate( month = month(date), day_of_week = weekdays(date),
day_of_week = as.factor(day_of_week), month = as.factor(month))
head(df_table4_day)
## # A tibble: 6 × 9
## date segs crime_prop welfare_prop search search_adj president_trump
## <date> <int> <dbl> <dbl> <int> <dbl> <fct>
## 1 2014-01-01 8 0.00655 0.0131 36 41.2 0
## 2 2014-01-02 2 0.0338 0.0175 36 41.2 0
## 3 2014-01-03 10 0.0382 0.119 14 16.0 0
## 4 2014-01-04 7 0.00866 0.0402 49 56.1 0
## 5 2014-01-05 2 0.00511 0.00621 32 36.6 0
## 6 2014-01-07 4 0.00945 0.0141 27 30.9 0
## # ℹ 2 more variables: month <fct>, day_of_week <fct>
set.seed (1)
model_report_table4_day <- lm(search ~ (segs + crime_prop + welfare_prop + president_trump + date + day_of_week+ month ), data = df_table4_day)
summary(model_report_table4_day)
##
## Call:
## lm(formula = search ~ (segs + crime_prop + welfare_prop + president_trump +
## date + day_of_week + month), data = df_table4_day)
##
## Residuals:
## Min 1Q Median 3Q Max
## -47.879 -13.474 -1.382 11.177 61.511
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 75.806988 23.640469 3.207 0.001364 **
## segs 0.069327 0.011492 6.033 1.92e-09 ***
## crime_prop -7.910580 9.225068 -0.858 0.391266
## welfare_prop 2.722003 16.461448 0.165 0.868680
## president_trump1 6.390542 1.697190 3.765 0.000171 ***
## date -0.002146 0.001431 -1.500 0.133857
## day_of_weekMonday 1.476294 1.544505 0.956 0.339270
## day_of_weekSaturday -3.075502 1.547489 -1.987 0.047012 *
## day_of_weekSunday -5.128327 1.543934 -3.322 0.000911 ***
## day_of_weekThursday 3.129898 1.540661 2.032 0.042333 *
## day_of_weekTuesday -0.420781 1.540145 -0.273 0.784721
## day_of_weekWednesday 3.990458 1.538551 2.594 0.009565 **
## month2 2.938851 1.990265 1.477 0.139936
## month3 -4.476345 1.988542 -2.251 0.024489 *
## month4 1.549878 1.989376 0.779 0.436026
## month5 1.490120 1.994469 0.747 0.455075
## month6 4.896084 1.986827 2.464 0.013812 *
## month7 4.077213 1.969381 2.070 0.038552 *
## month8 0.218729 1.974354 0.111 0.911798
## month9 0.954531 2.063616 0.463 0.643735
## month10 1.117143 2.103139 0.531 0.595354
## month11 3.736557 2.085526 1.792 0.073338 .
## month12 6.508333 2.110788 3.083 0.002075 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 18.56 on 2007 degrees of freedom
## (5 observations deleted due to missingness)
## Multiple R-squared: 0.08452, Adjusted R-squared: 0.07448
## F-statistic: 8.422 on 22 and 2007 DF, p-value: < 2.2e-16
stargazer(model_report_table4_day,
title = "Table 4 OLS (per day)",
dep.var.labels = c("Report"),
out = "table4_ols.html", # Save to HTML file
type = "text", # You can also use "html" or "latex"
intercept.bottom = FALSE,
omit.stat = c("ser", "adj.rsq", "f", "aic"),
notes = "Note: ∗p<0.1; ∗∗p<0.05; ∗∗∗p<0.01" )
##
## Table 4 OLS (per day)
## ======================================================
## Dependent variable:
## ---------------------------------
## Report
## ------------------------------------------------------
## Constant 75.807***
## (23.640)
##
## segs 0.069***
## (0.011)
##
## crime_prop -7.911
## (9.225)
##
## welfare_prop 2.722
## (16.461)
##
## president_trump1 6.391***
## (1.697)
##
## date -0.002
## (0.001)
##
## day_of_weekMonday 1.476
## (1.545)
##
## day_of_weekSaturday -3.076**
## (1.547)
##
## day_of_weekSunday -5.128***
## (1.544)
##
## day_of_weekThursday 3.130**
## (1.541)
##
## day_of_weekTuesday -0.421
## (1.540)
##
## day_of_weekWednesday 3.990***
## (1.539)
##
## month2 2.939
## (1.990)
##
## month3 -4.476**
## (1.989)
##
## month4 1.550
## (1.989)
##
## month5 1.490
## (1.994)
##
## month6 4.896**
## (1.987)
##
## month7 4.077**
## (1.969)
##
## month8 0.219
## (1.974)
##
## month9 0.955
## (2.064)
##
## month10 1.117
## (2.103)
##
## month11 3.737*
## (2.086)
##
## month12 6.508***
## (2.111)
##
## ------------------------------------------------------
## Observations 2,030
## R2 0.085
## ======================================================
## Note: *p<0.1; **p<0.05; ***p<0.01
## Note: ∗p<0.1; ∗∗p<0.05; ∗∗∗p<0.01
Data source : https://www.dhs.gov/ohss/topics/immigration/enforcement-and-legal-processes-monthly-tables
google_term_data_report_extend <-
google_term_data_dummies |>
filter(ymd >= '2014-01-01') |>
rename( year_month = ymd) |>
select(year_month, year, month, president, immigr_report ) |>
left_join(time_lines, by = "year_month") |>
fill(time, .direction = c("down"))
head(google_term_data_report_extend)
## year_month year month president immigr_report time
## 1 2014-01-01 2014 1 obama 44 pre-election
## 2 2014-02-01 2014 2 obama 45 pre-election
## 3 2014-03-01 2014 3 obama 47 pre-election
## 4 2014-04-01 2014 4 obama 41 pre-election
## 5 2014-05-01 2014 5 obama 37 pre-election
## 6 2014-06-01 2014 6 obama 38 pre-election
google_term_data_report_extend |>
ggplot(aes(x = year_month, y = immigr_report, colour = time)) +
geom_point() + geom_smooth( se=FALSE) +
geom_vline(data = time_lines, aes(xintercept = as.numeric(year_month)), linetype = "dotted", color = "black") +
xlab("Year-month") +
ylab("Immigration Reports search count") +
ggtitle("Immigration report search on Google")
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
ice <-
read_csv("extended_research/ice_reportings.csv", skip = 4, col_names = c("year", "month", "reports", "reports_convicted", "", "", "", "reports_non_criminal", "", ""))|>
select(c(1, 2, 3, 4, 8))|>
fill(year, .direction = "down")|>
filter(month != "Total")|>
mutate(
month = match(month, month.name),
date = make_date(year, month)
)
## New names:
## Rows: 131 Columns: 10
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," chr
## (2): year, month num (8): reports, reports_convicted, ...5, ...6, ...7,
## reports_non_criminal,...
## ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
## Specify the column types or set `show_col_types = FALSE` to quiet this message.
## • `` -> `...5`
## • `` -> `...6`
## • `` -> `...7`
## • `` -> `...9`
## • `` -> `...10`
head(ice)
## # A tibble: 6 × 6
## year month reports reports_convicted reports_non_criminal date
## <chr> <int> <dbl> <dbl> <dbl> <date>
## 1 2014 10 19040 14060 4980 2014-10-01
## 2 2014 11 16190 11940 4250 2014-11-01
## 3 2014 12 15710 11630 4080 2014-12-01
## 4 2014 1 16220 12070 4150 2014-01-01
## 5 2014 2 15350 11470 3880 2014-02-01
## 6 2014 3 16310 11780 4530 2014-03-01
ice_report_w_election <-
ice |>
filter(date <= '2020-01-01') |>
rename( year_month = date) |>
# select(year_month, year, month, president, immigr_report ) |>
arrange(year_month) |>
left_join(time_lines, by = "year_month") |>
fill(time, .direction = c("down"))
head(ice_report_w_election)
## # A tibble: 6 × 7
## year month reports reports_convicted reports_non_criminal year_month time
## <chr> <int> <dbl> <dbl> <dbl> <date> <fct>
## 1 2014 1 16220 12070 4150 2014-01-01 pre-ele…
## 2 2014 2 15350 11470 3880 2014-02-01 pre-ele…
## 3 2014 3 16310 11780 4530 2014-03-01 pre-ele…
## 4 2014 4 16530 11880 4650 2014-04-01 pre-ele…
## 5 2014 5 15120 10960 4150 2014-05-01 pre-ele…
## 6 2014 6 13870 10100 3770 2014-06-01 pre-ele…
ice_report_w_election|>
ggplot(aes(x = year_month, y = reports, colour = time)) +
geom_point() + geom_smooth( se=FALSE) +
geom_vline(data = time_lines, aes(xintercept = as.numeric(year_month)), linetype = "dotted", color = "black") +
xlab("Year-month") +
ylab("Total Immigration Arrest") +
ggtitle("Total Immigration Arrest by Year")
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
ice_report_w_election|>
ggplot(aes(x = year_month, y = reports_convicted, colour = time)) +
geom_point() + geom_smooth( se=FALSE) +
geom_vline(data = time_lines, aes(xintercept = as.numeric(year_month)), linetype = "dotted", color = "black") +
xlab("Year-month") +
ylab("Convicted Immigration Arrest") +
ggtitle("Convicted Immigration Arrest by Year")
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
ice_report_w_election|>
ggplot(aes(x = year_month, y = reports_non_criminal, colour = time)) +
geom_point() + geom_smooth( se=FALSE) +
geom_vline(data = time_lines, aes(xintercept = as.numeric(year_month)), linetype = "dotted", color = "black") +
xlab("Year-month") +
ylab("Non-criminal Immigration Arrest") +
ggtitle("Non-Criminal Immigration Arrest by Year")
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
One of the Hypothesis for the paper was ““People will have more interest in reporting immigrants when they believe the government supports deportation.” that means there is more interest in immigrant denunciation when people believe that reporting will lead to some action by the government. In finding the paper suggests that, “Reporting searches (search of”how to report immigrant”) increased sharply after Trump took office and that media reporting on Trump’s immigration policies during his administration (but not during the Trump campaign) is associated with more reporting searches”
So for research we decided to look at data from Law enforcement to see if there is a change in number of arrest of immigrants during Trumps period. We used immigrant arrest data from “Office of homeland Security” for our observation.
We looked into the immigrant arrest data from 3 point of view,
Total number of immigrant arrest from January 2014 to December 2019
Number of Immigrant arrested for committing crime
Number of Immigrant arrested even without committing a crime
1) For Total number of arrest & for immigrant arrest for criminal activity:
There is higher amounts of arrests pre-campaign (highest),
a lower number during the campaign (lowest),
then a spike in numbers post-inauguration but not as high as Pre-campaign (2nd highest)
2) For number of arrest with out criminal activity: - Highest number of arrest occurred during “post-inauguration” of trump. This numbers are way higer than pre-campaign or during campaign.
This suggests that when president Trump openly gave anti-immigrant speech people’s tendency to report undocumented immigrants has increased significantly. That means people were reporting undocumented immigrants even when they are not doing any harm to anyone. This finding of ours validates the paper’s statement that because government is supporting anti-immigrant activity people are more likely to report undocumented immigrants (even with out a crime)