Assignment 5: R APIs and Databases

Author

Matthew DeHaven

Due

February 26, 2024

Modified

March 31, 2024

1 Accept Assignment on Github Classroom

  1. Accept Assignment 5 on Github Classroom.

  2. Clone this assignment to your computer.

  3. 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

4 Pull FRED Series

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
  • Make a chart for each series

  • Combine all of the charts using patchwork

  • Save the combined chart to a pdf in the output folder, call it “fred-chart.pdf”

4.1 Vintage FRED

  • Choose one of the series from above, and pull it using a vintage date.1

  • Redo the chart with the new data, and use patchwork to make a combined figure comparing the current and vintage series.

  • Save the combined figure to a pdf in the output folder, call it “fred-vintage-chart.pdf”

1 See the coding example for this lecture if you are confused.

5 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

  • Install the tidycensus package

  • Pull median household income: “B19013_001” from the ACS3

    • But choose a different state than Rhode Island
  • Create a map with the data and ggplot2

  • Save the map to a pdf in the output folder, call it “tidycensus-map.pdf”

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.

6 (Optional) Connect to WRDS Database

Warning

This takes 1-2 days!

  • 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

7 Submit

Commit your code and output and push to Github!