Assignment 6: R APIs and Databases
1 Accept Assignment on Github Classroom
Clone this assignment to your computer.
Intitialize your own
renvenvironment.
2 Set up “secrets.r” file
- Copy the “secrets-template.r” file to a new “secrets.r” file
This will be where you will store your personal API keys and passwords.
I have already added “secrets.r” to the “.gitignore”, so it should not be tracked or pushed to Github.
3 FRED API
3.1 Pull FRED Series
- Get an API Key from FRED. Save it in your “secrets.r” file.
You will need to use the fredr package for this section.
- Pull the following data series
- Real GDP: “GDPC1”
- Rhode Island Unemployment Rate: “RIUR”
- US-Euro Spot Exchange Rate: “DEXUSEU”
- One more series of your choice, look around FRED’s website
- For each series, calculate the following:
- Mean
- Median
- 25th Percentile
- 75th Percentile
- Now report the same summary statistics, but only with data since 2020
3.2 Vintage FRED
Pull Real GDP using a vintage date
- There is a
vintage_datesargument in thefredr()function.
- There is a
Calculate the difference between the current and the vintage data series (if there is no difference, try another vintage date)
Print out the date with the maximum difference
4 tidycensus API
Request a Census API key: https://api.census.gov/data/key_signup.html
- Save it to your “secrets.r” file
Install the
sfpackage- Check their documentation if you have trouble
Install the
tidycensuspackagePull median household income: “B19013_001” from the ACS1
- But choose a different state than Rhode Island
Create a map with the data and
ggplot2- Follow the example in the slides
1 Same as the example in the slides.
(Optional) Mapview
If you want to try making one of those interactive maps, install the package mapview and give it a go.
5 Connect to WRDS Database
- First, get access to WRDS through Brown Univesrity Library
This can take 1-2 days to get access.
Once you have an account, make sure you can log into WRDS online: https://wrds-www.wharton.upenn.edu
Then add your account username and password to the “secrets.r” file.2
Then open up the “get-wrds-data.r” script
- The connection to the WRDS database should already work
- Run the example in the code (same as what we saw in class)
- Find another database to connect to and pull a subset of the data
- I’d suggest looking around on the WRDS website to see what data is available
2 Sometimes you have to approve the connection through the Duo app on your phone.
6 Submit
- Take a
renv::snapshot()to update yourrenv.lockfile - Commit your code and push to Github!