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 document 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)
Plot of mortgage interest rate over time, generated by ggplot_ecodata_ts() code.

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

September 21, 2026

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 September 21, 2026.

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

Image of a person using a computer

  • 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

Example eith Multiple Variables

# 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")
Plot of mortgage interest rate that only covers January 2007 through December 2016

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:

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

September 21, 2026

Unemployment Rate

UNRATE

Unemployment Rate

Monthly

%

Seasonally Adjusted

FRED (R) Federal Reserve Bank of St. Louis

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

September 21, 2026

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

September 21, 2026

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

September 21, 2026

Getting Started

  1. Login / Create an account at FRED (Federal Reserve Economic Data)
    (click person icon at top right)

  2. Follow this link to create a FRED API key which gives you access to download data from your code

  3. Login / Create Posit Cloud account at Posit Cloud

  4. Follow this link to join the

    ECO 301 space on Posit Connect

  5. Go into the console in Posit cloud and enter that 32-character FRED API key and in the Posit Cloud console, set the key:
    ecodata_set_fredkey("abcd1234efgh5678ijkl9012mnop3456")

    (insert your own 32-character key, this one won't work)

    This is part of getting_started.R in the project, ECODATA Homework 1

Documentation (Optional)