Assignment 5: R APIs and Databases
1 Accept Assignment on Github Classroom
Clone this assignment to your computer.
Intitialize your own
renv
environment.
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 and the
alfred
package.1Calculate 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
1 See the coding example for this lecture if you are confused.
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
sf
package- Check their documentation if you have trouble2.
Install the
tidycensus
packagePull median household income: “B19013_001” from the ACS3
- But choose a different state than Rhode Island
Create a map with the data and
ggplot2
- Follow the example in the slides
2 You likely need to install something called ‘gdal’ in the terminal.
3 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 (Optional) 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.
Then open up the “get-wrds-data.r” script
- The connection to the WRDS database should already work
- Try running the example in the code (same as what we saw in class)
- Try finding 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
6 Submit
Commit your code and push to Github!