-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path00_collect_data.R
executable file
·221 lines (169 loc) · 7.82 KB
/
00_collect_data.R
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
## ---------------------------
pacman::p_load(tidyverse, lubridate, gtrendsR, purrr)
# collect data ------------------------------------------------------------
gTrends_bdl <- function (keywords) {
country <- "DE"
time <- c("all")
channel <- "web"
trends <- gtrends(keywords,
gprop = channel,
geo = country,
time = time,
low_search_volume = TRUE)
results <- trends$interest_over_time
results$hits <- as.character(results$hits)
return(results)
}
# define search topics & terms --------------------------------------------
topics_and_keywords <- c(
"/m/0jt3_q3", # Data Science - Field of study
# python, data scientist gehalt,
# data science / scientist jobs, machine learning,
# data analytics, big data, data analyst,
# data engineer
# ...
"/m/016jq3", # Business intelligence - topic
# power / microsoft / sap / oracle bi
# dashboard
# ...
"/g/11ckkys_95", # Tableau Software - topic
# tableau, tableau dashboard, sql
# ...
"/m/0h1fn8h", # Deepl learning - topic
# neural network, deep neural network,
# tensorflow, ai, github, keras,
# pytorch, matlab,
# deep learning vs. machine learning,
# ...
"data science", # data science - search term
"r for data science", # related search term
"python for data science",# related search term
"data engineering", # data engineering - search term
"big data", # big data - search term
"data mining", # data mining - search term
"software engineering", # software engineering - search term
"Datenwissenschaftler",
"Datenwissenschaftlerin",
"Dateningenieur",
"Dateningenieurin",
"Geschäftsintelligenz",
"/m/012_3l", # Economic growth - topic
# wirtschaftswachstum,
# wirtschaftswachstum deutschland
# gdp, gdp growth, arbeitslosenquote
# inflation, inflationsrate,
# ...
"/g/1211cg58", # Economic crisis - topic
# wirtschaftskrise, wirtschaftskrise deutschland
# finanzkrise, crisis economica
# corona wirtschaftskrise, weltwirtschaftskrise
# ...
"/m/0gmfp_7", # Economic recovery - topic
# ...
"investieren", # search query
"/m/0dgpn15", # Kurzarbeit - topic
# kurzarbeitergeld / corona / rechner
# agentur für arbeit
# kündigung kurzarbeit
# antrag kurzarbeitergeld
"/m/07s_c", # Unemployment - topic
# arbeitslos, arbeitslosigkeit, arbeitslosengeld
# deutschland arbeitslosigkeit, hartz 4
# ...
"Insolvenz" # insolvenz - search term || insolvency
)
# pull the data -----------------------------------------------------------
ts_raw <- map_dfr(.x = topics_and_keywords,
.f = gTrends_bdl)
length(unique(ts_raw$keyword))
# prep the ts DF with proper labels ---------------------------------------
ts <- ts_raw %>% mutate(
keyword = case_when(
keyword == "/m/0jt3_q3" ~ "Data_Science_field_of_study",
keyword == "/m/016jq3" ~ "Business_intelligence_topic",
keyword == "/g/11ckkys_95" ~ "Tableau_Software_topic",
keyword == "/m/0h1fn8h" ~ "Deepl_learning_topic",
keyword == "data science" ~ "data_science_search_term",
keyword == "r for data science" ~ "r_for_data_science_search_term",
keyword == "python for data science" ~ "python_for_data_science_search_term",
keyword == "data engineering" ~ "data_engineering_search_term",
keyword == "big data" ~ "big_data_search_term",
keyword == "data mining" ~ "data_mining_search_term",
keyword == "software engineering" ~ "software_engineering_search_term",
keyword == "Datenwissenschaftler" ~ "Datenwissenschaftler_search_term",
keyword == "Datenwissenschaftlerin" ~ "Datenwissenschaftlerin_search_term",
keyword == "Dateningenieur" ~ "Dateningenieur_search_term",
keyword == "Dateningenieurin" ~ "Dateningenieurin_search_term",
keyword == "Geschäftsintelligenz" ~ "Geschäftsintelligenz_search_term",
keyword == "/m/012_3l" ~ "Economic_growth_topic",
keyword == "/g/1211cg58" ~ "Economic_crisis_topic",
keyword == "/m/0gmfp_7" ~ "Economic_recovery_topic",
keyword == "investieren" ~ "investieren_search_term",
keyword == "/m/0dgpn15" ~ "Kurzarbeit(short-time-work)_topic",
keyword == "/m/07s_c" ~ "Unemployment_topic",
keyword == "Insolvenz" ~ "Insolvenz(bankruptcy)_search_term",
TRUE ~ as.character(keyword)
)
) %>%
mutate_at("hits", ~ifelse(. == "<1", 0.5, .)) %>%
mutate_at("hits", ~as.numeric(.))
length(unique(ts$keyword))
## some things are missing
## check
## what is
## missing
# outersect <- function(x, y) {
# sort(c(setdiff(x, y),
# setdiff(y, x)))
# }
#
# intersect(unique(ts_pulled$keyword), topics_and_keywords)
# outersect(unique(ts_pulled$keyword), topics_and_keywords)
# "Dateningenieur" "Dateningenieurin" "Datenwissenschaftler" "Datenwissenschaftlerin" "Geschäftsintelligenz"
## German search terms
## don't have enough data
## to show up in the results
# descriptive stats -------------------------------------------------------
ts %>% group_by(keyword) %>%
summarise(hits_mean_over_time = mean(hits),
hits_min = min(hits),
hits_max = max(hits)) %>%
arrange(desc(hits_mean_over_time))
ts$DataEcon <- ts$keyword
ts <- ts %>% mutate(
DataEcon = keyword,
DataEcon = case_when(
DataEcon == "Data_Science_field_of_study" ~ "Data",
DataEcon == "Business_intelligence_topic" ~ "Data",
DataEcon == "Tableau_Software_topic" ~ "Data",
DataEcon == "Deepl_learning_topic" ~ "Data",
DataEcon == "data_science_search_term" ~ "Data",
DataEcon == "r_for_data_science_search_term" ~ "Data",
DataEcon == "python_for_data_science_search_term" ~ "Data",
DataEcon == "data_engineering_search_term" ~ "Data",
DataEcon == "big_data_search_term" ~ "Data",
DataEcon == "data_mining_search_term" ~ "Data",
DataEcon == "software_engineering_search_term" ~ "Data",
DataEcon == "Economic_growth_topic" ~ "Economy",
DataEcon == "Economic_crisis_topic" ~ "Economy",
DataEcon == "Economic_recovery_topic" ~ "Economy",
DataEcon == "investieren_search_term" ~ "Economy",
DataEcon == "Kurzarbeit(short-time-work)_topic" ~ "Economy",
DataEcon == "Unemployment_topic" ~ "Economy",
DataEcon == "Insolvenz(bankruptcy)_search_term" ~ "Economy",
TRUE ~ as.character(DataEcon)
)
)
ts %>% group_by(keyword, DataEcon) %>%
summarise(hits_mean_over_time = mean(hits),
hits_min = min(hits),
hits_max = max(hits)) %>%
arrange(desc(hits_mean_over_time))
ts %>% group_by(DataEcon) %>%
summarise(hits_mean_over_time = mean(hits),
hits_min = min(hits),
hits_max = max(hits)) %>%
arrange(desc(hits_mean_over_time))
# save DFs ----------------------------------------------------------------
save(ts_raw, file = "data/ts_raw.RData")
save(ts, file = "data/ts_prepped.RData")