##panel regression----
##all data with multicollinearity accounted for
# panel_all <- plm(
#   European_performance ~
#     First_and_second +
#     First_and_CL +
#     CL_and_relegated +
#     Top_4_total_GD +
#     Average_number_of_players +
#     Average_goals_by_top_3_players +
#     Gini_coefficient,
#   data = scaled_full_data,
#   index = c("Country","season_start"),
#   effect = "twoways",
#   model = "within"
# )
# summary(panel_all)
# #compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
# coeftest(panel_all, vcov = vcovHC, type = "HC1")

# #rerun with only significant vars
# panel_all_robust <- plm(
#   European_performance ~
#     Top_4_total_GD +
#     Average_goals_by_top_3_players +
#     Gini_coefficient,
#   data = scaled_full_data,
#   index = c("Country","season_start"),
#   effect = "twoways",
#   model = "within"
# )
# summary(panel_all_robust)
# #compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
# coeftest(panel_all_robust, vcov = vcovHC, type = "HC1")

#rerun with only significant vars & theory included
panel_all_robust_theory <- plm(
  European_performance ~
    First_and_second +
    CL_and_relegated +
    Top_4_total_GD +
    Average_goals_by_top_3_players +
    Gini_coefficient,
  data = scaled_full_data,
  index = c("Country","season_start"),
  effect = "twoways",
  model = "within"
)
summary(panel_all_robust_theory)
#compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
coeftest(panel_all_robust_theory, vcov = vcovHC, type = "HC1")


##using principal components
panel_pc <- plm(
  European_performance ~
    PC1 +
    PC2 +
    PC3 +
    PC4 +
    PC5,
  data = pca_results,
  index = c("Country","season_start"),
  effect = "twoways",
  model = "within"
)
summary(panel_pc)
#compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
coeftest(panel_pc, vcov = vcovHC, type = "HC1")

# #rerun with only significant pcs
# panel_pc_robust <- plm(
#   European_performance ~
#     PC1 +
#     PC4,
#   data = pca_results,
#   index = c("Country","season_start"),
#   effect = "twoways",
#   model = "within"
# )
# summary(panel_pc_robust)
# #compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
# coeftest(panel_pc_robust, vcov = vcovHC, type = "HC1")


##using competitive indices
panel_indices_multi <- plm(
  European_performance ~
    competitive_title_index +
    elite_dominance_index +
    player_rotation_index,
  data = scaled_full_data_competitiveness_index,
  index = c("Country","season_start"),
  effect = "twoways",
  model = "within"
)
summary(panel_indices_multi)
#compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
coeftest(panel_indices_multi, vcov = vcovHC, type = "HC1")

panel_indices_title <- plm(
  European_performance ~ competitive_title_index,
  data = scaled_full_data_competitiveness_index,
  index = c("Country","season_start"),
  effect = "twoways",
  model = "within"
)
summary(panel_indices_title)
#compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
coeftest(panel_indices_title, vcov = vcovHC, type = "HC1")

panel_indices_dominance <- plm(
  European_performance ~ elite_dominance_index,
  data = scaled_full_data_competitiveness_index,
  index = c("Country","season_start"),
  effect = "twoways",
  model = "within"
)
summary(panel_indices_dominance)
#compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
coeftest(panel_indices_dominance, vcov = vcovHC, type = "HC1")

panel_indices_competitiveness <- plm(
  European_performance ~ competitive_balance_index,
  data = scaled_full_data_competitiveness_index,
  index = c("Country","season_start"),
  effect = "twoways",
  model = "within"
)
summary(panel_indices_competitiveness)
#compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
coeftest(panel_indices_competitiveness, vcov = vcovHC, type = "HC1")

panel_indices_points <- plm(
  European_performance ~ multilevel_competitiveness_index,
  data = scaled_full_data_competitiveness_index,
  index = c("Country","season_start"),
  effect = "twoways",
  model = "within"
)
summary(panel_indices_points)
#compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
coeftest(panel_indices_points, vcov = vcovHC, type = "HC1")

# panel_indices_players <- plm(
#   European_performance ~ player_rotation_index,
#   data = scaled_full_data_competitiveness_index,
#   index = c("Country","season_start"),
#   effect = "twoways",
#   model = "within"
# )
# summary(panel_indices_players)
# #compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
# coeftest(panel_indices_players, vcov = vcovHC, type = "HC1")

