Build functions ———————————————————
## RegIndex_generator() creates a panel data set that contains
## a series of regulation indices according to your inputs;
## Reg_Type can be specified as "Non.S", "S", "Common", or "Mean".
## Corresp_Type can be specified as
## "soumu", "loose", "strict",
## "general_soumu", "general_loose", or "general_strict".
## Weight_Type can be specified as "Original" or "Moderate".
RegIndex_generator <- function(Reg_Type, Corresp_Type, Weight_Type){
switch(Reg_Type,
"Non.S" = {
Reg <- left_join(
PSACs %>% filter(RegType == Reg_Type),
switch(Corresp_Type,
"soumu" = {Corresp},
"loose" = {Corresp},
"strict" = {Corresp},
"general_soumu" = {Corresp_general},
"general_loose" = {Corresp_general},
"general_strict" = {Corresp_general}) %>%
filter(Corresp == Corresp_Type),
by = "Law") %>%
mutate(Law_weight = case_when(
Law_cat. == "Act" ~ 4,
Law_cat. == "Cabinet_Order" ~ 3,
Law_cat. == "Imperial_Ordinance" ~ 3,
Law_cat. == "Ministry_Ordinance" ~ 2,
Law_cat. == "Rule" ~ 2,
Law_cat. == "Notice" ~ 1),
Term_weight = switch (Weight_Type,
"Original" = case_when(
Cat. == "A" ~ 1000,
Cat. == "B" ~ 100,
Cat. == "C" ~ 10,
Cat. == "D" ~ 1),
"Moderate" = case_when(
Cat. == "A" ~ 4,
Cat. == "B" ~ 3,
Cat. == "C" ~ 2,
Cat. == "D" ~ 1)
)
) %>%
group_by(Year, Industry) %>%
summarise(Reg_Index = sum(Law_weight * Term_weight, na.rm = T))
Reg_Non.S_1995 <- Reg %>% group_by(Year, Industry) %>%
filter(Year == 1995)
Reg_Non.S <- left_join(Reg, Reg_Non.S_1995, by = "Industry",
suffix = c("", "_1995")) %>%
summarize(Industry, Reg_Index = Reg_Index/Reg_Index_1995) %>%
filter(!is.na(Industry))
},
"S" = {
Reg <- left_join(
PSACs %>% filter(RegType == Reg_Type),
switch(Corresp_Type,
"soumu" = {Corresp},
"loose" = {Corresp},
"strict" = {Corresp},
"general_soumu" = {Corresp_general},
"general_loose" = {Corresp_general},
"general_strict" = {Corresp_general}) %>%
filter(Corresp == Corresp_Type),
by = "Law") %>%
mutate(Law_weight = case_when(
Law_cat. == "Act" ~ 4,
Law_cat. == "Cabinet_Order" ~ 3,
Law_cat. == "Imperial_Ordinance" ~ 3,
Law_cat. == "Ministry_Ordinance" ~ 2,
Law_cat. == "Rule" ~ 2,
Law_cat. == "Notice" ~ 1),
Term_weight = switch (Weight_Type,
"Original" = case_when(
Cat. == "S" ~ 10000,
Cat. == "A" ~ 1000,
Cat. == "B" ~ 100,
Cat. == "C" ~ 10,
Cat. == "D" ~ 1),
"Moderate" = case_when(
Cat. == "S" ~ 5,
Cat. == "A" ~ 4,
Cat. == "B" ~ 3,
Cat. == "C" ~ 2,
Cat. == "D" ~ 1)
)
) %>%
group_by(Year, Industry) %>%
summarise(Reg_Index = sum(Law_weight * Term_weight, na.rm = T))
Reg_S_1995 <- Reg %>% group_by(Year, Industry) %>%
filter(Year == 1995)
Reg_S <- left_join(Reg, Reg_S_1995, by = "Industry",
suffix = c("", "_1995")) %>%
summarize(Industry, Reg_Index = Reg_Index/Reg_Index_1995) %>%
filter(!is.na(Industry))
},
"Common" = {
Reg <- left_join(
PSACs %>% filter(RegType == Reg_Type),
switch(Corresp_Type,
"soumu" = {Corresp},
"loose" = {Corresp},
"strict" = {Corresp},
"general_soumu" = {Corresp_general},
"general_loose" = {Corresp_general},
"general_strict" = {Corresp_general}) %>%
filter(Corresp == Corresp_Type),
by = "Law") %>%
mutate(Law_weight = case_when(
Law_cat. == "Act" ~ 4,
Law_cat. == "Cabinet_Order" ~ 3,
Law_cat. == "Imperial_Ordinance" ~ 3,
Law_cat. == "Ministry_Ordinance" ~ 2,
Law_cat. == "Rule" ~ 2,
Law_cat. == "Notice" ~ 1),
Term_weight = switch (Weight_Type,
"Original" = case_when(
Cat. == "A" ~ 1000,
Cat. == "B" ~ 100,
Cat. == "C" ~ 10,
Cat. == "D" ~ 1),
"Moderate" = case_when(
Cat. == "A" ~ 4,
Cat. == "B" ~ 3,
Cat. == "C" ~ 2,
Cat. == "D" ~ 1)
)
) %>%
group_by(Year, Industry) %>%
summarise(Reg_Index = sum(Law_weight * Term_weight, na.rm = T))
Reg_Common_1995 <- Reg %>% group_by(Year, Industry) %>%
filter(Year == 1995)
Reg_Common <- left_join(Reg, Reg_Common_1995, by = "Industry",
suffix = c("", "_1995")) %>%
summarize(Industry, Reg_Index = Reg_Index/Reg_Index_1995) %>%
filter(!is.na(Industry))
},
"Mean" = {
Reg <- left_join(
PSACs %>% filter(RegType == "Non.S"),
switch(Corresp_Type,
"soumu" = {Corresp},
"loose" = {Corresp},
"strict" = {Corresp},
"general_soumu" = {Corresp_general},
"general_loose" = {Corresp_general},
"general_strict" = {Corresp_general}) %>%
filter(Corresp == Corresp_Type),
by = "Law") %>%
mutate(Law_weight = case_when(
Law_cat. == "Act" ~ 4,
Law_cat. == "Cabinet_Order" ~ 3,
Law_cat. == "Imperial_Ordinance" ~ 3,
Law_cat. == "Ministry_Ordinance" ~ 2,
Law_cat. == "Rule" ~ 2,
Law_cat. == "Notice" ~ 1),
Term_weight = switch (Weight_Type,
"Original" = case_when(
Cat. == "A" ~ 1000,
Cat. == "B" ~ 100,
Cat. == "C" ~ 10,
Cat. == "D" ~ 1),
"Moderate" = case_when(
Cat. == "A" ~ 4,
Cat. == "B" ~ 3,
Cat. == "C" ~ 2,
Cat. == "D" ~ 1)
)
) %>%
group_by(Year, Industry) %>%
summarise(Reg_Index = sum(Law_weight * Term_weight, na.rm = T))
Reg_Non.S_1995 <- Reg %>% group_by(Year, Industry) %>%
filter(Year == 1995)
Reg_Non.S <- left_join(Reg, Reg_Non.S_1995, by = "Industry",
suffix = c("", "_1995")) %>%
summarize(Industry, Reg_Index = Reg_Index/Reg_Index_1995)
Reg_S <- left_join(
PSACs %>% filter(RegType == "S"),
switch(Corresp_Type,
"soumu" = {Corresp},
"loose" = {Corresp},
"strict" = {Corresp},
"general_soumu" = {Corresp_general},
"general_loose" = {Corresp_general},
"general_strict" = {Corresp_general}) %>%
filter(Corresp == Corresp_Type),
by = "Law") %>%
mutate(Law_weight = case_when(
Law_cat. == "Act" ~ 4,
Law_cat. == "Cabinet_Order" ~ 3,
Law_cat. == "Imperial_Ordinance" ~ 3,
Law_cat. == "Ministry_Ordinance" ~ 2,
Law_cat. == "Rule" ~ 2,
Law_cat. == "Notice" ~ 1),
Term_weight = switch (Weight_Type,
"Original" = case_when(
Cat. == "S" ~ 10000,
Cat. == "A" ~ 1000,
Cat. == "B" ~ 100,
Cat. == "C" ~ 10,
Cat. == "D" ~ 1),
"Moderate" = case_when(
Cat. == "S" ~ 5,
Cat. == "A" ~ 4,
Cat. == "B" ~ 3,
Cat. == "C" ~ 2,
Cat. == "D" ~ 1)
)
) %>%
group_by(Year, Industry) %>%
summarise(Reg_Index = sum(Law_weight * Term_weight, na.rm = T))
Reg_S_1995 <- Reg_S %>% group_by(Year, Industry) %>%
filter(Year == 1995)
Reg_S <- left_join(Reg_S, Reg_S_1995, by = "Industry",
suffix = c("", "_1995")) %>%
summarize(Industry, Reg_Index = Reg_Index/Reg_Index_1995)
Reg_Mean <- left_join(Reg_Non.S, Reg_S, by = c("Year", "Industry"),
suffix = c("_non.s", "_s")) %>%
group_by(Year, Industry) %>%
summarise(Reg_Index = (Reg_Index_non.s + Reg_Index_s)/2) %>%
filter(!is.na(Industry))
}
)
}