IsTrue <- function(x) { !is.na(x) & x }
load("_data/LSCMWG_working_data.RData", verbose = TRUE)
## Loading objects:
##   data
##   codebook
##   categories
##   variables

Classification function

Classification <- function(health, gender, 
  df = data, 
  year_to_show = 1990, 
  min_to_include = 1
){
  qs <- paste("q", 1:5, sep = "") 
  vars = c(health, gender)
  df <- df[, c("country", "year", "period", vars)]
  df <- df %>% group_by(country, period) %>% 
    mutate(across(all_of(vars), ~mean(.x, na.rm = TRUE), .names = "{col}_avg"), .keep = "all")
  df <- df[df$year %in% c(seq(1965, 2015, 5), 2018), ]
  df <- df %>% group_by(year)
  df <- df %>% mutate(across(paste(vars, "avg", sep = "_"), 
                      ~quantile(.x, probs = seq(0, 1, 0.2), na.rm = TRUE)[2], .names = "{col}_q20"))
  df <- df %>% mutate(across(paste(vars, "avg", sep = "_"), 
                      ~quantile(.x, probs = seq(0, 1, 0.2), na.rm = TRUE)[3], .names = "{col}_q40"))
  df <- df %>% mutate(across(paste(vars, "avg", sep = "_"), 
                      ~quantile(.x, probs = seq(0, 1, 0.2), na.rm = TRUE)[4], .names = "{col}_q60"))
  df <- df %>% mutate(across(paste(vars, "avg", sep = "_"), 
                      ~quantile(.x, probs = seq(0, 1, 0.2), na.rm = TRUE)[5], .names = "{col}_q80"))
  df <- ungroup(df)
  df[, paste(vars, "quintile", sep = "_")] <- parallel::mclapply(vars, function(var) {
    col <- rep(NA, nrow(df))
    col[df[, paste(var, "avg", sep = "_")] < df[, paste(var, "avg_q20", sep = "_")]] <- 1
    col[df[, paste(var, "avg", sep = "_")] >= df[, paste(var, "avg_q20", sep = "_")] & 
      df[, paste(var, "avg", sep = "_")] < df[, paste(var, "avg_q40", sep = "_")]] <- 2
    col[df[, paste(var, "avg", sep = "_")] >= df[, paste(var, "avg_q40", sep = "_")] &
      df[, paste(var, "avg", sep = "_")] < df[, paste(var, "avg_q60", sep = "_")]] <- 3
    col[df[, paste(var, "avg", sep = "_")] >= df[, paste(var, "avg_q60", sep = "_")] &
      df[, paste(var, "avg", sep = "_")] < df[, paste(var, "avg_q80", sep = "_")]] <- 4
    col[df[, paste(var, "avg", sep = "_")] >= df[, paste(var, "avg_q80", sep = "_")]] <- 5
    return(col)
  })
  df <- df[, c("country", "year", "period", names(df)[str_detect(names(df), fixed("quintile"))])]
  # combis <- expand.grid(health = health, gender = gender, stringsAsFactors = FALSE)
  # combis <- split(combis, seq(nrow(combis)))
  df$health_q1 <- rowSums(df[, paste(health, "quintile", sep = "_")] == 1, na.rm = TRUE)
  df$health_q2 <- rowSums(df[, paste(health, "quintile", sep = "_")] == 2, na.rm = TRUE)
  df$health_q3 <- rowSums(df[, paste(health, "quintile", sep = "_")] == 3, na.rm = TRUE)
  df$health_q4 <- rowSums(df[, paste(health, "quintile", sep = "_")] == 4, na.rm = TRUE) 
  df$health_q5 <- rowSums(df[, paste(health, "quintile", sep = "_")] == 5, na.rm = TRUE) 
  df$gender_q1 <- rowSums(df[, paste(gender, "quintile", sep = "_")] == 1, na.rm = TRUE) 
  df$gender_q2 <- rowSums(df[, paste(gender, "quintile", sep = "_")] == 2, na.rm = TRUE) 
  df$gender_q3 <- rowSums(df[, paste(gender, "quintile", sep = "_")] == 3, na.rm = TRUE) 
  df$gender_q4 <- rowSums(df[, paste(gender, "quintile", sep = "_")] == 4, na.rm = TRUE) 
  df$gender_q5 <- rowSums(df[, paste(gender, "quintile", sep = "_")] == 5, na.rm = TRUE)
  health_vars <- paste("health", qs, sep = "_")
  gender_vars <- paste("gender", qs, sep = "_")
  df$health_valid <- rowSums(df[, health_vars])
  df$gender_valid <- rowSums(df[, gender_vars])
  df$valid <- df$health_valid * df$gender_valid
  to_keep <- c("country", "year", "period", "valid", "health_valid", "gender_valid", health_vars, gender_vars)
  df <- df[df$valid > 0, to_keep]
  health_true <- df[, health_vars] == apply(df[, health_vars], MARGIN = 1, FUN = max)
  gender_true <- df[, gender_vars] == apply(df[, gender_vars], MARGIN = 1, FUN = max)
  health_help <- health_true * matrix(1:5, nrow = nrow(health_true), ncol = 5, byrow = TRUE)
  gender_help <- gender_true * matrix(1:5, nrow = nrow(gender_true), ncol = 5, byrow = TRUE)
  help_floor <- function(set) { return(floor(mean(set[set != 0]))) }
  help_ceiling <- function(set) { return(ceiling(mean(set[set != 0]))) }
  df$health_class <- apply(health_help, MARGIN = 1, help_floor)
  df$gender_class <- apply(gender_help, MARGIN = 1, help_floor)
  df$health_class_alt <- apply(health_help, MARGIN = 1, help_ceiling)
  df$gender_class_alt <- apply(gender_help, MARGIN = 1, help_ceiling)
  df$health_flag <- ifelse(df$health_class != df$health_class_alt, 1, 0)
  df$gender_flag <- ifelse(df$gender_class != df$gender_class_alt, 1, 0)
  health_index <- paste("health_q", df$health_class, sep = "")
  gender_index <- paste("gender_q", df$gender_class, sep = "")
  df$health_n <- unlist(lapply(1:length(health_index), function(index) { 
    as.integer(df[index, health_index[index]]) 
  }))
  df$gender_n <- unlist(lapply(1:length(gender_index), function(index) { 
    as.integer(df[index, gender_index[index]]) 
  }))
  df$combi <- df$health_n * df$gender_n
  df$class <- paste("H", df$health_class, "G", df$gender_class, sep = "")
  df$class_num <-df$health_class * df$gender_class
  test <- table(df[df$year == year_to_show & df$valid >= min_to_include, c("health_class", "gender_class")])
  print(test)
  number_of_countries <- sum(test)
  df$support <- paste(df$country, " (", df$combi, "/", df$valid, ")", sep = "")
  dat <- df[df$year == year_to_show, ]
  table_to_return <- tapply(dat$support, 
                            INDEX = list(health = dat$health_class, gender = dat$gender_class), 
                            paste, collapse = "; ")
  table_to_return[is.na(table_to_return)] <- ""
  dimnames(table_to_return) <- lapply(dimnames(table_to_return), function(name) { paste("Q", name, sep = "") })
  ## from here, this is the old way, to create the fuzzy table, not needed anymore but useful for comparison
  df$H1G1 <- df$health_q1 * df$gender_q1
  df$H2G1 <- df$health_q2 * df$gender_q1
  df$H3G1 <- df$health_q3 * df$gender_q1
  df$H4G1 <- df$health_q4 * df$gender_q1
  df$H5G1 <- df$health_q5 * df$gender_q1
  df$H1G2 <- df$health_q1 * df$gender_q2
  df$H2G2 <- df$health_q2 * df$gender_q2
  df$H3G2 <- df$health_q3 * df$gender_q2
  df$H4G2 <- df$health_q4 * df$gender_q2
  df$H5G2 <- df$health_q5 * df$gender_q2
  df$H1G3 <- df$health_q1 * df$gender_q3
  df$H2G3 <- df$health_q2 * df$gender_q3
  df$H3G3 <- df$health_q3 * df$gender_q3
  df$H4G3 <- df$health_q4 * df$gender_q3
  df$H5G3 <- df$health_q5 * df$gender_q3
  df$H1G4 <- df$health_q1 * df$gender_q4
  df$H2G4 <- df$health_q2 * df$gender_q4
  df$H3G4 <- df$health_q3 * df$gender_q4
  df$H4G4 <- df$health_q4 * df$gender_q4
  df$H5G4 <- df$health_q5 * df$gender_q4
  df$H1G5 <- df$health_q1 * df$gender_q5
  df$H2G5 <- df$health_q2 * df$gender_q5
  df$H3G5 <- df$health_q3 * df$gender_q5
  df$H4G5 <- df$health_q4 * df$gender_q5
  df$H5G5 <- df$health_q5 * df$gender_q5
  vars <- c("H1G1", "H2G1", "H3G1", "H4G1", "H5G1", 
            "H1G2", "H2G2", "H3G2", "H4G2", "H5G2", 
            "H1G3", "H2G3", "H3G3", "H4G3", "H5G3", 
            "H1G4", "H2G4", "H3G4", "H4G4", "H5G4", 
            "H1G5", "H2G5", "H3G5", "H4G5", "H5G5")
  names(vars) <- vars
  dat <- as.data.frame(df[df$year == year_to_show, c("country", "valid", vars)])
  classifications <- parallel::mclapply(vars, function(var_name) {
    new <- dat[dat[, var_name] >= min_to_include, c("country", var_name, "valid")]
    countries <- new$country
    new <- paste(new[, "country"], " (", new[, var_name], "/", new[, "valid"], ")", sep = "")
    new <- new[new != " (/)"]    
    return(list(class = new, ctry = countries))
  })
  countries <- sort(unique(unlist(lapply(classifications, function(x) { x$ctry }))))
  classifications <- lapply(classifications, function(class) { class$class })
  classifications <- lapply(classifications, paste, collapse = "; ")
  # print(matrix(names(classifications), 5, 5, dimnames = list(health = qs, gender = qs)))
  fuzzy_table <- matrix(classifications, 5, 5, dimnames = list(health = qs, gender = qs))
  cat("Number of countries classified: ", number_of_countries, "\n")
  if(number_of_countries != length(countries)) {
    cat("\nNot classifying the same number of countries as the old way!")
  }
  df <- df[, !names(df) %in% vars]
  return(list(df = df, n = number_of_countries, table = table_to_return, fuzzy = fuzzy_table))  
}

Classification with two variables each on the health and gender dimensions

result <- Classification(health = variables$health, gender = variables$gender)
##             gender_class
## health_class  1  2  3  4  5
##            1 26  7  1  0  0
##            2  8 15  7  4  0
##            3  0  8 14 10  1
##            4  0  2 10 15  0
##            5  0  0  1 20  7
## Number of countries classified:  156
kableExtra::kable(result$table, format = "html") %>% 
  kableExtra::kable_styling("striped") %>% 
  kableExtra::add_header_above(c(" " = 1, "Gender" = 5)) %>% 
  kableExtra::group_rows("Health", 1, 5)