indices_all_plotting_data <- regression_coefficient_data(panel_indices_multi) %>%
  mutate(term = paste0(term, " (multi)")) %>%
  rbind(regression_coefficient_data(panel_indices_title)) %>%
  rbind(regression_coefficient_data(panel_indices_dominance)) %>%
  rbind(regression_coefficient_data(panel_indices_competitiveness)) %>%
  rbind(regression_coefficient_data(panel_indices_points))


##panel regression using next years European performance value----
##all data with multicollinearity accounted for
panel_all_lead <- plm(
  lead_european_performance ~
    First_and_second +
    First_and_CL +
    CL_and_relegated +
    Top_4_total_GD +
    Average_number_of_players +
    Average_goals_by_top_3_players +
    Gini_coefficient,
  data = scaled_full_data,
  index = c("Country","season_start"),
  effect = "twoways",
  model = "within"
)
summary(panel_all_lead)
#compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
coeftest(panel_all_lead, vcov = vcovHC, type = "HC1")

# #rerun with only significant vars & theory included
# panel_all_lead_robust_theory <- plm(
#   lead_european_performance ~
#     First_and_CL +
#     CL_and_relegated +
#     Top_4_total_GD +
#     Average_goals_by_top_3_players +
#     Gini_coefficient,
#   data = scaled_full_data,
#   index = c("Country","season_start"),
#   effect = "twoways",
#   model = "within"
# )
# summary(panel_all_lead_robust_theory)
# #compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
# coeftest(panel_all_lead_robust_theory, vcov = vcovHC, type = "HC1")


##using principal components
panel_lead_pc <- plm(
  lead_european_performance ~
    PC1 +
    PC2 +
    PC3 +
    PC4 +
    PC5,
  data = pca_results,
  index = c("Country","season_start"),
  effect = "twoways",
  model = "within"
)
summary(panel_lead_pc)
#compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
coeftest(panel_lead_pc, vcov = vcovHC, type = "HC1")

#rerun with only significant pcs
# panel_lead_pc_robust <- plm(
#   lead_european_performance ~
#     PC1 +
#     PC3 +
#     PC4,
#   data = pca_results,
#   index = c("Country","season_start"),
#   effect = "twoways",
#   model = "within"
# )
# summary(panel_lead_pc_robust)
# #compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
# coeftest(panel_lead_pc_robust, vcov = vcovHC, type = "HC1")


##using competitive indices
panel_indices_multi_lead <- plm(
  lead_european_performance ~
    competitive_title_index +
    elite_dominance_index +
    player_rotation_index,
  data = scaled_full_data_competitiveness_index,
  index = c("Country","season_start"),
  effect = "twoways",
  model = "within"
)
summary(panel_indices_multi_lead)
#compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
coeftest(panel_indices_multi_lead, vcov = vcovHC, type = "HC1")

# panel_indices_title_lead <- plm(
#   lead_european_performance ~ competitive_title_index,
#   data = scaled_full_data_competitiveness_index,
#   index = c("Country","season_start"),
#   effect = "twoways",
#   model = "within"
# )
# summary(panel_indices_title_lead)
# #compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
# coeftest(panel_indices_title_lead, vcov = vcovHC, type = "HC1")

panel_indices_dominance_lead <- plm(
  lead_european_performance ~ elite_dominance_index,
  data = scaled_full_data_competitiveness_index,
  index = c("Country","season_start"),
  effect = "twoways",
  model = "within"
)
summary(panel_indices_dominance_lead)
#compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
coeftest(panel_indices_dominance_lead, vcov = vcovHC, type = "HC1")

panel_indices_competitiveness_lead <- plm(
  lead_european_performance ~ competitive_balance_index,
  data = scaled_full_data_competitiveness_index,
  index = c("Country","season_start"),
  effect = "twoways",
  model = "within"
)
summary(panel_indices_competitiveness_lead)
#compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
coeftest(panel_indices_competitiveness_lead, vcov = vcovHC, type = "HC1")

# panel_indices_points_lead <- plm(
#   lead_european_performance ~ multilevel_competitiveness_index,
#   data = scaled_full_data_competitiveness_index,
#   index = c("Country","season_start"),
#   effect = "twoways",
#   model = "within"
# )
# summary(panel_indices_points_lead)
# #compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
# coeftest(panel_indices_points_lead, vcov = vcovHC, type = "HC1")

# panel_indices_players_lead <- plm(
#   lead_european_performance ~ player_rotation_index,
#   data = scaled_full_data_competitiveness_index,
#   index = c("Country","season_start"),
#   effect = "twoways",
#   model = "within"
# )
# summary(panel_indices_players_lead)
# #compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
# coeftest(panel_indices_players_lead, vcov = vcovHC, type = "HC1")

