float.pos = "t"
)
FE
##############################
########FEIS TEST ROBUST
##############################
##feistests
feistestfun_var_02 <- function (x, var) {
AA <- bsfeistest(
x,
robust = TRUE,
type = "bs1",
rep = 500,
terms = c("betreuungvonkindermunter3jahre")
)
chi2 <- AA$wald_feis$result$chi2
print(chi2)
}
feistestfun_var_02_full <- function (x, var) {
AA <- bsfeistest(
x,
robust = TRUE,
type = "bs1",
rep = 500,
terms = c("ganztags.betreuungsquotekleink")
)
chi2 <- AA$wald_feis$result$chi2
print(chi2)
}
feistestfun_var_35 <- function (x, var) {
AA <- bsfeistest(
x,
robust = TRUE,
type = "bs1",
rep = 500,
terms = c("betreuungvonkinderm3bis5jahre")
)
chi2 <- AA$wald_feis$result$chi2
print(chi2)
}
feistestfun_var_35_full <- function (x, var) {
AA <- bsfeistest(
x,
robust = TRUE,
type = "bs1",
rep = 500,
terms = c("ganztags.betreuungsquotevorsch")
)
chi2 <- AA$wald_feis$result$chi2
print(chi2)
}
mods_feis <-
list(feis_Germany,
feis_Ost,
feis_West,
feis_Rural,
feis_Agglo,
feis_Urban,
feis_Metro)
########################
#Artificial Regression Tests and export (multicore for performence)
########################
FE_FEIS_02 <- mclapply(mods_feis, function(x)
feistestfun_var_02(x))
FE_FEIS_02_full <-
mclapply(mods_feis, function(x)
feistestfun_var_02_full(x))
FE_FEIS_35 <- mclapply(mods_feis, function(x)
feistestfun_var_35(x))
FE_FEIS_35_full <-
mclapply(mods_feis, function(x)
feistestfun_var_35_full(x))
Temp1 <-
data.frame(
t(sapply(FE_FEIS_02, c)),
c("Germany", "East", "West", "Rural", "Agglo", "Urban", "Metro"),
"Childcare coverage 0 to 2"
)
Temp2 <-
data.frame(
t(sapply(FE_FEIS_02_full, c)),
c("Germany", "East", "West", "Rural", "Agglo", "Urban", "Metro"),
"Share of full-time slots 0 to 2"
)
colnames(Temp1) <-
c("$\\chi^2$", "df", "$P(>\\chi^2$)", "Area", "Child Care type")
colnames(Temp2) <-
c("$\\chi^2$", "df", "$P(>\\chi^2$)", "Area", "Child Care type")
########################
###Table 1
########################
Table1 <- rbind(Temp1, Temp2)
Table1
Temp3 <-
data.frame(
t(sapply(FE_FEIS_35, c)),
c("Germany", "East", "West", "Rural", "Agglo", "Urban", "Metro"),
"Childcare coverage 3 to 5"
)
Temp4 <-
data.frame(
t(sapply(FE_FEIS_35_full, c)),
c("Germany", "East", "West", "Rural", "Agglo", "Urban", "Metro"),
"Share of full-time slots 3 to 5"
)
colnames(Temp3) <-
c("$\\chi^2$", "df", "$P(>\\chi^2$)", "Area", "Child Care Type")
colnames(Temp4) <-
c("$\\chi^2$", "df", "$P(>\\chi^2$)", "Area", "Child Care Type")
########################
###Table 2
########################
Table2 <- rbind(Temp3, Temp4)
Table2
########################
###Appendix Figure A5
########################
setwd(paste0(wd))
getwd()
library(sf)
library(Rcpp)
#county layer
ot <- st_read(dsn = "vg2500_01-01.utm32s.shape/vg2500",
layer = "vg2500_krs")
ot$RS <- as.numeric(as.character(ot$ARS))
#federal state layer
otbula <- st_read(dsn = "./vg2500_01-01.utm32s.shape/vg2500",
layer = "vg2500_lan")
length(unique(inkar_long.df$kennziffer))
length(unique(ot$ARS))
#prepare kennziffer with leading zero to merge to map data
head(inkar_long.df$kennziffer)
inkar_long.df$kennziffer <- as.character(inkar_long.df$kennziffer)
inkar_long.df$kennziffer <-
ifelse(
nchar(inkar_long.df$kennziffer) < 5 ,
paste0("0", inkar_long.df$kennziffer),
inkar_long.df$kennziffer
)
head(inkar_long.df$kennziffer)
ts <- merge(
x = ot,
y = inkar_long.df,
by.x = "ARS",
by.y = "kennziffer",
all.x = T,
all.y = F
)
#re-order kreistyp for legend
ts$kreistyp_fac <- factor(ts$kreistyp_fac)
levels(ts$kreistyp_fac)
ts$kreistyp_fac <- fct_rev(ts$kreistyp_fac)
#colors
cbPalette <- c(viridis(
4,
begin = 0.15,
end = 0.95,
direction = -1
))
tm_shape(ts) +  #print
tm_fill(
col = "kreistyp_fac",
style = "cat",
# Variable
title = "Area Types",
palette = c(cbPalette),
legend.hist = FALSE
) +
tm_borders(col = "white") +
tm_layout(
legend.outside = T,
legend.outside.position = "right",
legend.text.size = 2,
legend.title.size = 3,
frame = FALSE
) +
tm_shape(otbula) +
tm_borders(col = "grey30", lwd = 1.5)
##################
#main result graphics
#################
##basic table
B <-
as.data.frame(
rbind(
cbind(
summary(fe_Germany)$coef[1:4, ],
rep("FE", 4),
rep("Germany", 4) ,
rep("1 FE Germany", 4)
),
cbind(
summary(feis_Germany)$coef[1:4, ],
rep("FEIS", 4),
rep("Germany", 4),
rep("1 FEIS Germany", 4)
),
cbind(
summary(fe_Ost)$coef[1:4, ],
rep("FE", 4),
rep("East", 4),
rep("2 FE East", 4)
),
cbind(
summary(feis_Ost)$coef[1:4, ],
rep("FEIS", 4),
rep("East", 4),
rep("2 FEIS East", 4)
),
cbind(
summary(fe_West)$coef[1:4, ],
rep("FE", 4),
rep("West", 4),
rep("3 FE West", 4)
),
cbind(
summary(feis_West)$coef[1:4, ],
rep("FEIS", 4),
rep("West", 4),
rep("3 FEIS West", 4)
),
cbind(
summary(fe_Metro)$coef[1:4, ],
rep("FE", 4),
rep("Metro", 4),
rep("2 FE Metro", 4)
),
cbind(
summary(feis_Metro)$coef[1:4, ],
rep("FEIS", 4),
rep("Metro", 4),
rep("2 FEIS Metro", 4)
),
cbind(
summary(fe_Urban)$coef[1:4, ],
rep("FE", 4),
rep("Urban", 4),
rep("3 FE Urban", 4)
),
cbind(
summary(feis_Urban)$coef[1:4, ],
rep("FEIS", 4),
rep("Urban", 4),
rep("3 FEIS Urban", 4)
),
cbind(
summary(fe_Agglo)$coef[1:4, ],
rep("FE", 4),
rep("Agglo", 4),
rep("4 FE Agglo", 4)
),
cbind(
summary(feis_Agglo)$coef[1:4, ],
rep("FEIS", 4),
rep("Agglo", 4),
rep("4 FEIS Agglo", 4)
),
cbind(
summary(fe_Rural)$coef[1:4, ],
rep("FE", 4),
rep("Rural", 4),
rep("5 FE Rural", 4)
),
cbind(
summary(feis_Rural)$coef[1:4, ],
rep("FEIS", 4),
rep("Rural", 4),
rep("5 FEIS Rural", 4)
)
)
)
B
B2 <-
cbind(B, rep(
c(
"Childcare coverage 0-2",
"Share of full-time slots 0-2",
"Childcare coverage 3-5",
"Share of full-time slots 3-5"
),
dim(B)[1] / 4
))
colnames(B2)
B2
colnames(B2)[2] <- "SE"
colnames(B2)[5] <- "Model"
colnames(B2)[6] <- "Area"
colnames(B2)[7] <- "Variable"
colnames(B2)[8] <- "Var"
B2$Estimate <- as.double(as.character(B2$Estimate))
B2$SE <- as.double(as.character(B2$SE))
temp <- B2
colnames(temp)
head(temp)
temp$Var <- as.factor(temp$Var)
levels(temp$Var)
temp$Var <- ordered(
temp$Var,
levels = c(
"Childcare coverage 0-2",
"Share of full-time slots 0-2",
"Childcare coverage 3-5",
"Share of full-time slots 3-5"
)
)
temp$Variable_new <- as.factor(paste0(temp$Area, " ",  temp$Model))
temp$Variable_new
levels(temp$Variable_new)
class(temp$Variable_new)
temp$order[grepl("Germany", temp$Variable)] <- 1
temp$order[grepl("East", temp$Variable)] <- 2
temp$order[grepl("West", temp$Variable)] <- 3
temp$order[grepl("Metro", temp$Variable)] <- 7
temp$order[grepl("Urban", temp$Variable)] <- 6
temp$order[grepl("Agglo", temp$Variable)] <- 5
temp$order[grepl("Rural", temp$Variable)] <- 4
temp$order <- as.numeric(temp$order)
temp
temp$Area <- fct_reorder(temp$Area, temp$order, min)
levels(temp$Area)
temp$Area <- fct_rev(temp$Area)
temp$Model <- fct_rev(temp$Model)
colnames(temp)[4] <- "pval"
colnames(temp)[4]
temp$pval <- as.numeric(temp$pval)
temp$sig[abs(temp$pval) < 0.05] <-  "t<0.05  *  "
temp$sig[abs(temp$pval) < 0.01] <-  "t<0.01  ** "
temp$sig[abs(temp$pval) < 0.001] <- "t<0.001 ***"
temp$alph <- 0
temp$alph[!is.na(temp$sig)] <- 1
temp
library(viridisLite)
cbPalette <-
c(
"black",
inferno(
2,
begin = 0.5,
end = 0.8,
direction = -1
),
#"white",
viridis(
4,
begin = 0.3,
end = 0.9,
direction = -1
)
)
Figure1 <-
ggplot(temp[grepl("0-2", temp$Var), ], aes(Area, Estimate)) +
geom_point(
aes(
alpha = alph,
shape = Model,
color = Area,
fill = Area
),
na.rm = TRUE,
size = 5,
position = position_dodge(width = .7)
) +
geom_point(
aes(shape = Model,
color = Area),
na.rm = TRUE,
size = 5,
stroke = 1.5,
position = position_dodge(width = .7),
show.legend = FALSE
) +
geom_errorbar(
aes(
ymin = Estimate + SE * -1.96,
ymax = Estimate + SE * 1.96,
#alpha = alph,
color = Area,
lty = Model
),
position = position_dodge(width = .7),
width = 0,
size = 1
) +
scale_alpha(range = c(0.3, 1), guide = "none") +
scale_color_manual(values = rev(cbPalette)) +
scale_fill_manual(values = rev(cbPalette), guide = "none") +
scale_shape_manual(values = c(24, 21)) +
scale_linetype_manual(values = c(1, 1), guide = "none") +
ylab("Coefficients") +
xlab("") +
theme_light(base_size = 16) +
ggforce::facet_col(vars(Var), scales = 'free', space = 'free') +
coord_flip() +
geom_hline(yintercept = 0,
lty = 1,
col = "grey40") +
geom_vline(xintercept = 4.5,
linetype = 2,
col = "grey40") +
geom_vline(xintercept = 6.5,
linetype = 2,
col = "grey40") +
guides(
shape = guide_legend(
reverse = TRUE,
override.aes = list(size = 5, stroke = 1.5),
order = 2
),
color = guide_legend(
reverse = TRUE,
override.aes = list(size = 5),
order = 1
),
type =  guide_legend(
reverse = TRUE,
override.aes = list(size = 5),
order = 3
)
) +
theme(
legend.title = element_blank(),
legend.text = element_text(size = 20),
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
axis.title = element_text(size = 20),
axis.text.y = element_text(color = "black", size = 16),
axis.text.x = element_text(color = "black", size = 16),
strip.text.x = element_text(size = 15, face = "bold.italic")
)
Figure1
Figure2 <-
ggplot(temp[grepl("3-5", temp$Var), ], aes(Area, Estimate)) +
geom_point(
aes(
alpha = alph,
shape = Model,
color = Area,
fill = Area
),
na.rm = TRUE,
size = 5,
position = position_dodge(width = .7)
) +
geom_point(
aes(shape = Model,
color = Area),
na.rm = TRUE,
size = 5,
stroke = 1.5,
position = position_dodge(width = .7),
show.legend = FALSE
) +
geom_errorbar(
aes(
ymin = Estimate + SE * -1.96,
ymax = Estimate + SE * 1.96,
#alpha = alph,
color = Area,
lty = Model
),
position = position_dodge(width = .7),
width = 0,
size = 1
) +
scale_alpha(range = c(0.3, 1), guide = "none") +
scale_color_manual(values = rev(cbPalette)) +
scale_fill_manual(values = rev(cbPalette), guide = "none") +
scale_shape_manual(values = c(24, 21)) +
scale_linetype_manual(values = c(1, 1), guide = "none") +
ylab("Coefficients") +
xlab("") +
theme_light(base_size = 16) +
ggforce::facet_col(vars(Var), scales = 'free', space = 'free') +
coord_flip() +
geom_hline(yintercept = 0,
lty = 1,
col = "grey40") +
geom_vline(xintercept = 4.5,
linetype = 2,
col = "grey40") +
geom_vline(xintercept = 6.5,
linetype = 2,
col = "grey40") +
guides(
shape = guide_legend(
reverse = TRUE,
override.aes = list(size = 5, stroke = 1.5),
order = 2
),
color = guide_legend(
reverse = TRUE,
override.aes = list(size = 5),
order = 1
),
type =  guide_legend(
reverse = TRUE,
override.aes = list(size = 5),
order = 3
)
) +
theme(
legend.title = element_blank(),
legend.text = element_text(size = 20),
# legend.position = "bottom",
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
axis.title = element_text(size = 20),
axis.text.y = element_text(color = "black", size = 16),
axis.text.x = element_text(color = "black", size = 16),
strip.text.x = element_text(size = 15, face = "bold.italic")
)
Figure2