Gender
Q1 Q2 Q3 Q4 Q5
Health
Q1 Afghanistan (4/4); Angola (2/2); Bangladesh (1/4); Benin (2/4); Burkina Faso (2/2); Cameroon (1/4); Central African Republic (4/4); Chad (2/2); Congo, DRC (4/4); Cote d’Ivoire (4/4); Equatorial Guinea (2/2); Gambia (2/4); Guinea (2/2); Laos (2/4); Liberia (4/4); Madagascar (2/2); Malawi (4/4); Mali (4/4); Mozambique (4/4); Nepal (2/4); Niger (4/4); Nigeria (2/2); Sierra Leone (4/4); Tanzania (2/4); Uganda (2/4); Zambia (2/4) Bhutan (1/2); Burundi (0/4); Cambodia (0/4); Guinea-Bissau (2/2); Haiti (0/4); Pakistan (0/4); Rwanda (2/4) Somalia (2/2)
Q2 Egypt (1/4); India (2/4); Kenya (2/4); Nicaragua (1/4); Senegal (2/4); Sudan (2/4); Togo (2/4); Yemen (4/4) Bolivia (2/4); Comoros (2/2); Congo (2/4); El Salvador (2/4); Ghana (4/4); Guatemala (2/4); Indonesia (2/4); Iran (2/4); Maldives (0/4); Mauritania (4/4); Namibia (1/4); Papua New Guinea (2/4); Sao Tome & Principe (2/2); Turkey (1/4); Zimbabwe (2/4) Botswana (0/4); Dominican Republic (0/4); Eswatini (0/4); Gabon (0/4); Morocco (0/4); Myanmar (2/4); Peru (2/4) Djibouti (2/2); Kiribati (2/2); Lesotho (0/4); Mongolia (4/4)
Q3 Algeria (0/4); Cape Verde (2/2); Grenada (1/2); Honduras (0/4); Iraq (0/4); Saudi Arabia (2/4); Solomon Islands (2/2); Syria (1/4) Belize (0/4); Ecuador (2/4); Jordan (0/4); Libya (0/4); Mauritius (0/4); Mexico (2/4); Oman (2/2); Paraguay (2/4); South Africa (0/4); Suriname (2/2); Thailand (1/4); Trinidad & Tobago (1/4); Tunisia (0/4); Vanuatu (2/2) Albania (1/4); Brazil (0/4); China (1/4); Fiji (2/4); Guyana (0/4); Micronesia (2/2); Philippines (2/4); Samoa (1/2); Tonga (1/4); Viet Nam (0/4) North Korea (1/2)
Q4 Panama (2/2); Saint Lucia (2/2) Antigua & Barbuda (2/2); Bahamas (2/2); Brunei (1/4); Colombia (2/4); Costa Rica (0/4); Hungary (2/4); Jamaica (0/4); Romania (2/4); Saint Vincent & the Grenadines (2/2); Venezuela (0/4) Argentina (0/4); Bahrain (4/4); Barbados (1/4); Bulgaria (0/4); Chile (2/4); Kuwait (4/4); Lebanon (2/2); Malaysia (0/4); Poland (2/4); Qatar (1/4); Seychelles (2/2); South Korea (0/4); Sri Lanka (4/4); United Arab Emirates (0/4); Uruguay (2/4)
Q5 Cyprus (2/4) Australia (2/4); Austria (0/4); Belgium (2/4); Cuba (0/4); Denmark (0/4); Finland (0/4); France (2/4); Greece (0/4); Israel (2/4); Italy (0/4); Japan (2/4); Luxembourg (0/4); Netherlands (2/4); New Zealand (4/4); Portugal (0/4); Singapore (0/4); Spain (0/4); Switzerland (0/4); United Kingdom (2/4); United States of America (2/4) Canada (4/4); Iceland (4/4); Ireland (4/4); Malta (4/4); Norway (4/4); Sweden (4/4); Taiwan (2/2)

This is the fuzzy version of the above classification (only for illustration, not for analyses)

kableExtra::kable(result$fuzzy, format = "html") %>% 
  kableExtra::kable_styling("striped") %>% 
  kableExtra::add_header_above(c(" " = 1, "Gender" = 5)) %>% 
  kableExtra::group_rows("Health", 1, 5)
Gender
q1 q2 q3 q4 q5
Health
q1 Afghanistan (4/4); Angola (2/2); Bangladesh (1/4); Benin (2/4); Burkina Faso (2/2); Burundi (2/4); Cambodia (1/4); Cameroon (1/4); Central African Republic (4/4); Chad (2/2); Congo, DRC (4/4); Cote d’Ivoire (4/4); Equatorial Guinea (2/2); Gambia (2/4); Guinea (2/2); Haiti (2/4); Laos (2/4); Liberia (4/4); Madagascar (2/2); Malawi (4/4); Mali (4/4); Mozambique (4/4); Nepal (2/4); Niger (4/4); Nigeria (2/2); Pakistan (1/4); Sierra Leone (4/4); Tanzania (2/4); Uganda (2/4); Zambia (2/4) Bangladesh (1/4); Benin (2/4); Bhutan (1/2); Cameroon (1/4); Guinea-Bissau (2/2); Laos (2/4); Nepal (2/4); Rwanda (2/4); Tanzania (2/4); Uganda (2/4); Zambia (2/4) Burundi (2/4); Cambodia (1/4); Haiti (2/4); Pakistan (1/4); Rwanda (2/4); Somalia (2/2)
q2 Bangladesh (1/4); Cambodia (1/4); Cameroon (1/4); Egypt (1/4); Eswatini (1/4); Gabon (2/4); Gambia (2/4); India (2/4); Kenya (2/4); Maldives (2/4); Nicaragua (1/4); Pakistan (1/4); Senegal (2/4); Sudan (2/4); Togo (2/4); Yemen (4/4) Bangladesh (1/4); Bhutan (1/2); Bolivia (2/4); Botswana (1/4); Cameroon (1/4); Comoros (2/2); Congo (2/4); Dominican Republic (1/4); Egypt (1/4); El Salvador (2/4); Ghana (4/4); Guatemala (2/4); India (2/4); Indonesia (2/4); Iran (2/4); Kenya (2/4); Mauritania (4/4); Morocco (1/4); Namibia (1/4); Nicaragua (1/4); Papua New Guinea (2/4); Sao Tome & Principe (2/2); Senegal (2/4); Sudan (2/4); Togo (2/4); Turkey (1/4); Zimbabwe (2/4) Bolivia (2/4); Cambodia (1/4); El Salvador (2/4); Guatemala (2/4); Indonesia (2/4); Lesotho (2/4); Maldives (2/4); Myanmar (2/4); Namibia (1/4); Pakistan (1/4); Papua New Guinea (2/4); Peru (2/4); Turkey (1/4) Botswana (1/4); Djibouti (2/2); Dominican Republic (1/4); Kiribati (2/2); Mongolia (4/4); Morocco (1/4); Myanmar (2/4) Eswatini (1/4); Gabon (2/4); Lesotho (2/4)
q3 Algeria (2/4); Egypt (1/4); Eswatini (1/4); Honduras (2/4); Iraq (2/4); Nicaragua (1/4) Belize (1/4); Botswana (1/4); Cape Verde (2/2); Congo (2/4); Dominican Republic (1/4); Egypt (1/4); Grenada (1/2); Iran (2/4); Jordan (1/4); Libya (2/4); Mauritius (1/4); Morocco (1/4); Namibia (1/4); Nicaragua (1/4); Saudi Arabia (2/4); Solomon Islands (2/2); South Africa (2/4); Syria (1/4); Tunisia (2/4); Turkey (1/4); Zimbabwe (2/4) Brazil (2/4); Ecuador (2/4); Guyana (2/4); Iraq (2/4); Mexico (2/4); Namibia (1/4); Oman (2/2); Paraguay (2/4); Peru (2/4); Saudi Arabia (2/4); Suriname (2/2); Syria (1/4); Thailand (1/4); Trinidad & Tobago (1/4); Turkey (1/4); Vanuatu (2/2); Viet Nam (1/4) Albania (1/4); Algeria (2/4); Botswana (1/4); China (1/4); Dominican Republic (1/4); Ecuador (2/4); Fiji (2/4); Honduras (2/4); Jordan (1/4); Mauritius (1/4); Micronesia (2/2); Morocco (1/4); Paraguay (2/4); Philippines (2/4); Samoa (1/2); South Africa (2/4); Thailand (1/4); Tonga (1/4); Trinidad & Tobago (1/4) Albania (1/4); Belize (1/4); Brazil (2/4); China (1/4); Eswatini (1/4); Guyana (2/4); Libya (2/4); North Korea (1/2); Philippines (2/4); Tonga (1/4); Tunisia (2/4); Viet Nam (1/4)
q4 Belize (1/4); Costa Rica (1/4); Grenada (1/2); Jamaica (2/4); Jordan (1/4); Mauritius (1/4); Panama (2/2); Saint Lucia (2/2); Syria (1/4); Venezuela (2/4) Antigua & Barbuda (2/2); Argentina (2/4); Bahamas (2/2); Brunei (1/4); Bulgaria (1/4); Colombia (2/4); Hungary (2/4); Malaysia (1/4); Mexico (2/4); Romania (2/4); Saint Vincent & the Grenadines (2/2); South Korea (1/4); Syria (1/4); Thailand (1/4); Trinidad & Tobago (1/4); United Arab Emirates (2/4); Viet Nam (1/4) Albania (1/4); Bahrain (4/4); Barbados (1/4); Brunei (1/4); Chile (2/4); China (1/4); Colombia (2/4); Fiji (2/4); Hungary (2/4); Jordan (1/4); Kuwait (4/4); Lebanon (2/2); Mauritius (1/4); Poland (2/4); Qatar (1/4); Romania (2/4); Samoa (1/2); Seychelles (2/2); Sri Lanka (4/4); Thailand (1/4); Tonga (1/4); Trinidad & Tobago (1/4); Uruguay (2/4); Venezuela (2/4) Albania (1/4); Argentina (2/4); Barbados (1/4); Belize (1/4); Bulgaria (1/4); China (1/4); Costa Rica (1/4); Jamaica (2/4); Malaysia (1/4); North Korea (1/2); Poland (2/4); Qatar (1/4); South Korea (1/4); Tonga (1/4); United Arab Emirates (2/4); Uruguay (2/4); Viet Nam (1/4)
q5 Costa Rica (1/4) Austria (2/4); Brunei (1/4); Bulgaria (1/4); Cuba (2/4); Cyprus (2/4); Denmark (2/4); Finland (2/4); Greece (2/4); Italy (2/4); Luxembourg (2/4); Malaysia (1/4); Portugal (2/4); Singapore (2/4); South Korea (1/4); Spain (2/4); Switzerland (2/4) Australia (2/4); Barbados (1/4); Belgium (2/4); Brunei (1/4); Chile (2/4); Cyprus (2/4); France (2/4); Israel (2/4); Japan (2/4); Netherlands (2/4); New Zealand (4/4); Qatar (1/4); United Kingdom (2/4); United States of America (2/4) Australia (2/4); Austria (2/4); Barbados (1/4); Belgium (2/4); Bulgaria (1/4); Canada (4/4); Costa Rica (1/4); Cuba (2/4); Denmark (2/4); Finland (2/4); France (2/4); Greece (2/4); Iceland (4/4); Ireland (4/4); Israel (2/4); Italy (2/4); Japan (2/4); Luxembourg (2/4); Malaysia (1/4); Malta (4/4); Netherlands (2/4); Norway (4/4); Portugal (2/4); Qatar (1/4); Singapore (2/4); South Korea (1/4); Spain (2/4); Sweden (4/4); Switzerland (2/4); Taiwan (2/2); United Kingdom (2/4); United States of America (2/4)

Merging the classifications into the dataset

variables$class <- c("health_valid", "gender_valid", "health_class", "gender_class", 
                     "health_class_alt", "gender_class_alt", "health_flag", "gender_flag", 
                     "health_n", "gender_n", "class", "support")