indices_lead_plotting_data <- regression_coefficient_data(panel_indices_multi_lead) %>%
  mutate(term = paste0(term, " (multi)")) %>%
  rbind(regression_coefficient_data(panel_indices_dominance_lead)) %>%
  rbind(regression_coefficient_data(panel_indices_competitiveness_lead))


##panel regression for CL----
##all data with multicollinearity accounted for
CL_scaled_data <- scaled_full_data_comp_breakdown %>% filter(competition == "CL")
panel_all_CL <- plm(
  European_performance ~
    First_and_second +
    First_and_CL +
    CL_and_relegated +
    Top_4_total_GD +
    Average_number_of_players +
    Average_goals_by_top_3_players +
    Gini_coefficient,
  data = CL_scaled_data,
  index = c("Country","season_start"),
  effect = "twoways",
  model = "within"
)
summary(panel_all_CL)
#compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
coeftest(panel_all_CL, vcov = vcovHC, type = "HC1")

#rerun with only significant vars
# panel_all_CL_robust <- plm(
#   European_performance ~
#     CL_and_relegated +
#     Top_4_total_GD +
#     Average_goals_by_top_3_players +
#     Gini_coefficient,
#   data = CL_scaled_data,
#   index = c("Country","season_start"),
#   effect = "twoways",
#   model = "within"
# )
# summary(panel_all_CL_robust)
# #compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
# coeftest(panel_all_CL_robust, vcov = vcovHC, type = "HC1")


##using principal components
CL_pca_results <- pca_results_comp_breakdown %>% filter(competition == "CL")
panel_pc_CL <- plm(
  European_performance ~
    PC1 +
    PC2 +
    PC3 +
    PC4 +
    PC5,
  data = CL_pca_results,
  index = c("Country","season_start"),
  effect = "twoways",
  model = "within"
)
summary(panel_pc_CL)
#compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
coeftest(panel_pc_CL, vcov = vcovHC, type = "HC1")

#rerun with only significant pcs
# panel_pc_CL_robust <- plm(
#   European_performance ~
#     PC1 +
#     PC3 +
#     PC4,
#   data = CL_pca_results,
#   index = c("Country","season_start"),
#   effect = "twoways",
#   model = "within"
# )
# summary(panel_pc_CL_robust)
# #compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
# coeftest(panel_pc_CL_robust, vcov = vcovHC, type = "HC1")


##using competitive indices
CL_competitive_index <- scaled_full_data_comp_breakdown_competitiveness_index %>% filter(competition == "CL")
panel_indices_multi_CL <- plm(
  European_performance ~
    competitive_title_index +
    elite_dominance_index +
    player_rotation_index,
  data = CL_competitive_index,
  index = c("Country","season_start"),
  effect = "twoways",
  model = "within"
)
summary(panel_indices_multi_CL)
#compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
coeftest(panel_indices_multi_CL, vcov = vcovHC, type = "HC1")

# panel_indices_title_CL <- plm(
#   European_performance ~ competitive_title_index,
#   data = CL_competitive_index,
#   index = c("Country","season_start"),
#   effect = "twoways",
#   model = "within"
# )
# summary(panel_indices_title_CL)
# #compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
# coeftest(panel_indices_title_CL, vcov = vcovHC, type = "HC1")

panel_indices_dominance_CL <- plm(
  European_performance ~ elite_dominance_index,
  data = CL_competitive_index,
  index = c("Country","season_start"),
  effect = "twoways",
  model = "within"
)
summary(panel_indices_dominance_CL)
#compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
coeftest(panel_indices_dominance_CL, vcov = vcovHC, type = "HC1")

panel_indices_competitiveness_CL <- plm(
  European_performance ~ competitive_balance_index,
  data = CL_competitive_index,
  index = c("Country","season_start"),
  effect = "twoways",
  model = "within"
)
summary(panel_indices_competitiveness_CL)
#compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
coeftest(panel_indices_competitiveness_CL, vcov = vcovHC, type = "HC1")

# panel_indices_points_CL <- plm(
#   European_performance ~ multilevel_competitiveness_index,
#   data = CL_competitive_index,
#   index = c("Country","season_start"),
#   effect = "twoways",
#   model = "within"
# )
# summary(panel_indices_points_CL)
# #compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
# coeftest(panel_indices_points_CL, vcov = vcovHC, type = "HC1")

