-
Notifications
You must be signed in to change notification settings - Fork 0
/
Analyses_robustness_ols_log.Rmd
450 lines (322 loc) · 18.3 KB
/
Analyses_robustness_ols_log.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
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
---
title: "Robustness checks: linear models with log-transformed variables"
author: "Ana Macanovic"
date: "2024-07-24"
---
Various linear model specifications, but including log-transformed variables of interest.
All specifications include standard errors clustered at the professor level.
Load the packages:
```{r message= F, warning = F, eval = T}
source("helper_functions.R")
packages_to_load <- c("readr", "dplyr", "tidyr",
"ggplot2", "cowplot",
"tidyverse", "RPostgres",
"lubridate", "lmtest",
"sandwich", "ggpubr",
"knitr", "scales",
"ggeffects", "flextable",
"officer", "DescTools",
"gglorenz", "corrplot")
fpackage_check(packages_to_load)
# For full reproducibility, load the packages with groundhog using the code below instead
# of the fpackage_check function
# library(groundhog)
# groundhog.library(packages_to_load, date = "2024-4-23")
```
```{r include=FALSE}
opts_chunk$set(echo = TRUE)
opts_chunk$set(eval = TRUE)
opts_chunk$set(warning = FALSE)
opts_chunk$set(message = FALSE)
```
Load the panel dataset:
```{r warning = F, message = F}
prof_panel_filter <- read_csv("panel_datasets/prof_panel_final_26_7.csv")
```
Make a list to save all the results into:
```{r}
all_reg_rob_list <- list()
```
## Main models - log-transformed variables
### Printed news attention
```{r warning = F}
news_formula_log_model <- "news_all_log ~ inferred_gender + news_all_l_log + cited_by_total_all_l_log + alt_online_all_total_l_log + alt_twitter_total_l_log +coa_tot_cited_by_total_l_log + coa_tot_online_all_total_l_log + coa_tot_twitter_total_l_log+years_since_first_pub + as.factor(year)"
news_log_model <- lm_fitter_cl_robust_scopus(panel_dataset = prof_panel_filter,
lm_formula_list = news_formula_log_model,
year_cutoff_upper = 2023,
year_cutoff_lower = 2012)
```
### Online news attention
```{r}
online_news_formula_log_model <- "alt_online_all_log ~ inferred_gender + alt_online_all_l_log + cited_by_total_all_l_log + news_all_total_l_log + alt_twitter_total_l_log +coa_tot_cited_by_total_l_log + coa_tot_online_all_total_l_log + coa_tot_twitter_total_l_log+years_since_first_pub + as.factor(year)"
online_news_log_model <- lm_fitter_cl_robust_scopus(panel_dataset = prof_panel_filter,
lm_formula = online_news_formula_log_model,
year_cutoff_upper = 2023,
year_cutoff_lower = 2012)
```
### Twitter attention models
```{r}
twitter_formula_log_model <- "alt_twitter_log ~ inferred_gender + alt_twitter_l_log + cited_by_total_all_l_log + news_all_total_l_log + alt_online_all_total_l_log +coa_tot_cited_by_total_l_log + coa_tot_online_all_total_l_log + coa_tot_twitter_total_l_log+years_since_first_pub + as.factor(year)"
twitter_log_model <- lm_fitter_cl_robust_scopus(panel_dataset = prof_panel_filter,
lm_formula_list = twitter_formula_log_model,
year_cutoff_upper = 2023,
year_cutoff_lower = 2012)
```
### Combined coefficients
Print out selected coefficients in a table:
```{r}
table_models_log <- neat_regression_table_scopus(news_log_model[[1]],
online_news_log_model[[1]],
twitter_log_model[[1]])
# add to the list
all_reg_rob_list[['linear_log']] <- table_models_log
(table_models_save <- table_models_log %>%
regulartable() %>%
set_caption("Main model - log transformed")%>%
autofit())
word_document_name <-
read_docx() %>%
body_add_flextable(table_models_save) %>%
print(target = "results/supplement_tables/main_model_table_log.docx")
```
## Main models - log-transformed variables, but last year instead of totals
### Printed news attention
```{r warning = F}
news_formula_log_model <- "news_all_log ~ inferred_gender + news_all_l_log + cited_by_l_log + alt_online_all_l_log + alt_twitter_l_log +coa_tot_cited_by_l_log + coa_tot_online_all_l_log + coa_tot_twitter_l_log+years_since_first_pub + as.factor(year)"
news_log_model <- lm_fitter_cl_robust_scopus(panel_dataset = prof_panel_filter,
lm_formula_list = news_formula_log_model,
year_cutoff_upper = 2023,
year_cutoff_lower = 2012)
```
### Online news attention
```{r}
online_news_formula_log_model <- "alt_online_all_log ~ inferred_gender + alt_online_all_l_log + cited_by_total_all_l_log + news_all_total_l_log + alt_twitter_total_l_log +coa_tot_cited_by_total_l_log + coa_tot_online_all_total_l_log + coa_tot_twitter_total_l_log+years_since_first_pub + as.factor(year)"
online_news_log_model <- lm_fitter_cl_robust_scopus(panel_dataset = prof_panel_filter,
lm_formula = online_news_formula_log_model,
year_cutoff_upper = 2023,
year_cutoff_lower = 2012)
```
### Twitter attention models
```{r}
twitter_formula_log_model <- "alt_twitter_log ~ inferred_gender + alt_twitter_l_log + cited_by_total_all_l_log + news_all_total_l_log + alt_online_all_total_l_log +coa_tot_cited_by_total_l_log + coa_tot_online_all_total_l_log + coa_tot_twitter_total_l_log+years_since_first_pub + as.factor(year)"
twitter_log_model <- lm_fitter_cl_robust_scopus(panel_dataset = prof_panel_filter,
lm_formula_list = twitter_formula_log_model,
year_cutoff_upper = 2023,
year_cutoff_lower = 2012)
```
### Combined coefficients
Print out selected coefficients in a table:
```{r}
table_models_log <- neat_regression_table_scopus(news_log_model[[1]],
online_news_log_model[[1]],
twitter_log_model[[1]])
# add to the list
all_reg_rob_list[['linear_log']] <- table_models_log
(table_models_save <- table_models_log %>%
regulartable() %>%
set_caption("Main model - log transformed")%>%
autofit())
word_document_name <-
read_docx() %>%
body_add_flextable(table_models_save) %>%
print(target = "results/supplement_tables/main_model_table_log_last_year.docx")
```
## Main models - log-transformed variables and no first lag
### Printed news attention
```{r warning = F}
news_formula_log_model <- "news_all_log ~ inferred_gender + cited_by_total_all_l_log + alt_online_all_total_l_log + alt_twitter_total_l_log +coa_tot_cited_by_total_l_log + coa_tot_online_all_total_l_log + coa_tot_twitter_total_l_log+years_since_first_pub + as.factor(year)"
news_log_model <- lm_fitter_cl_robust_scopus(panel_dataset = prof_panel_filter,
lm_formula_list = news_formula_log_model,
year_cutoff_upper = 2023,
year_cutoff_lower = 2012)
```
### Online news attention
```{r}
online_news_formula_log_model <- "alt_online_all_log ~ inferred_gender + cited_by_total_all_l_log + news_all_total_l_log + alt_twitter_total_l_log +coa_tot_cited_by_total_l_log + coa_tot_online_all_total_l_log + coa_tot_twitter_total_l_log+years_since_first_pub + as.factor(year)"
online_news_log_model <- lm_fitter_cl_robust_scopus(panel_dataset = prof_panel_filter,
lm_formula = online_news_formula_log_model,
year_cutoff_upper = 2023,
year_cutoff_lower = 2012)
```
### Twitter attention models
```{r}
twitter_formula_log_model <- "alt_twitter_log ~ inferred_gender + cited_by_total_all_l_log + news_all_total_l_log + alt_online_all_total_l_log +coa_tot_cited_by_total_l_log + coa_tot_online_all_total_l_log + coa_tot_twitter_total_l_log+years_since_first_pub + as.factor(year)"
twitter_log_model <- lm_fitter_cl_robust_scopus(panel_dataset = prof_panel_filter,
lm_formula_list = twitter_formula_log_model,
year_cutoff_upper = 2023,
year_cutoff_lower = 2012)
```
### Combined coefficients
Print out selected coefficients in a table:
```{r}
table_models_log <- neat_regression_table_scopus(news_log_model[[1]],
online_news_log_model[[1]],
twitter_log_model[[1]])
# add to the list
all_reg_rob_list[['linear_log_nolag']] <- table_models_log
(table_models_save <- table_models_log %>%
regulartable() %>%
set_caption("Main model - log transformed")%>%
autofit())
word_document_name <-
read_docx() %>%
body_add_flextable(table_models_save) %>%
print(target = "results/supplement_tables/main_model_table_log_nolag.docx")
```
## Main models - log-transformed variables excluding 2020 and 2021
### Printed news attention
```{r warning = F}
news_formula_log_model <- "news_all_log ~ inferred_gender + news_all_l_log + cited_by_total_all_l_log + alt_online_all_total_l_log + alt_twitter_total_l_log +coa_tot_cited_by_total_l_log + coa_tot_online_all_total_l_log + coa_tot_twitter_total_l_log+years_since_first_pub + as.factor(year)"
news_log_model <- lm_fitter_cl_robust_scopus(panel_dataset = prof_panel_filter_2020,
lm_formula_list = news_formula_log_model,
year_cutoff_upper = 2023,
year_cutoff_lower = 2012)
```
### Online news attention
```{r}
online_news_formula_log_model <- "alt_online_all_log ~ inferred_gender + alt_online_all_l_log + cited_by_total_all_l_log + news_all_total_l_log + alt_twitter_total_l_log +coa_tot_cited_by_total_l_log + coa_tot_online_all_total_l_log + coa_tot_twitter_total_l_log+years_since_first_pub + as.factor(year)"
online_news_log_model <- lm_fitter_cl_robust_scopus(panel_dataset = prof_panel_filter_2020,
lm_formula = online_news_formula_log_model,
year_cutoff_upper = 2023,
year_cutoff_lower = 2012)
```
### Twitter attention models
```{r}
twitter_formula_log_model <- "alt_twitter_log ~ inferred_gender + alt_twitter_l_log + cited_by_total_all_l_log + news_all_total_l_log + alt_online_all_total_l_log +coa_tot_cited_by_total_l_log + coa_tot_online_all_total_l_log + coa_tot_twitter_total_l_log+years_since_first_pub + as.factor(year)"
twitter_log_model <- lm_fitter_cl_robust_scopus(panel_dataset = prof_panel_filter_2020,
lm_formula_list = twitter_formula_log_model,
year_cutoff_upper = 2023,
year_cutoff_lower = 2012)
```
### Combined coefficients
Print out selected coefficients in a table:
```{r}
table_models_log <- neat_regression_table_scopus(news_log_model[[1]],
online_news_log_model[[1]],
twitter_log_model[[1]])
# add to the list
all_reg_rob_list[['linear_log_2019']] <- table_models_log
(table_models_save <- table_models_log %>%
regulartable() %>%
set_caption("Main model - log transformed until 2020")%>%
autofit())
word_document_name <-
read_docx() %>%
body_add_flextable(table_models_save) %>%
print(target = "results/supplement_tables/main_model_table_log_2019.docx")
```
## Main models - log-transformed excluding those who held a public post
Load data on profesors who had a public position:
```{r}
# Connect to the database:
# fill in own credentials
port <- 5432
user <- "postgres"
password <- "dutchmediaprofssql"
database_name <- "postgres"
con <- dbConnect(Postgres(),
dbname= database_name,
port = port,
user = user,
password = password)
con # Checks connection is working
public_roles <- dbReadTable(con, "govt_positions")
prof_panel_filter_public <- filter(prof_panel_filter,
! profile_id %in% public_roles$profile_id)
```
### Printed news attention
```{r warning = F}
news_formula_log_model <- "news_all_log ~ inferred_gender + news_all_l_log + cited_by_total_all_l_log + alt_online_all_total_l_log + alt_twitter_total_l_log +coa_tot_cited_by_total_l_log + coa_tot_online_all_total_l_log + coa_tot_twitter_total_l_log+years_since_first_pub + as.factor(year)"
news_model_no_public <- lm_fitter_cl_robust_scopus(panel_dataset = prof_panel_filter_public,
lm_formula = news_formula_log_model,
year_cutoff_upper = 2023,
year_cutoff_lower = 2012)
```
### Online news attention
```{r}
online_news_formula_log_model <- "alt_online_all_log ~ inferred_gender + alt_online_all_l_log + cited_by_total_all_l_log + news_all_total_l_log + alt_twitter_total_l_log +coa_tot_cited_by_total_l_log + coa_tot_online_all_total_l_log + coa_tot_twitter_total_l_log+years_since_first_pub + as.factor(year)"
online_news_model_no_public <- lm_fitter_cl_robust_scopus(panel_dataset = prof_panel_filter_public,
lm_formula = online_news_formula_log_model,
year_cutoff_upper = 2023,
year_cutoff_lower = 2012)
```
### Twitter/X
```{r}
twitter_formula_log_model <- "alt_twitter_log ~ inferred_gender + alt_twitter_l_log + cited_by_total_all_l_log + news_all_total_l_log + alt_online_all_total_l_log +coa_tot_cited_by_total_l_log + coa_tot_online_all_total_l_log + coa_tot_twitter_total_l_log+years_since_first_pub + as.factor(year)"
twitter_model_no_public <- lm_fitter_cl_robust_scopus(panel_dataset = prof_panel_filter_public,
lm_formula = twitter_formula_log_model,
year_cutoff_upper = 2023,
year_cutoff_lower = 2012)
```
### Combined coefficients
Combine this all to plot the coefficients in one plot.
```{r}
options(scipen=999)
table_models_no_public_log <- neat_regression_table_scopus(news_model_no_public[[1]],
online_news_model_no_public[[1]],
twitter_model_no_public[[1]])
# add to the list
all_reg_rob_list[['linear_no_public_log']] <- table_models_no_public_log
(table_models_save <- table_models_no_public_log %>%
regulartable() %>%
set_caption("Main model - log transformed excluding professors with positions in government")%>%
autofit())
word_document_name <-
read_docx() %>%
body_add_flextable(table_models_save) %>%
print(target = "results/supplement_tables/main_model_table_no_public_log.docx")
```
## Main models - excluding those who were an emeritus professor
Load data on profesors who had a public position:
```{r}
emeritus_roles <- dbReadTable(con, "emeritus_info")
emeritus_roles <- filter(emeritus_roles, emeritus == TRUE)
prof_panel_filter_emeritus <- filter(prof_panel_filter,
! profile_id %in% emeritus_roles$profile_id)
```
### Printed news attention
```{r warning = F}
news_formula_log_model <- "news_all_log ~ inferred_gender + news_all_l_log + cited_by_total_all_l_log + alt_online_all_total_l_log + alt_twitter_total_l_log +coa_tot_cited_by_total_l_log + coa_tot_online_all_total_l_log + coa_tot_twitter_total_l_log+years_since_first_pub + as.factor(year)"
news_model_no_emer <- lm_fitter_cl_robust_scopus(panel_dataset = prof_panel_filter_emeritus,
lm_formula = news_formula_log_model,
year_cutoff_upper = 2023,
year_cutoff_lower = 2012)
```
### Online news attention
```{r}
online_news_formula_log_model <- "alt_online_all_log ~ inferred_gender + alt_online_all_l_log + cited_by_total_all_l_log + news_all_total_l_log + alt_twitter_total_l_log +coa_tot_cited_by_total_l_log + coa_tot_online_all_total_l_log + coa_tot_twitter_total_l_log+years_since_first_pub + as.factor(year)"
online_news_model_no_emer <- lm_fitter_cl_robust_scopus(panel_dataset = prof_panel_filter_emeritus,
lm_formula = online_news_formula_log_model,
year_cutoff_upper = 2023,
year_cutoff_lower = 2012)
```
### Twitter/X
```{r}
twitter_formula_log_model <- "alt_twitter_log ~ inferred_gender + alt_twitter_l_log + cited_by_total_all_l_log + news_all_total_l_log + alt_online_all_total_l_log +coa_tot_cited_by_total_l_log + coa_tot_online_all_total_l_log + coa_tot_twitter_total_l_log+years_since_first_pub + as.factor(year)"
twitter_model_no_emer <- lm_fitter_cl_robust_scopus(panel_dataset = prof_panel_filter_emeritus,
lm_formula = twitter_formula_log_model,
year_cutoff_upper = 2023,
year_cutoff_lower = 2012)
```
### Combined coefficients
Combine this all to plot the coefficients in one plot.
```{r}
options(scipen=999)
table_models_no_emer <- neat_regression_table_scopus(news_model_no_emer[[1]],
online_news_model_no_emer[[1]],
twitter_model_no_emer[[1]])
# add to the list
all_reg_rob_list[['linear_no_emer']] <- table_models_no_emer
(table_models_save <- table_models_no_emer %>%
regulartable() %>%
set_caption("Main model - excluding professors with emeritus positions")%>%
autofit())
word_document_name <-
read_docx() %>%
body_add_flextable(table_models_save) %>%
print(target = "results/supplement_tables/main_model_table_no_emeritus_log.docx")
```
Save the list:
```{r}
saveRDS(all_reg_rob_list, "results/ols_log_models.RDS")
```