df <- as.data.frame(result$df[, c("country", "year", "period", "class_num", variables$class)])
flagged <- df[df$year == 1990 & (df$health_flag == 1 | df$gender_flag == 1), 
              c("country", "class_num", variables$class)]
df$class_vv <- NA
df$class_vv[df$health_class < 3 & df$gender_class < 3] <- "low"
df$class_vv[df$health_class > 3 & df$gender_class > 3] <- "upp"
df$class_vv[!(df$health_class < 3 & df$gender_class < 3) & !(df$health_class > 3 & df$gender_class > 3)] <- "mid"
df$class_vv[df$class_vv == "mid" & df$health_class > df$gender_class] <- "H > G"
df$class_vv[df$class_vv == "mid" & df$health_class < df$gender_class] <- "G > H"
# addmargins(table(df$class_vv, df$class))
df$class_low <- ifelse(df$class_vv == "low", 1, 0)
df$class_upp <- ifelse(df$class_vv == "upp", 1, 0)
variables$class_core <- c("country", "class", "health_class", "gender_class", "class_vv")
class1990 <- df[df$year == 1990, variables$class_core]
names(class1990) <- c("country", paste(c("class", "health", "gender", "class_vv"), 1990, sep = ""))
class1995 <- df[df$year == 1995, variables$class_core]
names(class1995) <- c("country", paste(c("class", "health", "gender", "class_vv"), 1995, sep = ""))
df <- merge(data, df[, names(df) != "year"], by = c("country", "period"), all = TRUE)
df <- merge(df, class1990, by = "country", all.x = TRUE)
df <- merge(df, class1995, by = "country", all.x = TRUE)
df <- df[order(df$country, df$year), 
         c("country", "year", "period", names(df)[!names(df) %in% c("country", "year", "period")])]
df <- df[df$year != 1960 & df$year != 2019, ]
filepath <- paste("~/Dropbox/Lancet-SIGHT Commission/Working Groups/Metrics/Datasets/dataset_cy_class_",
                  lubridate::today(), ".csv", sep = "" )
write_csv(df, file = filepath)

Subset of 1990 classifications data for which the “floor” rule was applied

flagged

Which countries move more than 2 cells in the classifications?

names(years) <- years <- c(1990, 1995, 2015)
dat <- lapply(years, function(year) {
  df <- as.data.frame(df[df$year == year, c("country", "class_num")])
  names(df)[2] <- paste("class", year, sep = "")
  return(df)
})
dat <- Reduce(f = function(...) merge(..., by = "country", all = TRUE), x = dat)
dat$diff <- dat$class2015 - dat$class1990
dat$diff_alt <- dat$class2015 - dat$class1995
better <- dat[IsTrue(dat$diff > 2 | dat$diff_alt > 2), ]
worse <- dat[IsTrue(dat$diff < -2 | dat$diff_alt < -2), ]
better 
worse

Removing countries with untrustworthy statistics

All data is subject to measurement error. This is particularly problematic if measurement is systematically biased. Without other data to validate a given measure, this is a very difficult to problem to overcome. We only use data from reputable sources, such as academic centre and international organizations, but some self-reported data are still suspect. The World Bank and some NGOs have attempted to rate the capacity of National Statistical System, and some countries are not inlcuded in their rankings because assessments could be not be made based on available information. For instance, the ODIN rankings from 2015 to 2018 do not include the Central African Republic, Eritrea, Equatorial Guinea, and North Korea. Interestingly, among these, only North Korea is relatively highly ranked on the gender and health dimensions according to these data, which is simply not believable. Therefore, we remove only North Korea from the analyses.

df <- df[df$country != "North Korea", ]

Conflict incidence by 1995 classification groups

lapply(variables$conflict_incidence, function(var) {
  dat <- df[df$year > 1988, ]
  tbl <- tapply(dat[, var], list(health = dat$health1995, gender = dat$gender1995), mean, na.rm = TRUE)
  dat <- dat[!is.na(dat$class_vv1995) & dat$class_vv1995 != "mid", ]
  plot <- ggplot(dat, aes(x = year, y = !!sym(var), group = class_vv1995, color = class_vv1995)) + 
    stat_summary(fun="mean", geom="line", na.rm = TRUE, size = 1) + 
    xlim(1989, 2018) + 
    theme_bw() + 
    ggtitle(paste(var, " incidence by classification in 1995"))
  return(list(tbl, plot))
})

Mean growth rates by classification with t-test (alt H: mean different from global)

