see also stable versions in Party Facts Dataverse · (FAQ)

Data

Two Party Facts main tables – UTF-8 character encoding.

Note: Additional information in countries and datasets tables

Examples

R Tidyverse

Example: Merging Party Facts party datasets in R with tidyverse

library(tidyverse)

# download and read Party Facts mapping table
file_name <- "partyfacts-mapping.csv"
if( ! file_name %in% list.files()) {
  url <- "https://partyfacts.herokuapp.com/download/external-parties-csv/"
  download.file(url, file_name)
}
partyfacts_raw <- read_csv(file_name, guess_max = 50000)
partyfacts <- partyfacts_raw |> filter(! is.na(partyfacts_id))

# link datasets (select only linked parties)
dataset_1 <- partyfacts |> filter(dataset_key == "manifesto")
dataset_2 <- partyfacts |> filter(dataset_key == "parlgov")
link_table <-
  dataset_1 |>
  inner_join(dataset_2, by = c("partyfacts_id" = "partyfacts_id"))

# write results into file with dataset names in file name
file_out <- "partyfacts-linked.csv"
write_csv(link_table, file_out)

R

Example: Merging Party Facts party datasets in R

# download and read Party Facts mapping table
file_name <- 'partyfacts-mapping.csv'
if( ! file_name %in% list.files())
    url <- 'https://partyfacts.herokuapp.com/download/external-parties-csv/'
    download.file(url, file_name)
partyfacts <- read.csv(file_name, as.is=TRUE)  # maybe conversion of character encoding

# show and select available datasets
cat(paste(unique(partyfacts$dataset_key), collapse='\n'))
dataset_1 <- 'manifesto'
dataset_2 <- 'parlgov'

# merge two datasets selected
first <- partyfacts[partyfacts$dataset_key == dataset_1, ]
second <- partyfacts[partyfacts$dataset_key == dataset_2, ]
merge_table <- merge(first, second, by='partyfacts_id', all=TRUE)

# write results into file with dataset names in file name
file_out <- sprintf('partyfacts-%s-%s.csv', dataset_1, dataset_2)
write.csv(merge_table, file_out, na='', row.names = FALSE)

Stata

Example: Merging Party Facts party datasets in Stata

tempfile x
* copy "https://partyfacts.herokuapp.com/download/external-parties-csv/" "partyfacts-mapping.csv"
insheet using "partyfacts-mapping.csv", clear
keep if dataset_key == "parlgov"
foreach var of varlist _all {
    if "`var'" != "partyfacts_id" {
        rename `var' parlgov_`var'
    }
}
save "`x'", replace
insheet using "partyfacts-mapping.csv", clear
keep if dataset_key == "manifesto"
foreach var of varlist _all {
    if "`var'" != "partyfacts_id" {
        rename `var' manifesto_`var'
    }
}
joinby partyfacts_id using "`x'", unmatched(both)