Skip to content

Commit

Permalink
update PPDB -- SPSS source and tidyverse clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
hdigital committed Jun 15, 2017
1 parent b2727a8 commit 93ac6a2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
23 changes: 13 additions & 10 deletions import/ppdb/ppdb.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
library(dplyr)
library(readr)
library(tidyverse)
library(haven)
library(countrycode)

ppdb <- read_tsv('source__PPDB-Round_1a-1.tab')

country_all <- read_csv("../country.csv")
country <- country_all %>% select(country_short = name_short, country = name)
ppdb <- haven::read_spss("source__PPDB-Round_1a-1.sav")

names(ppdb) <- tolower(names(ppdb)) # lower-case variable names

Expand All @@ -13,10 +11,15 @@ first_last <- ppdb %>%
summarise(year_first = min(year), year_last = max(year))

party <- ppdb %>%
distinct(ptyid, .keep_all = TRUE) %>%
distinct(ptyid, .keep_all = TRUE) %>%
select(ctryid, country, ptyid, ptyname, share_year_first = cr5seats2) %>%
mutate(share_year_first = ifelse(share_year_first >= 0, round(share_year_first, 1), NA)) %>%
left_join(first_last) %>%
left_join(country)
left_join(first_last) %>%
mutate(country_short = countrycode(country, "country.name", "iso3c"))

# recoding party names with unicode issues
party[party$ptyid == 4003, "ptyname"] <- "Bloc Québécois"
party[party$ptyid == 11003, "ptyname"] <- "Fianna Fáil"
party[party$ptyid == 11003, "ptyname"] <- "Sinn Féin"

write_csv(party, 'ppdb.csv', na = '')
write_csv(party, "ppdb.csv", na = "")
9 changes: 2 additions & 7 deletions import/ppdb/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,9 @@ Poguntke, Thomas et al. 2016. “Party Rules, Party Resources and the Politics o

## Import

`PPDB-Round_1a-1.tab` from [PPDB Dataverse](https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/0NM7KZ)
`PPDB-Round_1a-1.sav` from [PPDB Dataverse](https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/0NM7KZ)


## Comments

Recoding party names

* "Ecologist Party \"The Greens\"" --> "Ecologist Party 'The Greens'"
* fixing unicode issues
- CAN -- Bloc Québécois
- IRL -- Fianna Fáil,
* recoding party names with unicode issus -- see `ppdb.R`

0 comments on commit 93ac6a2

Please sign in to comment.