GrowthRatesTtest <- function(var, min_obs = 2) { 
  dat1995 <- df[df$year == 1995, c("country", "class", "health_class", "gender_class", var)]
  dat2015 <- df[df$year == 2015, c("country", var)]
  names(dat1995)[names(dat1995) != "country"] <- paste(names(dat1995)[names(dat1995) != "country"] , 
                                                       1995, sep = "_")
  names(dat2015)[names(dat2015) != "country"] <- paste(names(dat2015)[names(dat2015) != "country"] , 
                                                       2015, sep = "_")
  dat <- merge(dat1995, dat2015, by = c("country"), all = TRUE)
  dat$growth <- dat[, paste(var, 2015, sep ="_")] - dat[, paste(var, 1995, sep ="_")]
  tbl <- tapply(dat$growth, list(health = dat$health_class_1995, gender = dat$gender_class_1995), function(df) {
    if(sum(!is.na(df)) >= min_obs) {
      result <- t.test(df, mu = mean(dat$growth, na.rm = TRUE))
      mean <- round(result[["estimate"]][["mean of x"]], 2)
      pvalue <- round(result[["p.value"]], 2)
      df <- result[["parameter"]][["df"]]
      cell <- paste(mean, " (p-value ", pvalue, "; df ", df, ")", sep = "")
    } else { cell <- "" }
    return(cell)
  })
  tbl[is.na(tbl)] <- ""
  return(list(global_mean = mean(dat$growth, na.rm = TRUE), ttests = noquote(tbl)))
}
variables$outcomes <- c(variables$health_full, variables$gender_full, variables$death_rates, variables$measurement_models)
parallel::mclapply(variables$outcomes, GrowthRatesTtest)
## $imr_wpp
## $imr_wpp$global_mean
## [1] 22.86067
## 
## $imr_wpp$ttests
##       gender
## health 1                         2                           3                           4                           5                     
##      1 50.66 (p-value 0; df 28)  54.21 (p-value 0.02; df 10)                                                                               
##      2 30.62 (p-value 0.2; df 6) 30.81 (p-value 0.08; df 11) 23.66 (p-value 0.87; df 11) 21.77 (p-value 0.75; df 4)                        
##      3                           20.05 (p-value 0.22; df 7)  14.82 (p-value 0; df 18)    17.03 (p-value 0.03; df 11)                       
##      4                           5.58 (p-value 0; df 3)      6.77 (p-value 0; df 14)     9.16 (p-value 0; df 11)                           
##      5                                                       4.34 (p-value 0.03; df 1)   3.39 (p-value 0; df 22)     3.04 (p-value 0; df 4)
## 
## 
## $ufmr_wpp
## $ufmr_wpp$global_mean
## [1] 37.07946
## 
## $ufmr_wpp$ttests
##       gender
## health 1                          2                            3                           4                          5                  
##      1 93.01 (p-value 0; df 28)   104.83 (p-value 0.06; df 10)                                                                           
##      2 54.14 (p-value 0.12; df 6) 45.28 (p-value 0.2; df 11)   31.56 (p-value 0.39; df 11) 32.84 (p-value 0.42; df 4)                    
##      3                            26.61 (p-value 0.01; df 7)   18.68 (p-value 0; df 18)    20.58 (p-value 0; df 11)                      
##      4                            7.63 (p-value 0; df 3)       8.37 (p-value 0; df 14)     10.74 (p-value 0; df 11)                      
##      5                                                         6.17 (p-value 0.04; df 1)   4.18 (p-value 0; df 22)    4 (p-value 0; df 4)
## 
## 
## $life_exp_wpp
## $life_exp_wpp$global_mean
## [1] 5.835333
## 
## $life_exp_wpp$ttests
##       gender
## health 1                         2                           3                         4                          5                        
##      1 9.14 (p-value 0; df 28)   13.11 (p-value 0.06; df 10)                                                                               
##      2 5.25 (p-value 0.83; df 6) 7.3 (p-value 0.13; df 11)   2.8 (p-value 0.07; df 11) 5 (p-value 0.29; df 4)                              
##      3                           4.99 (p-value 0.25; df 7)   4.13 (p-value 0; df 18)   5.35 (p-value 0.33; df 11)                          
##      4                           1.75 (p-value 0.04; df 3)   3.59 (p-value 0; df 14)   4.66 (p-value 0.02; df 11)                          
##      5                                                       4.26 (p-value 0.22; df 1) 4.54 (p-value 0; df 22)    4.58 (p-value 0.01; df 4)
## 
## 
## $daly_ihme
## $daly_ihme$global_mean
## [1] 14551.19
## 
## $daly_ihme$ttests
##       gender
## health 1                            2                              3                             4                             5                        
##      1 47988.28 (p-value 0; df 28)  44097.91 (p-value 0; df 10)                                                                                         
##      2 21531.1 (p-value 0.26; df 6) 15662.09 (p-value 0.64; df 11) 6441.71 (p-value 0.01; df 11) 15452.03 (p-value 0.87; df 4)                          
##      3                              7955.44 (p-value 0.01; df 7)   3119.08 (p-value 0; df 18)    4205.14 (p-value 0; df 11)                             
##      4                              -3915.65 (p-value 0.01; df 3)  181.93 (p-value 0; df 14)     3659.28 (p-value 0; df 11)                             
##      5                                                             961.87 (p-value 0.1; df 1)    2197.38 (p-value 0; df 22)    3045.73 (p-value 0; df 4)
## 
## 
## $labor_mod_ratio15_ilo
## $labor_mod_ratio15_ilo$global_mean
## [1] 0.05810865
## 
## $labor_mod_ratio15_ilo$ttests
##       gender
## health 1                         2                          3                          4                          5                        
##      1 0.01 (p-value 0; df 28)   0.04 (p-value 0.26; df 10)                                                                                
##      2 0.04 (p-value 0.64; df 6) 0.04 (p-value 0.5; df 11)  0.07 (p-value 0.74; df 11) 0.02 (p-value 0.64; df 2)                           
##      3                           0.1 (p-value 0.06; df 7)   0.03 (p-value 0.11; df 18) 0.03 (p-value 0.11; df 11)                          
##      4                           0.06 (p-value 0.94; df 3)  0.08 (p-value 0.5; df 11)  0.05 (p-value 0.83; df 11)                          
##      5                                                      0.1 (p-value 0.37; df 1)   0.13 (p-value 0; df 22)    0.12 (p-value 0.11; df 4)
## 
## 
## $wmn_parl_wdi
## $wmn_parl_wdi$global_mean
## [1] NaN
## 
## $wmn_parl_wdi$ttests
##       gender
## health 1 2 3 4 5
##      1          
##      2          
##      3          
##      4          
##      5          
## 
## 
## $tfr_wpp
## $tfr_wpp$global_mean
## [1] 0.9533444
## 
## $tfr_wpp$ttests
##       gender
## health 1                          2                         3                          4                          5                     
##      1 1.36 (p-value 0.01; df 28) 1.8 (p-value 0; df 10)                                                                                
##      2 1.42 (p-value 0.01; df 6)  1.2 (p-value 0.23; df 11) 0.83 (p-value 0.39; df 11) 1.39 (p-value 0.29; df 4)                        
##      3                            1.92 (p-value 0.01; df 7) 1 (p-value 0.79; df 18)    0.51 (p-value 0; df 11)                          
##      4                            1.13 (p-value 0.64; df 3) 0.65 (p-value 0.02; df 14) 0.73 (p-value 0.26; df 11)                       
##      5                                                      -0.04 (p-value 0.05; df 1) 0.08 (p-value 0; df 22)    0.14 (p-value 0; df 4)
## 
## 
## $asfr_adol_wpp
## $asfr_adol_wpp$global_mean
## [1] 22.53888
## 
## $asfr_adol_wpp$ttests
##       gender
## health 1                          2                           3                           4                           5                     
##      1 34.17 (p-value 0; df 28)   26.25 (p-value 0.61; df 10)                                                                               
##      2 38.11 (p-value 0.05; df 6) 26.3 (p-value 0.58; df 11)  21.17 (p-value 0.84; df 11) 18.17 (p-value 0.46; df 4)                        
##      3                            32.47 (p-value 0.2; df 7)   20.92 (p-value 0.64; df 18) 19.61 (p-value 0.56; df 11)                       
##      4                            29.92 (p-value 0.44; df 3)  19.68 (p-value 0.45; df 14) 17.93 (p-value 0.14; df 11)                       
##      5                                                        12.29 (p-value 0.02; df 1)  8.02 (p-value 0; df 22)     8.36 (p-value 0; df 4)
## 
## 
## $daly_ratio_ihme
## $daly_ratio_ihme$global_mean
## [1] 0.00972674
## 
## $daly_ratio_ihme$ttests
##       gender
## health 1                          2                           3                          4                          5                        
##      1 0 (p-value 0.29; df 28)    -0.03 (p-value 0.05; df 10)                                                                                
##      2 -0.02 (p-value 0.07; df 6) -0.01 (p-value 0.21; df 11) 0.03 (p-value 0.48; df 11) -0.02 (p-value 0.01; df 4)                          
##      3                            -0.05 (p-value 0.01; df 7)  0 (p-value 0.41; df 18)    0.05 (p-value 0.08; df 11)                          
##      4                            -0.06 (p-value 0.17; df 3)  0.04 (p-value 0.11; df 14) 0.04 (p-value 0.24; df 11)                          
##      5                                                        0 (p-value 0.7; df 1)      0.04 (p-value 0; df 22)    0.05 (p-value 0.02; df 4)
## 
## 
## $mys_ratio_hdr
## $mys_ratio_hdr$global_mean
## [1] 0.09543494
## 
## $mys_ratio_hdr$ttests
##       gender
## health 1                         2                         3                          4                         5                     
##      1 0.19 (p-value 0; df 20)   0.15 (p-value 0.14; df 6)                                                                            
##      2 0.12 (p-value 0.76; df 5) 0.13 (p-value 0.24; df 9) 0.03 (p-value 0.19; df 10)                                                 
##      3                           0.19 (p-value 0.19; df 4) 0.13 (p-value 0.34; df 15) 0.03 (p-value 0; df 9)                          
##      4                                                     0.07 (p-value 0.19; df 10) 0.04 (p-value 0.07; df 9)                       
##      5                                                     0.08 (p-value 0.83; df 1)  0.05 (p-value 0; df 22)   0.02 (p-value 0; df 3)
## 
## 
## $deaths_all_int_rate
## $deaths_all_int_rate$global_mean
## [1] 1.082219
## 
## $deaths_all_int_rate$ttests
##       gender
## health 1                          2                          3                           4                           5                      
##      1 0.57 (p-value 0.76; df 28) 0.17 (p-value 0.35; df 10)                                                                                
##      2 -0.69 (p-value 0.01; df 6) -0.4 (p-value 0; df 11)    0 (p-value 0; df 11)        0.11 (p-value 0; df 4)                             
##      3                            3.18 (p-value 0.53; df 7)  -0.32 (p-value 0.04; df 18) 0.03 (p-value 0; df 11)                            
##      4                            66.08 (p-value 0.4; df 3)  -2.93 (p-value 0.07; df 14) -3.03 (p-value 0.19; df 11)                        
##      5                                                       0 (p-value 0; df 1)         0 (p-value 0; df 22)        -0.19 (p-value 0; df 4)
## 
## 
## $deaths_civilians_int_rate
## $deaths_civilians_int_rate$global_mean
## [1] 0.2311096
## 
## $deaths_civilians_int_rate$ttests
##       gender
## health 1                          2                          3                           4                           5                  
##      1 0.07 (p-value 0.51; df 28) 0.05 (p-value 0.04; df 10)                                                                            
##      2 0.07 (p-value 0.08; df 6)  0 (p-value 0; df 11)       -0.01 (p-value 0; df 11)    0.01 (p-value 0; df 4)                         
##      3                            0.3 (p-value 0.83; df 7)   0.06 (p-value 0; df 18)     0.01 (p-value 0; df 11)                        
##      4                            11.64 (p-value 0.4; df 3)  -0.17 (p-value 0.01; df 14) -0.54 (p-value 0.17; df 11)                    
##      5                                                       0 (p-value 0; df 1)         0 (p-value 0; df 22)        0 (p-value 0; df 4)
## 
## 
## $deaths_civilians_osv_rate
## $deaths_civilians_osv_rate$global_mean
## [1] -2.319773
## 
## $deaths_civilians_osv_rate$ttests
##       gender
## health 1                           2                           3                        4                           5                      
##      1 -5.45 (p-value 0.45; df 28) -6.38 (p-value 0.54; df 10)                                                                             
##      2 -0.26 (p-value 0; df 6)     0.01 (p-value 0; df 11)     0 (p-value 0; df 11)     -0.05 (p-value 0; df 4)                            
##      3                             0.32 (p-value 0; df 7)      0.05 (p-value 0; df 18)  0.02 (p-value 0; df 11)                            
##      4                             1.91 (p-value 0.11; df 3)   -0.21 (p-value 0; df 14) -18.22 (p-value 0.4; df 11)                        
##      5                                                         0 (p-value 0; df 1)      0.01 (p-value 0; df 22)     -0.06 (p-value 0; df 4)
## 
## 
## $deaths_all_nsc_rate
## $deaths_all_nsc_rate$global_mean
## [1] 0.2496955
## 
## $deaths_all_nsc_rate$ttests
##       gender
## health 1                          2                           3                          4                          5                  
##      1 0.21 (p-value 0.85; df 28) -0.56 (p-value 0.09; df 10)                                                                          
##      2 0.29 (p-value 0.88; df 6)  -0.08 (p-value 0; df 11)    -0.03 (p-value 0; df 11)   -1.02 (p-value 0.11; df 4)                    
##      3                            -0.41 (p-value 0.15; df 7)  1.05 (p-value 0.43; df 18) 0 (p-value 0; df 11)                          
##      4                            8.62 (p-value 0.4; df 3)    0 (p-value 0; df 14)       0.07 (p-value 0.02; df 11)                    
##      5                                                        0 (p-value 0; df 1)        0 (p-value 0; df 22)       0 (p-value 0; df 4)
## 
## 
## $deaths_civilians_nsc_rate
## $deaths_civilians_nsc_rate$global_mean
## [1] 0.01816283
## 
## $deaths_civilians_nsc_rate$ttests
##       gender
## health 1                           2                          3                          4                    5                  
##      1 -0.02 (p-value 0.15; df 28) 0 (p-value 0; df 10)                                                                          
##      2 0 (p-value 0; df 6)         0 (p-value 0; df 11)       0 (p-value 0; df 11)       0 (p-value 0; df 4)                     
##      3                             -0.01 (p-value 0.01; df 7) 0.11 (p-value 0.41; df 18) 0 (p-value 0; df 11)                    
##      4                             0.5 (p-value 0.41; df 3)   0 (p-value 0; df 14)       0 (p-value 0; df 11)                    
##      5                                                        0 (p-value 0; df 1)        0 (p-value 0; df 22) 0 (p-value 0; df 4)
## 
## 
## $deaths_all_ucdp_rate
## $deaths_all_ucdp_rate$global_mean
## [1] -0.9926033
## 
## $deaths_all_ucdp_rate$ttests
##       gender
## health 1                           2                           3                           4                            5                         
##      1 -4.66 (p-value 0.46; df 28) -6.77 (p-value 0.39; df 10)                                                                                    
##      2 -0.65 (p-value 0.55; df 6)  -0.5 (p-value 0.18; df 11)  -0.03 (p-value 0; df 11)    -0.95 (p-value 0.95; df 4)                             
##      3                             3.11 (p-value 0.22; df 7)   0.77 (p-value 0.24; df 18)  0.05 (p-value 0; df 11)                                
##      4                             76.7 (p-value 0.39; df 3)   -3.22 (p-value 0.33; df 14) -21.21 (p-value 0.36; df 11)                           
##      5                                                         0 (p-value 0; df 1)         0 (p-value 0; df 22)         -0.26 (p-value 0.05; df 4)
## 
## 
## $hom_odcwho_rate
## $hom_odcwho_rate$global_mean
## [1] -0.6334615
## 
## $hom_odcwho_rate$ttests
##       gender
## health 1                          2                          3                          4                           5                        
##      1                                                                                                                                       
##      2 -1.67 (p-value 0.15; df 1) 2.48 (p-value 0.31; df 1)  -8.34 (p-value 0.19; df 5)                                                      
##      3                            -2.29 (p-value 0.94; df 2) -1.31 (p-value 0.91; df 9) -3.8 (p-value 0.12; df 9)                            
##      4                            1.42 (p-value 0.65; df 1)  5.96 (p-value 0.1; df 10)  0.22 (p-value 0.49; df 6)                            
##      5                                                       -1.4 (p-value 0.57; df 1)  -0.54 (p-value 0.61; df 21) -0.4 (p-value 0.33; df 3)
## 
## 
## $latentmean_fariss
## $latentmean_fariss$global_mean
## [1] -0.5256115
## 
## $latentmean_fariss$ttests
##       gender
## health 1                          2                           3                           4                           5                         
##      1 -0.4 (p-value 0.5; df 28)  -0.3 (p-value 0.58; df 10)                                                                                    
##      2 -1.28 (p-value 0.05; df 6) -0.96 (p-value 0.09; df 11) -0.05 (p-value 0.04; df 11) -0.16 (p-value 0.38; df 3)                            
##      3                            -0.28 (p-value 0.13; df 6)  -0.46 (p-value 0.77; df 18) -0.33 (p-value 0.3; df 11)                            
##      4                            0 (p-value 0.51; df 3)      -0.71 (p-value 0.54; df 14) -0.64 (p-value 0.79; df 11)                           
##      5                                                        -0.63 (p-value 0.39; df 1)  -0.45 (p-value 0.57; df 22) -0.66 (p-value 0.65; df 4)
## 
## 
## $v2cltort
## $v2cltort$global_mean
## [1] -0.2589878
## 
## $v2cltort$ttests
##       gender
## health 1                           2                           3                           4                           5                         
##      1 -0.18 (p-value 0.72; df 28) -0.08 (p-value 0.51; df 10)                                                                                   
##      2 -0.71 (p-value 0.2; df 6)   -0.97 (p-value 0.13; df 10) -0.16 (p-value 0.68; df 11) -0.13 (p-value 0.89; df 2)                            
##      3                             -0.37 (p-value 0.54; df 7)  -0.61 (p-value 0.16; df 17) -0.54 (p-value 0.15; df 10)                           
##      4                             0.24 (p-value 0.52; df 1)   0.01 (p-value 0.43; df 10)  0.11 (p-value 0.17; df 10)                            
##      5                                                         -0.26 (p-value 0.99; df 1)  -0.02 (p-value 0.06; df 20) -0.12 (p-value 0.44; df 4)
## 
## 
## $v2clkill
## $v2clkill$global_mean
## [1] -0.2952073
## 
## $v2clkill$ttests
##       gender
## health 1                           2                           3                           4                           5                         
##      1 -0.42 (p-value 0.58; df 28) -0.37 (p-value 0.72; df 10)                                                                                   
##      2 -0.72 (p-value 0.29; df 6)  -0.86 (p-value 0.24; df 10) -0.07 (p-value 0.33; df 11) 0.1 (p-value 0.63; df 2)                              
##      3                             -0.17 (p-value 0.58; df 7)  -0.28 (p-value 0.94; df 17) -0.38 (p-value 0.74; df 10)                           
##      4                             0.62 (p-value 0.49; df 1)   -0.23 (p-value 0.79; df 10) -0.18 (p-value 0.71; df 10)                           
##      5                                                         -0.58 (p-value 0.35; df 1)  -0.04 (p-value 0.02; df 20) -0.23 (p-value 0.78; df 4)
## 
## 
## $v2caviol
## $v2caviol$global_mean
## [1] -0.1098632
## 
## $v2caviol$ttests
##       gender
## health 1                          2                         3                          4                          5                         
##      1 0.17 (p-value 0.47; df 14) 0.36 (p-value 0.11; df 5)                                                                                 
##      2 -1.04 (p-value 0.19; df 4) 0.12 (p-value 0.65; df 7) 0.09 (p-value 0.51; df 5)  -0.33 (p-value 0.32; df 1)                           
##      3                            0.15 (p-value 0.75; df 2) 0.33 (p-value 0.47; df 11) -0.35 (p-value 0.42; df 6)                           
##      4                                                      0.05 (p-value 0.82; df 7)  -0.6 (p-value 0.39; df 5)                            
##      5                                                      -0.69 (p-value 0.18; df 1) -0.72 (p-value 0.2; df 8)  -0.33 (p-value 0.24; df 4)

