Skip to contents

ucdp_country_crosswalk() adds the counterpart to a Correlates of War (ccode) or Gleditsch-Ward (gwcode) identifier. By default it obtains a year-sensitive mapping from peacesciencer::create_stateyears() and peacesciencer::add_gwcode_to_cow() or peacesciencer::add_ccode_to_gw(). A supplied crosswalk makes the operation fully offline and is useful when freezing a replication workflow.

Usage

ucdp_country_crosswalk(
  data,
  from = c("gw", "cow"),
  code = NULL,
  year = "year",
  crosswalk = NULL,
  unmatched = c("keep", "warn", "drop", "error")
)

Arguments

data

A data frame containing a country code and year.

from

Coding system used by code: "gw" or "cow".

code, year

Names of the source-code and year columns. Common UCDP names are detected when code is omitted.

crosswalk

Optional data frame containing year, gwcode, and ccode. If omitted, the mapping is generated by peacesciencer.

unmatched

How to handle rows without a counterpart: retain them with NA, warn and retain them, drop them, or raise an error.

Value

A tibble with the original rows and a gwcode or ccode column. The ucdp_source attribute is preserved and matching diagnostics are stored in ucdp_crosswalk.

Examples

x <- data.frame(country_id = c(2, 20, 999), year = 2020)
map <- data.frame(
  year = c(2020, 2020), gwcode = c(2, 20), ccode = c(2, 20)
)
ucdp_country_crosswalk(x, from = "gw", crosswalk = map)
#> # A tibble: 3 × 3
#>   country_id  year ccode
#>        <dbl> <dbl> <int>
#> 1          2  2020     2
#> 2         20  2020    20
#> 3        999  2020    NA