I run the main regressions allowing for non-linear effects of temperature on domestic violence.
I estimate several regressions, with different binned temperature measures (tmean, tmax, tmin…)
I save plots for all the regs
For the main reg, with bins_tmean_one, I also
save a reg table for the main reg with tmean
compute summary statistics for the estimates
plot the support of bins and save it
library(tidyverse)library(here) # path controllibrary(fixest) # estimations with fixed effectslibrary(modelsummary) # for the modelplot figurelibrary(patchwork) # assemble the plotslibrary(knitr) # for kablelibrary(tictoc)tic("Total render time")source("fun_dynamic_bins.R")# Massive regressions, take ages to run,# set memory limit v high, also uses swapmem.maxVSize(vsize =40000)
[1] 40000
data <-read_rds(here("..", "output", "data_reports.rds")) %>%filter(covid_phase =="Pre-pandemic")data <- data %>%mutate(prec_quintile =ntile(prec, 5),rh_quintile =ntile(rh, 5),wsp_quintile =ntile(wsp, 5))
Or also show a table, and save it as reg_bins_reports.tex
reg_bins_reports
Dependent Var.:
Reports
Daily Mean Temp. Bin = <11
-0.2213*** (0.0415)
Daily Mean Temp. Bin = [11,12)
-0.1432*** (0.0394)
Daily Mean Temp. Bin = [12,13)
-0.0764** (0.0292)
Daily Mean Temp. Bin = [13,14)
-0.0789*** (0.0240)
Daily Mean Temp. Bin = [14,15)
-0.0602** (0.0188)
Daily Mean Temp. Bin = [15,16)
-0.0155 (0.0153)
Daily Mean Temp. Bin = [17,18)
0.0151 (0.0139)
Daily Mean Temp. Bin = [18,19)
0.0409** (0.0155)
Daily Mean Temp. Bin = [19,20)
0.1018*** (0.0184)
Daily Mean Temp. Bin = [20,21)
0.0850*** (0.0233)
Daily Mean Temp. Bin = [21,22)
0.0981*** (0.0291)
Daily Mean Temp. Bin = >=22
0.1341*** (0.0371)
Fixed-Effects:
——————-
prec_quintile
Yes
rh_quintile
Yes
wsp_quintile
Yes
ageb
Yes
year-month
Yes
day_of_week
Yes
day_of_year
Yes
______________________________
___________________
S.E.: Clustered
by: ageb
Observations
3,624,826
Squared Cor.
0.01334
Pseudo R2
0.05616
BIC
804,317.1
I want to compute some summary stats:
sum_stats <-iplot(reg_bins_reports, only.params = T)$prms %>%as_tibble() %>%mutate(ref = estimate==0) %>%left_join(data %>%count(estimate_names = bins_tmean_one) %>%mutate(share_in_pc =100*n /sum(n))) sum_stats %>%#remove first and last, because its not a one degree jumpslice(2:(n() -1)) %>%select(estimate_names, estimate) %>%mutate(value_diff = estimate -lag(estimate),mean_diff =mean(value_diff, na.rm = T)) %>%kable()
estimate_names
estimate
value_diff
mean_diff
[11,12)
-0.1432142
NA
0.024133
[12,13)
-0.0764416
0.0667726
0.024133
[13,14)
-0.0788947
-0.0024531
0.024133
[14,15)
-0.0602501
0.0186447
0.024133
[15,16)
-0.0155372
0.0447129
0.024133
[16,17)
0.0000000
0.0155372
0.024133
[17,18)
0.0151162
0.0151162
0.024133
[18,19)
0.0408825
0.0257663
0.024133
[19,20)
0.1017882
0.0609058
0.024133
[20,21)
0.0849635
-0.0168247
0.024133
[21,22)
0.0981159
0.0131524
0.024133
I also plot the support of the temp bins and save it as reg_bins_mean_temp_distrib.png