Preparing cross-sectional dataset

covariates <- c("pc_rgdpe_avg", "life_exp_wpp", "imr_wpp", "mys_ratio_hdr", "asfr_adol_wpp")
vars <- unlist(lapply(covariates, function(var) { names(df)[str_detect(names(df), var)] }))
vars <- vars[vars != "pasfr_adol_wpp"]
include <- c("country", "class", "class_vv", "class_low", "class_upp", vars)
new1990 <- df[df$year == 1990, c(include, variables$death_rates, variables$measurement_models)]
new1995 <- df[df$year == 1995, c(include, variables$death_rates, variables$measurement_models, 
  paste(variables$conflict_incidence, "cumulative1989", sep = "_"),
  paste(variables$political, "cumulative1991", sep = "_"))]
new2015 <- df[df$year == 2015, c(include, 
  paste(c(variables$death_rates, variables$measurement_models), "cumulative1991", sep = "_"),
  paste(c(variables$death_rates, variables$measurement_models), "cumulative1996", sep = "_"),
  paste(variables$conflict_incidence, "cumulative1991", sep = "_"),
  paste(variables$conflict_incidence, "cumulative1996", sep = "_"),
  paste(variables$political, "cumulative1991", sep = "_"),
  paste(variables$political, "cumulative1996", sep = "_"))]
names(new1990)[names(new1990) != "country"] <- paste(names(new1990)[names(new1990) != "country"], "1990", sep = "_")
names(new1995)[names(new1995) != "country"] <- paste(names(new1995)[names(new1995) != "country"], "1995", sep = "_")
names(new2015)[names(new2015) != "country"] <- paste(names(new2015)[names(new2015) != "country"], "2015", sep = "_")
new <- merge(new1990, new1995, by = c("country"), all = TRUE)
new <- merge(new, new2015, by = c("country"), all = TRUE)
## growth vars 
new$pc_rgdpe_avg_growth1990_2015 <- new$pc_rgdpe_avg_2015 - new$pc_rgdpe_avg_1990
new$life_exp_wpp_growth1990_2015 <- new$life_exp_wpp_2015 - new$life_exp_wpp_1990
new$imr_wpp_growth1990_2015 <- new$imr_wpp_2015 - new$imr_wpp_1990
new$mys_ratio_hdr_growth1990_2015 <- new$mys_ratio_hdr_2015 - new$mys_ratio_hdr_1990
new$asfr_adol_wpp_growth1990_2015 <- new$asfr_adol_wpp_2015 - new$asfr_adol_wpp_1990
new$pc_rgdpe_avg_growth1995_2015 <- new$pc_rgdpe_avg_2015 - new$pc_rgdpe_avg_1995
new$life_exp_wpp_growth1995_2015 <- new$life_exp_wpp_2015 - new$life_exp_wpp_1995
new$imr_wpp_growth1995_2015 <- new$imr_wpp_2015 - new$imr_wpp_1995
new$mys_ratio_hdr_growth1995_2015 <- new$mys_ratio_hdr_2015 - new$mys_ratio_hdr_1995
new$asfr_adol_wpp_growth1995_2015 <- new$asfr_adol_wpp_2015 - new$asfr_adol_wpp_1995
## logged version of pcGDP growth vars; need to account for negative values
new$lg_pc_rgdpe_avg_growth1990_2015[IsTrue(new$pc_rgdpe_avg_growth1990_2015 < 0)] <- log(-new$pc_rgdpe_avg_growth1990_2015[IsTrue(new$pc_rgdpe_avg_growth1990_2015 < 0)])
new$lg_pc_rgdpe_avg_growth1990_2015[IsTrue(new$pc_rgdpe_avg_growth1990_2015 >= 0)] <- log(new$pc_rgdpe_avg_growth1990_2015[IsTrue(new$pc_rgdpe_avg_growth1990_2015 >= 0)])
new$lg_pc_rgdpe_avg_growth1995_2015[IsTrue(new$pc_rgdpe_avg_growth1995_2015 < 0)] <- log(-new$pc_rgdpe_avg_growth1995_2015[IsTrue(new$pc_rgdpe_avg_growth1995_2015 < 0)])
new$lg_pc_rgdpe_avg_growth1995_2015[IsTrue(new$pc_rgdpe_avg_growth1995_2015 >= 0)] <- log(new$pc_rgdpe_avg_growth1995_2015[IsTrue(new$pc_rgdpe_avg_growth1995_2015 >= 0)])
CodePerformance <- function(y_var, x_vars, show = FALSE, prefix = "perf") {
  x_vars <- paste(x_vars, collapse = " + ")
  equation <- paste(y_var, " ~ ", x_vars, sep = "")
  df <- na.omit(get_all_vars(formula = equation, data = new, country = country))
  mod <- lm(formula = equation, data = df)
  df$predicted <- predict(mod)
  df[, paste(prefix, y_var, sep = "_")] <- df[, y_var] - df$predicted
  if(show) print(df)
  return(invisible(df[, c("country", paste(prefix, y_var, sep = "_"))]))
}
performance_measures <- unlist(lapply(c(1990, 1995), function(year) {
  unlist(lapply(covariates[2:5], function(var) {
    return(list(
      CodePerformance(y_var = paste(var, "_growth", year, "_2015", sep = ""), 
                      x_vars = paste(c(paste("lg", var, sep = "_"), "lg_pc_rgdpe_avg"), year, sep = "_")),
      CodePerformance(y_var = paste(var, "_growth", year, "_2015", sep = ""), 
                      x_vars = c(paste(c(paste("lg", var, sep = "_"), "lg_pc_rgdpe_avg"), year, sep = "_"),
                                 paste("lg_pc_rgdpe_avg_growth", year, "_2015", sep = "")), prefix = "perfv2")
    ))
  }), recursive = FALSE)
}), recursive = FALSE)
performance_measures <- Reduce(f = function(...) merge(..., by = "country", all = TRUE), x = performance_measures)
new <- merge(new, performance_measures, by = "country", all = TRUE)
# filepath <- paste("~/Dropbox/Lancet-SIGHT Commission/Working Groups/Metrics/Datasets/dataset_crosssectional_", lubridate::today(), ".csv", sep = "" )
# write.csv(new, file = filepath)

Performance Rankings in classification groups

Performance <- function(category, year, vars) {
  countries <- unique(df$country[df$year == year & df$class_vv %in% category])
  countries <- countries[!is.na(countries)]
  lapply(vars, function(var) {
    var <- paste(var, "_growth", year, "_2015", sep = "")
    # other <- paste(c("deaths_all_ucdp_rate_cumulative"), year + 1, "_2015", sep = "")
    other <- NULL
    select_vars <- c("country", var, paste("perf", var, sep = "_"), other)
    # select_vars[!select_vars %in% names(new)]
    dat <- new[new$country %in% countries, select_vars]
    dat[order(dat[, var], decreasing = TRUE, na.last = NA), ]
  })
}

Low classification

