ABOUT

The code aims to provide transparency for the merging and treatment of variables for the Multidimensional Measures of Militarization (m3) Dataset (version 1). Please reach out to in case of any doubts or feedback. The dataset contains information for 159 countries spanning the years 1990 to 2020.

SETUP

#.rs.restartR() to restart session in R

rm(list = ls())
cat("\014") #for clearing console
check.packages <- function(pkg){
  new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
  if (length(new.pkg))
    install.packages(new.pkg, dependencies = TRUE,
                     repos = "https://cran.rstudio.com")
  sapply(pkg, require, character.only = TRUE)
}
#installing the packages 
check.packages(c("tidyverse","countrycode","readxl",
                 "WDI","haven","ggplot2","lubridate",
                 "car","olsrr","writexl","DBI","RSQLite"))
##   tidyverse countrycode      readxl         WDI       haven     ggplot2 
##        TRUE        TRUE        TRUE        TRUE        TRUE        TRUE 
##   lubridate         car       olsrr     writexl         DBI     RSQLite 
##        TRUE        TRUE        TRUE        TRUE        TRUE        TRUE
## Normalization function
norm <- function(v) {
    max <- max(v, na.rm = TRUE)
    min <- min(v, na.rm = TRUE)
    return((v - min) / (max - min))
}

PREPARING DATA

Loading the files

#The first file loads the detailed equipment per country

#conscription ----

#define the path
path_conscription<-"Conscription_for_merge.xlsx"

#read the data
# this dataset has Northen Cyprus
conscription_data <- read_excel(path_conscription,1)  

#m3 dataset -----

#define the path
path_m3<-"PRM3_master.xlsx"

#read the data
m3_data <- read_excel(path_m3,1)

#gmi dataset 2021 -----

path_gmi<-"GMI_2021.xlsx"

gmi_data <- read_excel(path_gmi,1)

##milpol dataset ----

path_milpol<-"02MilPol_final_updated_june2023.dta"

milpol_data<-read_dta(path_milpol)

#economic_m3 dataset ---

ecom3_data <- read_dta("Rdataset_3M_filtered_clean.dta")

#economic_m3 dataset NEW ----

path_ecom3new<-"ecom3_data_new.xlsx"
ecom3_data_new <- read_excel(path_ecom3new,1)
#this dataset is the same as ecom3_data after running all the cleaning stated here but manually changing some values

#dissagreggated gmi dataset ----

dsg_gmi_data<-read_csv("disaggregate_gmi_2021.csv")

Standarize column names

#conscription ----

conscription_names<-c("country_iso"="ISO",
                      "year"="Year",
                      "country.name"="Country",
                      "com_mil_serv"="ComMilServ",
                      "com_mil_serv_gen"="ComMilServ_Gen",
                      "com_mil_serv_sur_min" ="ComMilServ_Dur_min",
                      "com_mil_serv_dur_max" = "ComMilServ_Dur_max",
                      "com_mil_serv_dur_min"="ComMilServ_Dur_min",
                      "alt_civ_serv"="AltCivServ",
                      "mobilisation"="Mobilisation")   

#com_mil_serv_sur_min should not exist, however will drop it at the end (not to mess w/rest of the code)

conscription_data<-conscription_data%>%
  select(all_of(conscription_names))

#m3 dataset -----

m3_names<-c("country.name"="country_text",
            "country_iso"="country_id",
            "country_cowcode"="cowcode",
            "year","mil_origin","mil_leader",
            "mil_mod","mil_veto","mil_repress",
            "mil_repress_count","mil_impun")

m3_data<-m3_data%>%
  select(all_of(m3_names))

#gmi dataset  -----

gmi_names<-c("country_iso","country.name","region",
             "gmi_2000","gmi_2001","gmi_2002",
             "gmi_2003","gmi_2004","gmi_2005",
             "gmi_2006","gmi_2007","gmi_2008",
             "gmi_2009","gmi_2010","gmi_2011",
             "gmi_2012","gmi_2013","gmi_2014",
             "gmi_2015","gmi_2016","gmi_2017",
             "gmi_2018","gmi_2019","gmi_2020")

gmi_data<-gmi_data%>%
  select(all_of(gmi_names))

##milpol dataset ----

milpol_names <- c("year" = "year",
                  "country.name" = "countryname_english",
                   "milpol_cripre" ="MilPol_CriPre" ,
                   "max_conf_milpol_cripre"="Max_Conf_MilPol_CriPre",
                   "p_a_milpol_cripre"="p_a_MilPol_CriPre",
                   "milpol_lawenf" = "MilPol_LawEnf" ,
                    "max_conf_milpol_lawenf" ="Max_Conf_MilPol_LawEnf" ,
                   "p_a_milpol_lawenf" ="p_a_MilPol_LawEnf" ,
                    "milpol_peapre" ="MilPol_PeaPre" ,
                    "max_conf_milpol_peapre" = "Max_Conf_MilPol_PeaPre",
                    "p_a_milpol_peapre" = "p_a_MilPol_PeaPre",
                    "milpol_dummy" ="MilPol_Dummy" ,
                   "milpol_sum" = "MilPol_Sum"