---
title: "bill_merged"
author: "Zhaowen Guo"
date: "August 7, 2020"
output: pdf_document
---

#### first task ####

```{r setup, include=FALSE}
library(rjson)
library(tidyverse)
```

```{r}
bill <- read.csv("bills115-116partialAugust2020.csv")
cong_115 <- read.csv("HS115_members.csv")
cong_116 <- read.csv("HS116_members.csv")
```

```{r}
# merge variables to congress 115
bill_115 <- bill %>%
    filter(congress == 115)

cong_115 <- cong_115 %>%
    select("nominate_dim1","state_abbrev","district_code","state_icpsr","icpsr")
    
bill_115_merged <- left_join(bill_115, cong_115, by = "icpsr")
```

```{r}
# merge variables to congress 116
bill_116 <- bill %>%
    filter(congress == 116)

cong_116 <- cong_116 %>%
    select("nominate_dim1","state_abbrev","district_code","state_icpsr","icpsr")
    
bill_116_merged <- left_join(bill_116, cong_116, by = "icpsr") 
```

```{r}
# combine all the data 
bill_merged <- rbind(bill_115_merged, bill_116_merged)
write.csv(bill_merged, "bill_merged.csv", row.names=FALSE)
```


```{r}
# add bioguide variable 
bioguide <- read.csv("HSall_members.csv")
bioguide_115_116 <- bioguide %>%
    filter(congress == 115 | congress == 116) %>%
    filter(chamber != 'President') %>%
    select("icpsr","bioguide_id")

bill_merged_bio <- left_join(bill_merged, unique(bioguide_115_116)) # exclude the duplicates
write.csv(bill_merged_bio, "merged_bio.csv",row.names = F)
```