Performance(category = "low", year = 1995, vars = c(variables$health, variables$gender))
## $life_exp_wpp
##                      country life_exp_wpp_growth1995_2015 perf_life_exp_wpp_growth1995_2015
## 146                   Rwanda                        44.00                        15.6370726
## 60                  Ethiopia                        15.63                         5.6604691
## 187                   Uganda                        14.94                         2.7052494
## 20                    Bhutan                        14.60                         5.8882904
## 99                   Liberia                        14.53                         3.9591625
## 129                    Niger                        14.15                         2.3535015
## 158             Sierra Leone                        13.86                        -2.8115245
## 106                   Malawi                        13.42                         1.8763556
## 29                  Cambodia                        13.34                         5.3515806
## 108                 Maldives                        13.05                         7.0621836
## 200                   Zambia                        12.93                         1.4358004
## 57                   Eritrea                        12.65                                NA
## 5                     Angola                        12.50                        -0.4680210
## 125                    Nepal                        12.05                         5.0213484
## 28                   Burundi                        11.89                         1.0646711
## 105               Madagascar                        11.84                         3.1958062
## 21                   Bolivia                        11.60                         4.1372284
## 177                 Tanzania                        11.24                         1.4725698
## 95                      Laos                        11.06                         3.0239962
## 14                Bangladesh                        10.89                         4.8788380
## 1                Afghanistan                        10.36                                NA
## 152      Sao Tome & Principe                        10.24                         3.5484075
## 184                   Turkey                        10.10                         3.9775386
## 163                  Somalia                         9.90                                NA
## 109                     Mali                         9.66                        -1.3164510
## 27              Burkina Faso                         9.38                        -0.5357478
## 120                  Morocco                         9.06                         4.0079560
## 71                 Guatemala                         8.85                         3.1101402
## 79                     India                         8.65                         2.3663202
## 40                Congo, DRC                         8.51                        -1.3812439
## 154                  Senegal                         8.15                         0.7260010
## 73             Guinea-Bissau                         8.03                        -3.0481911
## 39                     Congo                         7.94                        -0.8249882
## 121               Mozambique                         7.92                        -2.7344273
## 198                    Yemen                         7.81                         2.0166379
## 170                    Sudan                         7.76                         0.2364652
## 139                     Peru                         7.48                         3.1433549
## 65                    Gambia                         7.42                        -1.9827570
## 90                     Kenya                         7.26                        -0.8033107
## 80                 Indonesia                         6.70                         0.8808579
## 72                    Guinea                         6.69                        -3.6054338
## 162          Solomon Islands                         6.64                                NA
## 56         Equatorial Guinea                         6.55                        -3.8326236
## 75                     Haiti                         6.38                        -1.2937167
## 130                  Nigeria                         6.08                        -4.8908092
## 137         Papua New Guinea                         5.42                                NA
## 54                     Egypt                         5.39                         0.6098402
## 133                 Pakistan                         5.20                        -1.0735387
## 34                      Chad                         5.09                        -6.0253812
## 38                   Comoros                         5.01                        -2.6493475
## 19                     Benin                         4.79                        -2.8871802
## 68                     Ghana                         4.04                        -3.4379136
## 30                  Cameroon                         3.68                        -5.7480138
## 180                     Togo                         3.30                        -4.2557120
## 112               Mauritania                         3.06                        -3.2304180
## 201                 Zimbabwe                         2.27                        -7.1765434
## 42             Cote d'Ivoire                         1.97                        -7.4877519
## 33  Central African Republic                         0.79                        -9.8151182
## 59                  Eswatini                       -10.23                       -17.5566949
## 
## $imr_wpp
##                      country imr_wpp_growth1995_2015 perf_imr_wpp_growth1995_2015
## 146                   Rwanda                 156.846                  101.3413533
## 99                   Liberia                  95.964                   42.3460134
## 121               Mozambique                  75.594                   24.1016319
## 106                   Malawi                  74.605                   26.1920456
## 129                    Niger                  73.804                   24.4098564
## 60                  Ethiopia                  68.205                   20.0570134
## 5                     Angola                  66.809                   18.5152058
## 158             Sierra Leone                  65.676                   14.4822822
## 200                   Zambia                  63.350                   16.3859298
## 105               Madagascar                  63.279                   18.7583253
## 72                    Guinea                  62.458                   16.4746785
## 177                 Tanzania                  58.400                   12.6566076
## 28                   Burundi                  58.220                   11.3285023
## 73             Guinea-Bissau                  56.778                    9.4914976
## 29                  Cambodia                  55.983                   13.8484742
## 14                Bangladesh                  55.101                   13.1352285
## 125                    Nepal                  53.220                   10.8521199
## 108                 Maldives                  51.451                   18.3523536
## 130                  Nigeria                  50.889                    1.0891746
## 95                      Laos                  50.837                    6.9736949
## 21                   Bolivia                  50.737                   10.9705565
## 1                Afghanistan                  50.233                           NA
## 163                  Somalia                  49.977                           NA
## 57                   Eritrea                  49.419                           NA
## 109                     Mali                  48.481                   -0.6866388
## 152      Sao Tome & Principe                  47.294                    7.0566717
## 187                   Uganda                  46.314                    0.5329932
## 20                    Bhutan                  45.121                    7.0300063
## 184                   Turkey                  44.359                   13.9817225
## 79                     India                  43.026                    2.1123658
## 56         Equatorial Guinea                  42.222                   -3.4075185
## 54                     Egypt                  40.630                    6.3901490
## 198                    Yemen                  40.258                   -2.7797131
## 27              Burkina Faso                  39.229                   -6.3409520
## 40                Congo, DRC                  36.507                   -9.6719667
## 139                     Peru                  36.046                    5.1078794
## 34                      Chad                  34.977                  -12.2552822
## 19                     Benin                  34.516                  -10.1592491
## 154                  Senegal                  33.307                   -4.3098911
## 42             Cote d'Ivoire                  32.958                   -9.8410415
## 133                 Pakistan                  32.943                   -9.7668121
## 90                     Kenya                  32.477                   -5.9502655
## 30                  Cameroon                  32.255                  -11.0410226
## 170                    Sudan                  32.087                   -8.3896849
## 75                     Haiti                  31.413                  -11.8225649
## 80                 Indonesia                  30.908                   -1.7416743
## 120                  Morocco                  28.816                   -2.6391880
## 71                 Guatemala                  28.370                   -4.0619019
## 180                     Togo                  27.726                  -13.5287278
## 68                     Ghana                  27.665                   -9.8669485
## 65                    Gambia                  26.241                  -12.1945376
## 38                   Comoros                  22.888                  -15.9025083
## 39                     Congo                  22.552                  -13.8615527
## 33  Central African Republic                  20.741                  -25.5608883
## 137         Papua New Guinea                  15.575                           NA
## 112               Mauritania                  11.458                  -26.2089456
## 201                 Zimbabwe                  10.623                  -23.1217832
## 162          Solomon Islands                   9.230                           NA
## 59                  Eswatini                   2.495                  -28.2730190
## 
## $mys_ratio_hdr
##                      country mys_ratio_hdr_growth1995_2015 perf_mys_ratio_hdr_growth1995_2015
## 54                     Egypt                  0.2916080638                        0.122339021
## 19                     Benin                  0.2875264271                        0.050584543
## 95                      Laos                  0.2827380952                        0.119705726
## 106                   Malawi                  0.2800000000                        0.109914974
## 170                    Sudan                  0.2674216028                        0.079863141
## 125                    Nepal                  0.2626728111                       -0.023718296
## 29                  Cambodia                  0.2439746300                        0.058207622
## 129                    Niger                  0.2342857143                       -0.049720864
## 42             Cote d'Ivoire                  0.2275795564                        0.012097660
## 137         Papua New Guinea                  0.2231132075                                 NA
## 198                    Yemen                  0.2229437229                       -0.153498062
## 28                   Burundi                  0.2222222222                        0.053776853
## 71                 Guatemala                  0.2153846154                        0.125884306
## 90                     Kenya                  0.2137931034                        0.072132923
## 177                 Tanzania                  0.2113095238                        0.094737206
## 79                     India                  0.2053658537                       -0.023555356
## 133                 Pakistan                  0.1978021978                       -0.039479678
## 39                     Congo                  0.1960652806                        0.071503754
## 158             Sierra Leone                  0.1904761905                       -0.014129419
## 14                Bangladesh                  0.1893772894                        0.053103240
## 184                   Turkey                  0.1877705628                        0.047314248
## 109                     Mali                  0.1820512821                       -0.040225847
## 99                   Liberia                  0.1808510638                       -0.076627595
## 146                   Rwanda                  0.1608695652                        0.029638956
## 68                     Ghana                  0.1588347494                        0.011794835
## 59                  Eswatini                  0.1582515194                        0.053247735
## 40                Congo, DRC                  0.1423709586                       -0.064356031
## 65                    Gambia                  0.1407867495                       -0.044020105
## 33  Central African Republic                  0.1303935514                       -0.097402003
## 187                   Uganda                  0.1284313725                       -0.027620536
## 75                     Haiti                  0.1136363636                       -0.066800831
## 201                 Zimbabwe                  0.1100694444                        0.009933556
## 120                  Morocco                  0.1093750000                       -0.070031540
## 180                     Togo                  0.1079365079                       -0.110107179
## 121               Mozambique                  0.0889328063                       -0.096163836
## 1                Afghanistan                  0.0883620690                                 NA
## 108                 Maldives                  0.0854309687                        0.012848684
## 80                 Indonesia                  0.0728571429                       -0.003308769
## 21                   Bolivia                  0.0561920349                       -0.023662447
## 112               Mauritania                  0.0522875817                       -0.099189748
## 139                     Peru                  0.0511549002                       -0.021239967
## 30                  Cameroon                  0.0147523709                       -0.117335790
## 200                   Zambia                 -0.0008067769                       -0.057740368
## 154                  Senegal                 -0.2368421053                       -0.331988405
## 
## $asfr_adol_wpp
##                      country asfr_adol_wpp_growth1995_2015 perf_asfr_adol_wpp_growth1995_2015
## 108                 Maldives                        91.781                         59.8200603
## 198                    Yemen                        78.568                         48.5394904
## 20                    Bhutan                        72.961                         43.5443108
## 79                     India                        65.924                         39.8990427
## 1                Afghanistan                        63.132                                 NA
## 65                    Gambia                        61.531                         26.1897721
## 30                  Cameroon                        56.723                         19.3759609
## 125                    Nepal                        55.789                         25.4308254
## 14                Bangladesh                        54.862                         22.2962156
## 158             Sierra Leone                        51.224                         15.1493570
## 71                 Guatemala                        49.724                         15.3561099
## 57                   Eritrea                        49.605                                 NA
## 5                     Angola                        45.600                          5.0954357
## 187                   Uganda                        45.266                         11.1241668
## 59                  Eswatini                        43.877                          8.1069710
## 34                      Chad                        39.874                          1.9195152
## 60                  Ethiopia                        39.696                         13.4983150
## 154                  Senegal                        39.530                          7.6146333
## 133                 Pakistan                        38.512                         12.8951882
## 95                      Laos                        37.221                          9.9159902
## 72                    Guinea                        34.428                         -4.1402866
## 38                   Comoros                        33.755                          2.7598411
## 68                     Ghana                        32.062                          2.3329430
## 73             Guinea-Bissau                        30.469                         -1.5326382
## 19                     Benin                        30.401                          0.4124152
## 56         Equatorial Guinea                        29.482                         -8.6484653
## 27              Burkina Faso                        29.414                         -1.6782629
## 105               Madagascar                        29.174                         -3.0543288
## 90                     Kenya                        29.107                         -1.3661345
## 184                   Turkey                        29.023                          2.7953056
## 121               Mozambique                        28.210                         -4.5363286
## 170                    Sudan                        28.040                         -0.1475028
## 130                  Nigeria                        26.383                         -2.6384502
## 112               Mauritania                        24.939                         -3.9163510
## 54                     Egypt                        24.676                         -1.5626247
## 28                   Burundi                        24.075                          1.7236570
## 152      Sao Tome & Principe                        23.893                         -6.6387851
## 42             Cote d'Ivoire                        23.647                        -11.0948529
## 99                   Liberia                        22.375                         -7.6826402
## 129                    Niger                        22.023                        -15.0031276
## 200                   Zambia                        20.739                        -12.1772835
## 137         Papua New Guinea                        19.258                                 NA
## 21                   Bolivia                        19.241                         -8.4596921
## 146                   Rwanda                        18.179                          1.1620082
## 29                  Cambodia                        17.965                         -2.0759585
## 139                     Peru                        17.937                         -9.2483630
## 177                 Tanzania                        17.539                        -13.1365101
## 109                     Mali                        17.434                        -17.5115791
## 75                     Haiti                        16.708                         -4.9594721
## 33  Central African Republic                        16.290                        -16.2226275
## 180                     Togo                        15.749                        -12.1741057
## 106                   Malawi                        15.100                        -17.8111240
## 80                 Indonesia                        12.635                        -10.8317346
## 39                     Congo                         7.054                        -24.3730158
## 162          Solomon Islands                         6.758                                 NA
## 120                  Morocco                         3.478                        -12.4133228
## 40                Congo, DRC                        -2.239                        -31.6450446
## 201                 Zimbabwe                        -6.097                        -37.6626173
## 163                  Somalia                        -8.646                                 NA

H > G classification

