knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Introduction and Purpose

This package specifically utilizes data from the Constituency-Level Elections Archive (CLEA) to create party nationalization datasets, which contain effective number of parties measures (ENP), as well as several measures of party nationalization. These measures exist for both Lower Chamber and Upper Chamber election results at three different levels of aggregation: the national level, the party level, and the constituency level. Moreover, Gini measures of inequality are included as well, which are utilized for various measures. This package contains the main function to create and populate these databases, as well as scripts for post-processing of these measures and comparison of said measures to existing measures on the archive.

The following is a robust example of the usage of the nationalization package. More information is available here on CLEA generally, or here about these measures of nationalization more-specifically.

Installing nationalization

The package is housed on GitHub here and can easily be downloaded using the devtools package:

install.packages("devtools")
devtools::install_github("simongamerpage/nationalization",
                         build_vignettes = TRUE)

Note that it is highly recommended to install all necessary dependencies if/when prompted during the installation process. While this package only depends on five packages, those packages have their own dependencies, which are necessary to be installed and up-to-date on the user's local machine. R may prompt the user to restart their session prior to installation, which is recommended; however, R does this for every package being downloaded or updated, thus opting to restart only once is acceptable.

Using Appropriate Data

As noted, nationalization() requires data in CLEA format, where the most crucial variables for nationalization() to run successfully are included below. Users should ensure that these columns are present prior to running the script, even if they are empty and/or not relevant for output. For example, even if the user opts to use the default pv1/pvs1 used for measures, having cv1/cvs1 present and filled with -990 is required because the script parses the correct columns to use.

In short, ensure the following columns are present, at the very least, to ensure nationalization() runs correctly:

# Variable list to print
vars=c("id","ctr_n","ctr","yr","mn","tier","cst","cst_n","pty","pty_n","vv1","pv1","pvs1","cv1","cvs1","seat")
print(vars)

Using nationalization

To use nationalization::nationalization(), only three arguments are absolutely necessary, which are listed and briefly explained below:

A number of other arguments are available for the advanced user, which do not need to be specified to run the script. The next section describes these optional arguments and their relevance in detail; moreover, using ?nationalization in the console after loading the library, library(nationalization), describes all the arguments briefly.

Now, it is time to run! In this example, my data exists on my Desktop, in a folder titled "CLEA", which is in .rdata format, and I want the output in that same folder, where a sub-folder called "output" exists.

library(nationalization)
nationalization(dataSource = "C:/Users/pagesim/Desktop/CLEA/CLEA_LC_R14.rdata",
                dataFormat = ".rdata",
                outputFolder = "C:/Users/pagesim/Desktop/CLEA/output/")

Output in the console should look similar to the following, where total computation time (in minutes) is included. Note that this output is for CLEA Release 14, which contains approx. 1.1 million rows of electoral data.

#> [1] ---------------------------------------------------
#> [1] Initializing... Checking Packages & Data Existence
#> [1] ---------------------------------------------------
#> [1] Sucessfully created subset for Gini & party-level measures...
#> [1] Sucessfully created subset for national-level ENP measures...
#> [1] Sucessfully created subset for constituency-level measures...
#> [1] Sucessfully created subset for national-level inflation/PSNS measures...
#> [1] Sucessfully created subset for national-level local_E measures...
#> [1] --------------------------------
#> [1] Computing inequality measures...
#> [1] --------------------------------
#> [1] Gini inequality measures successfully computed! Moving to party-level...
#> [1] ---------------------------------
#> [1] Computing Party Level Dataset...
#> [1] ---------------------------------
#> [1] Party-level measures successfully computed! Moving to national-level...
#> [1] ------------------------------------
#> [1] Computing National Level Dataset...
#> [1] ------------------------------------
#> [1] National-level measures successfully computed! Moving to constituency-level...
#> [1] ---------------------------------------
#> [1] Computing Constituency Level Dataset...
#> [1] ---------------------------------------
#> [1] Constituency-level measures successfully computed!
#> The entire computation took  2.650667 mins 
#> [1] Done!

Optional Arguments for the Advanced User

A number of optional arguments with default parameters exist for the advanced user of the nationalization function. Their purpose and applicability are listed and described below in detail. Note that none of the following arguments need to be specified for the function to work as intended.



simongamerpage/nationalization documentation built on Dec. 23, 2021, 2:24 a.m.