The Federal Reserve Economic Data (FRED) repository contains over 812,000 of economic and financial time series. FRED includes data from a variety of sources, including the Federal Reserve, the Penn World Table, Eurostat, the World Bank, and U.S. statistical agencies, among others. You can use Stata's fredsearch command to search for data and use Stata's import fred command to import data directly from the FRED website.
You will need a FRED account and an API key to access FRED data. This website will guide you through the process of getting a key: https://fred.stlouisfed.org/docs/api/api_key.html.
You can use Stata's set fredkey command to send your FRED key to the FRED website.
. set fredkey type your FRED key here
Now we are ready to search for data. Let's search for monthly data on the exchange rate between the U.S. dollar and the Japanese yen.
. fredsearch us dollar yen exchange rate monthly
Series ID Title Data range Frequency |
EXJPUS Japanese Yen to U.... 1971-01-01 to 2023-12-01 Monthly |
Total: 1 |
The output tells us that there is a data series named EXJPUS that contains monthly data beginning on January 1, 1971.
We can import these data into Stata using the import fred command.
. import fred EXJPUS
Summary |
Series ID Nobs Date range Frequency |
EXJPUS 636 1971-01-01 to 2023-12-01 Monthly |
# of series imported: 1 |
highest frequency: Monthly |
lowest frequency: Monthly |
The output tells us that we imported 636 observations. Let's type describe to verify that our data imported successfully.
. describe Contains data Observations: 636 Variables: 3
Variable Storage Display Value |
name type format label Variable label |
datestr str10 %-10s observation date |
daten int %td numeric (daily) date |
EXJPUS float %9.0g Japanese Yen to U.S. Dollar Spot Exchange Rate |
Sorted by: datestr |
The variable datestr contains the date for each observation stored as a string. The variable daten contains the date stored as a number with a date display format. Type help dates if you would like to learn more about using date data in Stata. The variable EXJPUS contains the Japanese yen to U.S. dollar spot exchange rate.
Lets use the list command to view the first five observations.
. list in 1/5
datestr daten EXJPUS | |||
1. | 1971-01-01 01jan1971 358.02 | ||
2. | 1971-02-01 01feb1971 357.545 | ||
3. | 1971-03-01 01mar1971 357.5187 | ||
4. | 1971-04-01 01apr1971 357.5032 | ||
5. | 1971-05-01 01may1971 357.413 | ||
We could use the daterange() option to import data for a specific range of dates. For example, we could import the exchange rate data beginning January 1, 1980 and ending January 1, 2000 using the following command. Note that we added the clear option to clear Stata's memory before we imported the new data.
. import fred EXJPUS, daterange(1980-1-1 2000-1-1) clear
Summary |
Series ID Nobs Date range Frequency |
EXJPUS 241 1980-01-01 to 2000-01-01 Monthly |
# of series imported: 1 |
highest frequency: Monthly |
lowest frequency: Monthly |
FRED data series include metadata that are saved as characteristics. You can learn more about characteristics by typing help char. For now, let's just type char list to view the metadata that are included with this dataset.
. char list EXJPUS[Title]: Japanese Yen to U.S. Dollar Spot Exchange Rate EXJPUS[Series_ID]: EXJPUS EXJPUS[Source]: Board of Governors of the Federal Reserve System (US) EXJPUS[Release]: G.5 Foreign Exchange Rates EXJPUS[Seasonal_Adjustment]: Not Seasonally Adjusted EXJPUS[Date_Range]: 1971-01-01 to 2023-12-01 EXJPUS[Frequency]: Monthly EXJPUS[Units]: Japanese Yen to One U.S. Dollar EXJPUS[Last_Updated]: 2024-01-02 15:20:03-06 EXJPUS[Notes]: Averages of daily figures. Noon buying rates in New York City for cable transfer..
Nearly all FRED data are time series. You will need to use the tsset command to use Stata's extensive collection of time-series features. You can learn more about declaring time-series data by typing help tsset. But for now, let's type tsset daten to tell Stata that daten is the time variable in our time-series dataset.
. tsset daten Time variable: daten, 01jan1980 to 01jan2000, but with gaps Delta: 1 day
Now we can type tsline EXJPUS to view a graph of the exchange rate over time.
. tsline EXJPUS
Let's save our FRED data to a Stata dataset by typing save EXJPUS.
. save EXJPUS
You can watch a demonstration of these commands by clicking on the link to the YouTube video below. You can read more about these commands by clicking on the links to the Stata manual entries below.
Watch Import FRED (Import Federal Reserve Economic Data) in Stata.
Read more in the Stata Programming Reference Manual; see [P] char.
Read more in the Stata Data Management Reference Manual; see [D] clear, [D] copy, [D] describe, [D] dir, [D] import fred, [D] list, [D] sysuse, and [D] save.
Read more in the Stata Time-Series Reference Manual; see [TS] tsset and [TS] tsline.