Geting Started with ECODATA

ECO 301: Money and Banking

Getting Started with ECODATA

  • ECODATA is an R package for downloading and visualizing economic data

  • Can pull data from FRED and World Bank

  • Create reproducible, professional-quality data visualizations, and documenting your data sources

  • Easy only two or three lines of code

Example: Morgage Interest Rate

Download data on average 30-year mortgage interest rate from FRED:

# Load the library
library(ecodata)

# Download the data, save it in a data frame called `mydata`
mydata <- get_ecodata("https://fred.stlouisfed.org/series/MORTGAGE30US")

ECODATA data frame mydata:

Plot Mortgage Interest Rate

ggplot_ecodata_ts(mydata, title = "Mortgage Interest Rate - Fixed Rate 30-Year", plot.recessions = TRUE)

Information About Data

Get a description of the data

ecodata_description_table(mydata)

Variable

Code

Description

Frequency

Units

Seasonal Adjustment

Source

URL

Access Date

30-Year Fixed Rate Mortgage Average in the United States

MORTGAGE30US

30-Year Fixed Rate Mortgage Average in the United States

Weekly

%

Not Seasonally Adjusted

FRED (R) Federal Reserve Bank of St. Louis

https://fred.stlouisfed.org/series/MORTGAGE30US

February 03, 2025

Cite the data

ecodata_cite_table(mydata)

Variable

Cite

30-Year Fixed Rate Mortgage Average in the United States

FRED (R) Federal Reserve Bank of St. Louis; https://fred.stlouisfed.org/series/MORTGAGE30US; Accessed on February 03, 2025.

Why use the ECODATA Package?

  • Reproducible: The code is the set of instructions for what you created

  • Flexible: With more knowledge of R, you can change the data, the graph, the labels, etc.

  • Efficient: Easy to replicate code for similar variables, similar tasks

  • Used in other courses: R is used in econometrics (ECO 307), statistics (STAT courses), and others

  • Coding in R and Python used in industry, even among those who are not computer scientists or data scientists

  • Even more important / relevant with AI

    • AI assistance makes coding more accessible

    • Verification and reproducibility is key with AI-generated content

Advanced Example

# Get three variables - Save the list of URLs in an objected called 'variables'
variables <- c("https://fred.stlouisfed.org/series/FEDFUNDS",
               "https://fred.stlouisfed.org/series/UNRATE",
               "https://fred.stlouisfed.org/series/CPIAUCSL")

# Make up my own names for those variables 
varnames <- c("Federal Funds Rate", "Unemployment Rate", "CPI")

# Download all three variables, give them my own names
# Also set frequency = "m" for monthly data
mydata <- get_ecodata(variables, varnames = varnames, frequency = "m")

# Get only Great Recession + Recovery
mydata <- mydata |>
  filter(Date >= "2007-01-01" & Date <= "2016-12-31")

View of the Data

ECODATA data frame mydata:

Create a Plot for One Variable

ggplot_ecodata_ts(mydata, 
                  variables = "Unemployment Rate",
                  plot.recession = TRUE,
                  title = "Unemployment Rate")

Compute Inflation Rate

Inflation is the growth rate of the CPI

mydata <- ecodata_compute_pctchange(mydata, variable = "CPI", new_variable = "Inflation")

ECODATA data frame mydata:

Create a Faceted Plot

ggplot_ecodata_facet(mydata, 
  variables = c("Unemployment Rate", "Inflation", "Federal Funds Rate"),
  ncol = 3,
  plot.recession = TRUE,
  title = "United States Great Recession and Recovery")

Description of the Data

ecodata_description_table(mydata)

Variable

Code

Description

Frequency

Units

Seasonal Adjustment

Source

URL

Access Date

Federal Funds Rate

FEDFUNDS

Federal Funds Effective Rate

Monthly

%

Not Seasonally Adjusted

FRED (R) Federal Reserve Bank of St. Louis

https://fred.stlouisfed.org/series/FEDFUNDS

February 03, 2025

Unemployment Rate

UNRATE

Unemployment Rate

Monthly

%

Seasonally Adjusted

FRED (R) Federal Reserve Bank of St. Louis

https://fred.stlouisfed.org/series/UNRATE

February 03, 2025

CPI

CPIAUCSL

Consumer Price Index for All Urban Consumers: All Items in U.S. City Average

Monthly

Index 1982-1984=100

Seasonally Adjusted

FRED (R) Federal Reserve Bank of St. Louis

https://fred.stlouisfed.org/series/CPIAUCSL

February 03, 2025

Inflation

CPIAUCSL

Percent Change in Consumer Price Index for All Urban Consumers: All Items in U.S. City Average

Monthly

Percent

Seasonally Adjusted

FRED (R) Federal Reserve Bank of St. Louis

https://fred.stlouisfed.org/series/CPIAUCSL

February 03, 2025

Getting Started

  1. Login / Create Posit Cloud account at https://posit.cloud

  2. Create your own copy of the ECODATA Exercises project by following:

    https://posit.cloud/content/9518648

  3. Click + Save a Permanent Copy (top-right corner) to save your copy

  4. Login / Create FRED account at https://fred.stlouisfed.org/
    (click My Account at top right)

  5. Get your FRED key at https://fredaccount.stlouisfed.org/apikeys

  6. Copy that 32-character key and in the Posit Cloud console, set the key:
    ecodata::ecodata_set_fredkey("abcd1234efgh5678ijkl9012mnop3456")
    (insert your own 32-character key, this one won’t work)

Documentation