Performance(category = "H > G", year = 1995, vars = c(variables$health, variables$gender))
## $life_exp_wpp
##                            country life_exp_wpp_growth1995_2015 perf_life_exp_wpp_growth1995_2015
## 165                    South Korea                         8.43                         4.2214007
## 81                            Iran                         8.13                         3.4443959
## 128                      Nicaragua                         7.00                         2.4565416
## 76                        Honduras                         6.22                         2.2220818
## 32                      Cape Verde                         6.03                         1.5622962
## 169                      Sri Lanka                         5.87                         2.4782158
## 55                     El Salvador                         5.74                         1.1597323
## 35                           Chile                         5.07                         1.8989982
## 10                         Austria                         4.84                         1.0609495
## 43                         Croatia                         4.64                         1.0876796
## 153                   Saudi Arabia                         4.27                        -0.9025512
## 25                          Brunei                         4.17                        -1.8034918
## 135          Palestinian Territory                         4.14                         0.4193966
## 6                Antigua & Barbuda                         4.03                        -0.1625565
## 113                      Mauritius                         3.86                        -0.7785654
## 136                         Panama                         3.75                         0.6459770
## 44                            Cuba                         3.68                                NA
## 148                    Saint Lucia                         3.49                        -0.2187625
## 107                       Malaysia                         3.49                        -0.6208494
## 171                       Suriname                         3.31                        -1.5153235
## 26                        Bulgaria                         3.13                        -0.9514363
## 41                      Costa Rica                         3.08                         0.6169143
## 157                     Seychelles                         2.33                        -2.6278055
## 70                         Grenada                         2.11                        -1.6379999
## 82                            Iraq                         2.07                        -1.7313213
## 195                      Venezuela                         2.04                        -1.9417057
## 12                         Bahamas                         1.50                        -3.6710456
## 149 Saint Vincent & the Grenadines                         1.15                        -2.7379162
## 86                         Jamaica                         0.06                        -2.5695333
## 174                          Syria                        -1.41                        -3.0953525
## 
## $imr_wpp
##                            country imr_wpp_growth1995_2015 perf_imr_wpp_growth1995_2015
## 128                      Nicaragua                  30.120                   -0.8172150
## 32                      Cape Verde                  25.941                   -5.1511974
## 76                        Honduras                  24.615                   -4.6459834
## 81                            Iran                  24.187                   -2.8064882
## 55                     El Salvador                  23.391                   -5.1194119
## 153                   Saudi Arabia                  21.348                    1.8764995
## 171                       Suriname                  18.017                   -7.7247174
## 6                Antigua & Barbuda                  13.822                   -0.6299222
## 135          Palestinian Territory                  13.378                  -11.3890169
## 169                      Sri Lanka                  11.212                   -5.9761791
## 136                         Panama                  10.246                   -9.3125900
## 82                            Iraq                   9.532                  -18.5602455
## 12                         Bahamas                   9.455                   -1.1161171
## 86                         Jamaica                   8.782                  -10.0142976
## 174                          Syria                   8.390                  -15.8266195
## 195                      Venezuela                   8.081                   -9.3163286
## 165                    South Korea                   7.328                    4.0461107
## 26                        Bulgaria                   7.080                   -3.8281385
## 35                           Chile                   6.799                   -2.5202355
## 113                      Mauritius                   6.460                   -6.5648696
## 43                         Croatia                   5.953                    1.3439958
## 107                       Malaysia                   5.922                   -1.2888868
## 41                      Costa Rica                   5.229                   -5.0179147
## 44                            Cuba                   5.138                           NA
## 10                         Austria                   3.546                    7.7229816
## 70                         Grenada                   2.773                  -10.3158384
## 149 Saint Vincent & the Grenadines                   1.916                  -13.1253475
## 25                          Brunei                   1.764                    0.6003328
## 148                    Saint Lucia                   1.748                  -11.7438221
## 157                     Seychelles                   0.897                   -6.0740262
## 
## $mys_ratio_hdr
##          country mys_ratio_hdr_growth1995_2015 perf_mys_ratio_hdr_growth1995_2015
## 81          Iran                   0.339375000                        0.211471764
## 128    Nicaragua                   0.293269231                        0.205600008
## 153 Saudi Arabia                   0.278888889                        0.132330646
## 82          Iraq                   0.192307692                        0.017435455
## 43       Croatia                   0.166386555                        0.064115309
## 113    Mauritius                   0.140601504                        0.048761372
## 10       Austria                   0.137655626                        0.046091022
## 174        Syria                   0.135154062                        0.030489879
## 107     Malaysia                   0.129839747                        0.050511334
## 165  South Korea                   0.090928137                       -0.001254859
## 25        Brunei                   0.084249084                        0.012876261
## 195    Venezuela                   0.079081633                        0.035772451
## 76      Honduras                   0.073924731                        0.031679742
## 55   El Salvador                   0.042777778                       -0.022001923
## 26      Bulgaria                   0.041155704                       -0.006021852
## 41    Costa Rica                   0.037418301                       -0.005285118
## 86       Jamaica                   0.022513441                       -0.008115322
## 44          Cuba                   0.021505376                                 NA
## 35         Chile                  -0.005316742                       -0.050893903
## 169    Sri Lanka                  -0.022807018                       -0.072950267
## 
## $asfr_adol_wpp
##                            country asfr_adol_wpp_growth1995_2015 perf_asfr_adol_wpp_growth1995_2015
## 128                      Nicaragua                        53.419                         17.9640214
## 148                    Saint Lucia                        50.463                         18.4945266
## 153                   Saudi Arabia                        49.452                         21.3973785
## 135          Palestinian Territory                        49.295                         17.8572712
## 70                         Grenada                        48.097                         19.1792355
## 76                        Honduras                        47.388                         14.1338740
## 86                         Jamaica                        36.901                          5.7247741
## 12                         Bahamas                        36.846                          5.5906029
## 81                            Iran                        36.039                         10.4655784
## 41                      Costa Rica                        33.819                          1.7077213
## 149 Saint Vincent & the Grenadines                        33.443                          3.0116501
## 32                      Cape Verde                        33.045                          2.7358784
## 171                       Suriname                        28.907                         -2.3264506
## 55                     El Salvador                        27.685                         -2.1281318
## 6                Antigua & Barbuda                        24.791                         -4.9328592
## 174                          Syria                        24.632                          4.7130102
## 25                          Brunei                        23.832                         -0.7322815
## 26                        Bulgaria                        22.958                         -4.2720931
## 35                           Chile                        14.682                        -13.1339679
## 113                      Mauritius                        14.190                         -7.1100050
## 44                            Cuba                        12.658                                 NA
## 10                         Austria                        11.925                         -1.2393054
## 136                         Panama                        11.135                        -21.2608330
## 43                         Croatia                         9.495                          0.1482466
## 169                      Sri Lanka                         7.446                         -3.8410965
## 195                      Venezuela                         7.119                        -25.0833920
## 157                     Seychelles                         6.788                        -23.1967274
## 107                       Malaysia                         5.943                         -2.6367027
## 165                    South Korea                         2.345                         15.5054961
## 82                            Iraq                       -12.038                        -34.5125277

G > H classification

Performance(category = "G > H", year = 1995, vars = c(variables$health, variables$gender))
## $life_exp_wpp
##                country life_exp_wpp_growth1995_2015 perf_life_exp_wpp_growth1995_2015
## 176         Tajikistan                        11.59                         3.8887628
## 58             Estonia                         8.28                         3.2823350
## 23            Botswana                         7.93                        -1.1287422
## 118           Mongolia                         7.70                         1.5594762
## 122            Myanmar                         7.03                         0.7248560
## 11          Azerbaijan                         7.02                         1.3627536
## 24              Brazil                         7.00                         1.9171684
## 96              Latvia                         6.47                         1.1058001
## 8              Armenia                         5.93                         1.8833804
## 91            Kiribati                         5.85                                NA
## 77             Hungary                         5.84                         0.8566287
## 2              Albania                         5.80                         3.1027103
## 36               China                         5.77                         2.2810007
## 150              Samoa                         5.49                                NA
## 51  Dominican Republic                         5.16                         0.4473957
## 74              Guyana                         5.00                                NA
## 185       Turkmenistan                         4.60                        -2.1867276
## 49            Djibouti                         4.53                        -3.2197075
## 102          Lithuania                         4.26                        -0.3154891
## 94          Kyrgyzstan                         4.02                        -1.0350297
## 193         Uzbekistan                         3.96                        -0.9080611
## 89          Kazakhstan                         3.62                        -2.3404482
## 104          Macedonia                         3.62                         0.1884203
## 16             Belarus                         3.00                        -1.7445919
## 115         Micronesia                         3.00                                NA
## 140        Philippines                         2.72                        -1.6455232
## 64               Gabon                         2.69                        -4.9771318
## 181              Tonga                         1.13                                NA
## 123            Namibia                        -0.80                        -7.6495766
## 164       South Africa                        -2.30                        -8.9583696
## 98             Lesotho                       -10.43                       -16.9566239
## 
## $imr_wpp
##                country imr_wpp_growth1995_2015 perf_imr_wpp_growth1995_2015
## 11          Azerbaijan                  50.336                   12.4836623
## 176         Tajikistan                  50.164                   10.8411789
## 118           Mongolia                  44.720                    7.8597153
## 94          Kyrgyzstan                  40.284                    7.1847091
## 89          Kazakhstan                  36.778                    7.5325964
## 193         Uzbekistan                  31.685                   -1.6891165
## 8              Armenia                  30.871                    1.5782088
## 122            Myanmar                  29.016                  -11.2301595
## 36               China                  28.998                    0.4466554
## 185       Turkmenistan                  28.561                   -7.0375832
## 24              Brazil                  26.953                   -0.1234694
## 51  Dominican Republic                  22.017                   -8.0324827
## 64               Gabon                  21.617                  -11.0636537
## 2              Albania                  21.524                   -2.6084387
## 49            Djibouti                  20.429                  -17.9080291
## 91            Kiribati                  18.297                           NA
## 104          Macedonia                  17.611                   -2.7699707
## 58             Estonia                  13.135                    1.4475069
## 74              Guyana                  13.120                           NA
## 140        Philippines                  12.746                  -13.3370769
## 115         Micronesia                  12.560                           NA
## 96              Latvia                  12.398                   -0.1824839
## 102          Lithuania                  12.110                    0.2677959
## 16             Belarus                  11.669                    1.3327291
## 123            Namibia                  11.218                  -19.0805007
## 164       South Africa                   8.283                  -17.9018293
## 77             Hungary                   8.214                    0.4603962
## 150              Samoa                   8.074                           NA
## 23            Botswana                   6.349                  -20.4210048
## 181              Tonga                   2.538                           NA
## 98             Lesotho                  -2.540                  -39.2772389
## 
## $mys_ratio_hdr
##                country mys_ratio_hdr_growth1995_2015 perf_mys_ratio_hdr_growth1995_2015
## 118           Mongolia                  0.1581632653                        0.103094090
## 98             Lesotho                  0.1540880503                        0.156892357
## 123            Namibia                  0.1293350717                        0.078201548
## 122            Myanmar                  0.1139817629                        0.072956712
## 94          Kyrgyzstan                  0.0923757993                        0.039886366
## 58             Estonia                  0.0842653593                        0.039706942
## 89          Kazakhstan                  0.0824742268                        0.024388478
## 2              Albania                  0.0812662414                        0.021324028
## 74              Guyana                  0.0716705295                                 NA
## 11          Azerbaijan                  0.0462962963                       -0.012649509
## 140        Philippines                  0.0439560440                        0.008800213
## 96              Latvia                  0.0256598240                       -0.010887649
## 164       South Africa                  0.0225113122                       -0.032465537
## 102          Lithuania                  0.0202020202                       -0.024607014
## 36               China                  0.0172280294                       -0.044509577
## 8              Armenia                  0.0073179033                       -0.023123581
## 16             Belarus                  0.0067283431                       -0.039117448
## 51  Dominican Republic                  0.0016091954                       -0.025020736
## 77             Hungary                 -0.0009182736                       -0.051781948
## 181              Tonga                 -0.0022269460                                 NA
## 176         Tajikistan                 -0.0043706294                       -0.057162746
## 24              Brazil                 -0.0184633711                       -0.040179006
## 23            Botswana                 -0.0319148936                       -0.070789498
## 64               Gabon                 -0.3934343434                       -0.395144631
## 
## $asfr_adol_wpp
##                country asfr_adol_wpp_growth1995_2015 perf_asfr_adol_wpp_growth1995_2015
## 64               Gabon                        71.596                         29.4761310
## 8              Armenia                        55.225                         28.5484132
## 23            Botswana                        46.999                         15.1613404
## 193         Uzbekistan                        37.056                         13.8703486
## 102          Lithuania                        31.449                         10.1239325
## 58             Estonia                        30.958                          8.8600675
## 115         Micronesia                        29.807                                 NA
## 96              Latvia                        28.216                          7.0254010
## 104          Macedonia                        25.154                          6.2394245
## 94          Kyrgyzstan                        24.814                         -0.8374210
## 91            Kiribati                        24.806                                 NA
## 49            Djibouti                        23.754                          6.7289192
## 16             Belarus                        22.863                          1.5059333
## 89          Kazakhstan                        22.423                         -1.4837099
## 24              Brazil                        19.674                        -10.2561609
## 164       South Africa                        18.343                        -13.2424779
## 77             Hungary                        16.222                         -2.9451258
## 51  Dominican Republic                        15.345                        -18.0878566
## 123            Namibia                        12.704                        -17.2997016
## 122            Myanmar                        12.529                          0.4521098
## 118           Mongolia                        11.837                         -2.0850232
## 36               China                         8.391                          6.9319094
## 181              Tonga                         7.922                                 NA
## 176         Tajikistan                         6.931                        -14.4826060
## 74              Guyana                         5.752                                 NA
## 150              Samoa                         5.418                                 NA
## 185       Turkmenistan                        -0.034                        -12.6233328
## 98             Lesotho                        -1.130                        -26.2436005
## 2              Albania                        -1.997                         -5.9405149
## 140        Philippines                        -6.293                        -26.5138229
## 11          Azerbaijan                       -11.708                        -28.1384794

