Analyzing Mexican votes in the U.N.

Datetime:2016-08-22 22:55:35          Topic: Assembler  Encryption and Decryption  DataBase           Share

(This article was first published on En El Margen - R-English , and kindly contributed toR-bloggers)

Last week I discovered the unvotes package on github so I thought i’d do some number-crunching to see if I find anything interesting.

The package provides the voting history of countries in the United Nations General Assembly, along with information such as date, description, and topics for each vote.

The author makes it clear to reference the original publication of the data:

Erik Voeten “Data and Analyses of Voting in the UN General Assembly” Routledge Handbook of International Organization, edited by Bob Reinalda (published May 27, 2013)

I installed from CRAN and created a small function that counts the amount of times two countries “agree”, that is they vote the same way in a given resolution.

library(dplyr)
library(magrittr)
library(unvotes)

# the database of all votes 
votes <- un_votes %>%
  left_join(., un_roll_calls) %>%
  left_join(., un_roll_call_issues)

# a function to count the amount of times any given countries "agree"
un_agree <- function(db, # the database
                     country1, 
                     country2,
                     abstain = TRUE # if FALSE, do not count abstains
                     ){
  c1 <- db %>% 
    filter(country == country1) %>%
    mutate("vote2" = vote)
  c2 <- db %>% 
    filter(country == country2)
  j <- c1 %>% select(vote2, rcid) %>%
    left_join(., c2 %>% select(rcid, vote), by = "rcid") %>%
    filter(!is.na(vote))
  if(!abstain){
  j <- j %>% 
    filter(vote != "abstain") %>%
    filter(vote2 != "abstain")
  }
  j <- j %>% 
    mutate("agree" = ifelse(vote2 == as.character(vote), 1, 0))
  sum(j$agree)/length(j$agree)*100
}

Now, it would be interesting to see how much my home country and its rowdy neighbour to the north see eye-to-eye…

un_agree(votes, "Mexico", "United States")
# [1] 23.32385

So about one-fourth of every vote. This goes up slightly when eliminating abstentions (29.7%).

However, this might be interesting to see by “sexenio”, or Mexican presidential term. Small caveat, the last vote in the dataset is september 9th, 2014.

# some of the newest presidential terms...
votes %<>% mutate("mxterm" = ifelse(date >= '1988-12-01' & 
                                   date <= '1994-11-30', "salinas", 
                            ifelse(date >= '1994-12-01' & 
                                   date <= '2000-11-30', "zedillo",
                            ifelse(date >= '2000-12-01' & 
                                   date <= '2006-11-30', "fox",
                            ifelse(date >= '2006-12-01' & 
                                   date <= '2012-11-30', "calderon",
                            ifelse(date >= '2012-12-01' & 
                                   date <= '2018-11-30', "penanieto", "others"))
                                   ))))
un_agree(votes %>% filter(mxterm =="salinas"), 
        "Mexico", "United States")
# [1] 10.77586
un_agree(votes %>% filter(mxterm =="zedillo"), 
        "Mexico", "United States")
# [1] 20.76167
un_agree(votes %>% filter(mxterm =="fox"), 
        "Mexico", "United States")
# [1] 9.129213
un_agree(votes %>% filter(mxterm =="calderon"), 
        "Mexico", "United States")
# [1] 8.935743
un_agree(votes %>% filter(mxterm =="penanieto"), 
        "Mexico", "United States")
# [1] 12.92517

This is unexpected. It’s usually folk tale that the PAN-ista governments (Fox and especially Calderon) cooperated much more with their American counterparts than the rest. Maybe we could visualize this side by side in a graph:

agree_by_year <- votes %>% 
  filter(country %in% c("Mexico", "United States")) %>% 
  group_by(year = year(date), rcid) %>% 
  summarise("DifVote" = n_distinct(vote)) %>% 
  mutate("Agree" = ifelse(DifVote == 1, 1, 0)) %>% 
  summarise("PercentageAgree" = sum(Agree)/n_distinct(rcid), 
            "VoteCount" = n_distinct(rcid))
  
g <- ggplot(agree_by_year, 
        aes(x = year, 
            y = PercentageAgree*100))+
  geom_line(colour = eem_colors[1])+
  theme_eem()+
  labs(title = "Do Mexico and U.S. agree in U.N. votes?",
       x = "Year", y = "(%)")
g

So the tendency has been to disagree more under these presidents. Off course, this could be due to a number of quirky data issues. Among them, the amount of different votes taken to the General Assembly (in orange)…