# panel_indices_players_CL <- plm(
#   European_performance ~ player_rotation_index,
#   data = CL_competitive_index,
#   index = c("Country","season_start"),
#   effect = "twoways",
#   model = "within"
# )
# summary(panel_indices_players_CL)
# #compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
# coeftest(panel_indices_players_CL, vcov = vcovHC, type = "HC1")


##panel regression for EL----
##all data with multicollinearity accounted for
# EL_scaled_data <- scaled_full_data_comp_breakdown %>% filter(competition == "EL")
# panel_all_EL <- plm(
#   European_performance ~
#     First_and_second +
#     First_and_CL +
#     CL_and_relegated +
#     Top_4_total_GD +
#     Average_number_of_players +
#     Average_goals_by_top_3_players +
#     Gini_coefficient,
#   data = EL_scaled_data,
#   index = c("Country","season_start"),
#   effect = "twoways",
#   model = "within"
# )
# summary(panel_all_EL)
# #compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
# coeftest(panel_all_EL, vcov = vcovHC, type = "HC1")


##using principal components
# EL_pca_results <- pca_results_comp_breakdown %>% filter(competition == "EL")
# panel_pc_EL <- plm(
#   European_performance ~
#     PC1 +
#     PC2 +
#     PC3 +
#     PC4 +
#     PC5,
#   data = EL_pca_results,
#   index = c("Country","season_start"),
#   effect = "twoways",
#   model = "within"
# )
# summary(panel_pc_EL)
# #compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
# coeftest(panel_pc_EL, vcov = vcovHC, type = "HC1")


##using competitive indices
# EL_competitive_index <- scaled_full_data_comp_breakdown_competitiveness_index %>% filter(competition == "EL")
# panel_indices_multi_EL <- plm(
#   European_performance ~
#     competitive_title_index +
#     elite_dominance_index +
#     player_rotation_index,
#   data = EL_competitive_index,
#   index = c("Country","season_start"),
#   effect = "twoways",
#   model = "within"
# )
# summary(panel_indices_multi_EL)
# #compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
# coeftest(panel_indices_multi_EL, vcov = vcovHC, type = "HC1")

# panel_indices_title_EL <- plm(
#   European_performance ~ competitive_title_index,
#   data = EL_competitive_index,
#   index = c("Country","season_start"),
#   effect = "twoways",
#   model = "within"
# )
# summary(panel_indices_title_EL)
# #compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
# coeftest(panel_indices_title_EL, vcov = vcovHC, type = "HC1")

# panel_indices_dominance_EL <- plm(
#   European_performance ~ elite_dominance_index,
#   data = EL_competitive_index,
#   index = c("Country","season_start"),
#   effect = "twoways",
#   model = "within"
# )
# summary(panel_indices_dominance_EL)
# #compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
# coeftest(panel_indices_dominance_EL, vcov = vcovHC, type = "HC1")

# panel_indices_competitiveness_EL <- plm(
#   European_performance ~ competitive_balance_index,
#   data = EL_competitive_index,
#   index = c("Country","season_start"),
#   effect = "twoways",
#   model = "within"
# )
# summary(panel_indices_competitiveness_EL)
# #compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
# coeftest(panel_indices_competitiveness_EL, vcov = vcovHC, type = "HC1")

# panel_indices_points_EL <- plm(
#   European_performance ~ multilevel_competitiveness_index,
#   data = EL_competitive_index,
#   index = c("Country","season_start"),
#   effect = "twoways",
#   model = "within"
# )
# summary(panel_indices_points_EL)
# #compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
# coeftest(panel_indices_points_EL, vcov = vcovHC, type = "HC1")

# panel_indices_players_EL <- plm(
#   European_performance ~ player_rotation_index,
#   data = EL_competitive_index,
#   index = c("Country","season_start"),
#   effect = "twoways",
#   model = "within"
# )
# summary(panel_indices_players_EL)
# #compute clustered standard errors (adjustment for autocorrelation + heteroskedasticity)
# coeftest(panel_indices_players_EL, vcov = vcovHC, type = "HC1")

indices_comp_breakdown_plotting_data <- regression_coefficient_data(panel_indices_multi_CL) %>%
  mutate(term = paste0(term, " (CL multi)")) %>%
  rbind(regression_coefficient_data(panel_indices_dominance_CL) %>% mutate(term = paste0(term, " (CL)"))) %>%
  rbind(regression_coefficient_data(panel_indices_competitiveness_CL) %>% mutate(term = paste0(term, " (CL)")))