High classification

Performance(category = "upp", year = 1995, vars = c(variables$health, variables$gender))
## $life_exp_wpp
##                      country life_exp_wpp_growth1995_2015 perf_life_exp_wpp_growth1995_2015
## 97                   Lebanon                         7.54                       4.208014541
## 161                 Slovenia                         6.40                       2.398055630
## 22      Bosnia & Herzegovina                         6.39                       3.973409283
## 141                   Poland                         6.00                       1.914668431
## 142                 Portugal                         5.72                       2.131493191
## 46            Czech Republic                         5.67                       1.186405520
## 159                Singapore                         5.61                       2.142427107
## 103               Luxembourg                         5.37                       0.885477255
## 83                   Ireland                         5.26                       1.582805656
## 178                 Thailand                         5.03                       0.960831593
## 127              New Zealand                         4.97                       1.513979442
## 48                   Denmark                         4.91                       0.899166950
## 85                     Italy                         4.89                       1.544748638
## 168                    Spain                         4.88                       1.953203410
## 62                   Finland                         4.86                       1.206067599
## 175                   Taiwan                         4.84                       0.748652146
## 173              Switzerland                         4.76                       1.185162946
## 84                    Israel                         4.71                       1.356067795
## 9                  Australia                         4.67                       1.331367166
## 160                 Slovakia                         4.63                       0.271752422
## 190           United Kingdom                         4.63                       1.069920816
## 63                    France                         4.60                       1.244087923
## 67                   Germany                         4.46                       0.608684048
## 131                   Norway                         4.32                       0.874781584
## 189     United Arab Emirates                         4.21                      -1.881613189
## 17                   Belgium                         4.12                       0.459630160
## 126              Netherlands                         4.05                       0.597825424
## 31                    Canada                         4.04                       0.638747393
## 192                  Uruguay                         4.02                       0.335029878
## 87                     Japan                         3.90                       1.011350456
## 110                    Malta                         3.85                       1.146780288
## 172                   Sweden                         3.75                       0.604164859
## 69                    Greece                         3.70                       0.763789737
## 78                   Iceland                         3.66                       0.528565654
## 13                   Bahrain                         3.52                      -0.653650118
## 7                  Argentina                         3.51                      -0.230766835
## 15                  Barbados                         3.43                      -0.171597368
## 191 United States of America                         3.29                      -0.965114082
## 143                    Qatar                         3.14                      -0.354457116
## 45                    Cyprus                         2.98                       0.005218632
## 93                    Kuwait                         2.37                      -2.641210883
## 
## $imr_wpp
##                      country imr_wpp_growth1995_2015 perf_imr_wpp_growth1995_2015
## 178                 Thailand                  15.988                   -3.6988616
## 97                   Lebanon                  15.523                   -4.5409134
## 141                   Poland                  11.950                    0.1537548
## 22      Bosnia & Herzegovina                  11.508                   -6.4819885
## 7                  Argentina                  11.173                   -6.0614659
## 192                  Uruguay                  10.003                   -4.5048327
## 13                   Bahrain                   7.950                   -0.9897136
## 143                    Qatar                   7.924                   -0.5986872
## 46            Czech Republic                   6.457                    5.6308813
## 142                 Portugal                   6.177                    4.7791109
## 189     United Arab Emirates                   6.159                    3.6557103
## 160                 Slovakia                   6.157                    0.5579037
## 69                    Greece                   5.166                    5.1374172
## 161                 Slovenia                   5.119                    7.1682623
## 93                    Kuwait                   5.108                   -0.5395942
## 84                    Israel                   5.057                    5.7612027
## 45                    Cyprus                   4.989                    3.4867553
## 85                     Italy                   4.390                    7.2874830
## 17                   Belgium                   4.302                    6.5323763
## 103               Luxembourg                   3.835                    8.4969141
## 168                    Spain                   3.750                    7.5789123
## 78                   Iceland                   3.197                   13.0924902
## 83                   Ireland                   3.191                    7.2979840
## 131                   Norway                   3.067                   10.6399414
## 63                    France                   3.053                    7.8277431
## 110                    Malta                   3.011                    2.5125115
## 127              New Zealand                   2.992                    5.5564138
## 9                  Australia                   2.884                    7.9271383
## 62                   Finland                   2.836                   11.6235560
## 159                Singapore                   2.747                   12.0637042
## 48                   Denmark                   2.742                    8.2882319
## 126              Netherlands                   2.716                    8.5490853
## 191 United States of America                   2.715                    4.0460542
## 172                   Sweden                   2.706                   11.3525502
## 67                   Germany                   2.631                    8.9744356
## 190           United Kingdom                   2.625                    6.8180660
## 87                     Japan                   2.216                   13.3774091
## 173              Switzerland                   2.169                    8.9768174
## 15                  Barbados                   1.973                   -5.1488929
## 31                    Canada                   1.594                    7.4614849
## 175                   Taiwan                   1.160                    8.6002349
## 
## $mys_ratio_hdr
##                      country mys_ratio_hdr_growth1995_2015 perf_mys_ratio_hdr_growth1995_2015
## 93                    Kuwait                   0.201318458                        0.138377572
## 189     United Arab Emirates                   0.161607143                        0.118549606
## 142                 Portugal                   0.151736111                        0.076154021
## 45                    Cyprus                   0.124747475                        0.048998908
## 48                   Denmark                   0.120347395                        0.052192025
## 67                   Germany                   0.087684729                        0.008182759
## 87                     Japan                   0.082166768                        0.020169696
## 69                    Greece                   0.081317765                        0.006259212
## 62                   Finland                   0.078241431                        0.022369713
## 168                    Spain                   0.072261072                        0.004772843
## 15                  Barbados                   0.070187166                        0.023030779
## 85                     Italy                   0.068307906                       -0.002377045
## 31                    Canada                   0.066239316                        0.012367822
## 9                  Australia                   0.059282051                        0.000811882
## 173              Switzerland                   0.059145604                       -0.017549703
## 192                  Uruguay                   0.046190476                        0.007427191
## 83                   Ireland                   0.040711430                       -0.002831784
## 159                Singapore                   0.037296037                       -0.037707321
## 141                   Poland                   0.036234104                       -0.010046239
## 17                   Belgium                   0.025792495                       -0.034121154
## 126              Netherlands                   0.025081081                       -0.039916201
## 63                    France                   0.025042849                       -0.036483448
## 131                   Norway                   0.024806723                       -0.026222876
## 103               Luxembourg                   0.023089431                       -0.045063814
## 84                    Israel                   0.017241379                       -0.033202069
## 172                   Sweden                   0.016260163                       -0.031020188
## 13                   Bahrain                   0.013888889                       -0.033066865
## 161                 Slovenia                   0.010294331                       -0.041680281
## 127              New Zealand                   0.009641026                       -0.041719026
## 7                  Argentina                   0.007369283                       -0.030412572
## 46            Czech Republic                   0.001512573                       -0.050452390
## 190           United Kingdom                  -0.006731946                       -0.054953730
## 191 United States of America                  -0.008481203                       -0.054585453
## 160                 Slovakia                  -0.015037594                       -0.059654026
## 110                    Malta                  -0.023188406                       -0.073046960
## 178                 Thailand                  -0.030448718                       -0.073260887
## 78                   Iceland                  -0.065836941                       -0.106703378
## 143                    Qatar                  -0.082306831                       -0.080199093
## 
## $asfr_adol_wpp
##                      country asfr_adol_wpp_growth1995_2015 perf_asfr_adol_wpp_growth1995_2015
## 143                    Qatar                        32.737                          8.5625068
## 191 United States of America                        31.574                          0.9960145
## 46            Czech Republic                        30.337                          7.8074673
## 97                   Lebanon                        28.063                          9.4482338
## 189     United Arab Emirates                        25.502                         -2.7527880
## 160                 Slovakia                        22.897                          0.1688794
## 45                    Cyprus                        19.171                          5.1508218
## 78                   Iceland                        16.141                         -0.6033095
## 15                  Barbados                        15.198                        -12.3820446
## 141                   Poland                        15.030                          0.2886285
## 161                 Slovenia                        14.792                          3.9301115
## 31                    Canada                        13.647                         -3.0204085
## 22      Bosnia & Herzegovina                        13.529                          7.3469200
## 93                    Kuwait                        13.239                         -1.9256931
## 175                   Taiwan                        12.958                          3.2430798
## 190           United Kingdom                        12.034                         -6.6652161
## 127              New Zealand                        10.469                         -9.3790489
## 142                 Portugal                        10.431                         -1.9558858
## 7                  Argentina                         9.988                        -18.6961937
## 192                  Uruguay                         9.948                        -18.8091760
## 131                   Norway                         9.709                          0.4781870
## 69                    Greece                         8.808                         -0.3386986
## 9                  Australia                         8.573                         -4.9957003
## 13                   Bahrain                         8.318                         -4.2877142
## 67                   Germany                         7.845                         -1.5992842
## 84                    Israel                         7.799                         -4.1901849
## 103               Luxembourg                         6.118                         -1.5163718
## 172                   Sweden                         5.957                          1.8379237
## 83                   Ireland                         5.399                         -3.1272447
## 17                   Belgium                         4.790                          1.4458914
## 48                   Denmark                         4.465                          4.0996927
## 159                Singapore                         3.980                          5.8044345
## 62                   Finland                         3.957                          0.4015450
## 173              Switzerland                         3.044                          6.1919774
## 126              Netherlands                         2.663                          5.5793764
## 85                     Italy                         1.849                          3.6117867
## 63                    France                         1.390                          2.6705565
## 168                    Spain                         0.707                          0.2638633
## 87                     Japan                        -0.730                         11.7612327
## 110                    Malta                        -1.293                         -4.2594156
## 178                 Thailand                        -1.338                        -23.1854048
save(data, codebook, categories, variables, df, new, file = "_data/LSCMWG_working_class.RData")