g +
  geom_line(aes(x = year, y = VoteCount), colour = eem_colors[2])

Now, it might seem strange so much disagreement, so let’s see if this rate is small or large in the context of everyone else. I’m going to loop through every country, to see Mexico’s (historic) agreement with each one…

# I found making a function to be easier for the rest
# of the post... 
agree_world_with <- function(db, 
                             country_pivot){
v <- NULL
for(i in 1:length(unique(db$country))){
country <- unique(db$country)[i]
p <- un_agree(db = votes, 
         country1 = country_pivot, 
         country2 = unique(db$country)[i])
d <- data.frame("country" = country, "p" = p)
v <- rbind.data.frame(v, d)}
  return(v)
}

# Now for the fun part... 
# which countries agree most with Mexico?
agree_world_with(votes, "Mexico") %>% 
  arrange(desc(p)) %>%
  filter(country != "Mexico") %>% # obviously p=100
  head()
#                country        p
#1           Timor-Leste 95.82192
#2            Seychelles 94.46378
#3 Sao Tome and Principe 93.73695
#4         Guinea-Bissau 92.48287
#5              Zimbabwe 92.37548
#6              Suriname 92.37288

# which countries agree less with Mexico?
agree_world_with(votes, "Mexico") %>% 
  arrange(desc(p)) %>%
  filter(country != "Mexico") %>%
  tail()
#                            country        p
#194                Marshall Islands 35.27607
#195 Micronesia, Federated States of 27.76163
#196                          Israel 25.96885
#197                   United States 23.32385
#198                           Palau 20.79327
#199                        Zanzibar  0.00000

For the record, I tried doing the same exercise for each “sexenio” and basically came up with the same number of countries on top, maybe we’re not so close to the U.S. after all?

What about abstentions? You would think Mexico’s historical no-intervention foreign policy would make it a cronical abstainer, but actually even the United States and France use this trick more often…

# count abstentions by country
abstentions <- votes %>% 
  mutate("abstain" = ifelse(as.character(vote) == "abstain", 1, 0)) %>%
  group_by(country) %>% 
  summarise("prct_abstentions" = sum(abstain)/n_distinct(rcid)) %>%
  arrange(desc(prct_abstentions))
abstentions[1:30, ] %>% as.data.frame
#                           country prct_abstentions
#1                         Zanzibar        1.0000000
#2      Federal Republic of Germany        0.5183636
#3                           France        0.4210017
#4                            Tonga        0.4038710
#5                      South Sudan        0.3958333
#6                            Japan        0.3929402
#7                          Georgia        0.3845050
#8                            Italy        0.3822297
#9  Micronesia, Federated States of        0.3818046
#10                         Austria        0.3641872
#11                  United Kingdom        0.3614412
#12              Korea, Republic of        0.3612663
#13                         Belgium        0.3587247
#14                      Luxembourg        0.3495841
#15                        Portugal        0.3486631
#16                          Canada        0.3462857
#17                Marshall Islands        0.3426431
#18                     Netherlands        0.3395579
#19                         Ireland        0.3381340
#20                         Finland        0.3379368
#21                       Australia        0.3326978
#22            Moldova, Republic of        0.3320053
#23                          Sweden        0.3277905
#24                          Israel        0.3275574
#25                         Denmark        0.3267912
#26                          Norway        0.3253862
#27                         Iceland        0.3208144
#28                         Estonia        0.3169192
#29                          Latvia        0.3159236
#30                           Spain        0.3145144

# Mexico is actually at spot 122 with only 10% of its total votes!! 
abstentions[122, ]
#  1  Mexico        0.1094109

This dataset is actually really nice, we can make a small comparison of some foreign policy. For example NAFTA partners and their agreement on some issues related to Israel…

# only the Palestinian conflict
israelset <- votes %>% filter(issue == "Palestinian conflict")
nafta <- c("Mexico", "United States", "Canada")
agree_with_israel <- data.frame("country" = nafta, 
                                "agree" = c(
                                un_agree(israelset, nafta[1], "Israel"),
                                un_agree(israelset, nafta[2], "Israel"),
                                un_agree(israelset, nafta[3], "Israel")
                                ))
agree_with_israel
#        country     agree
#1        Mexico  5.156724
#2 United States 77.620968
#3        Canada 25.226131

I’m sure the kind readers at r-bloggers will come up with another useful analysis from this package. Maybe a map? Tweet me up!





About List