Importing U.S. exchange rate data from the Federal Reserve and standardizing country names across datasets

Category : Research

Importing U.S. exchange rate data from the Federal Reserve and standardizing country names across datasets

Download the PDF from SSRN.


fxrates is a program to import historical US exchange rate data from the Federal Reserve and to calculate the daily change of the exchange rates. Since, many cross-country datasets use different spellings and conventions for country names, a second command countrynames is introduced to convert country names to a common naming standard.
Keywords Exchange rates, country names, standardization, data management, historical data


Often, economic and financial researchers must convert between currencies in order to facilitate cross-country comparisons. We provide a program, entitled fxrates, which downloads daily foreign exchange rates, relative to the US dollar, from the Federal Reserve’s database.

Working with multiple cross-country datasets, such as international foreign exchange rates, introduces a unique problem: variations in country names. They are often spelled differently, or follow different grammatical conventions, across datasets. Some common differences between datasets include: “North Korea” rather than “Korea, North”, or “Korea, Democratic People’s Republic” or even “Korea, DPR.” Likewise, “United States of America”, is often “United States”, “USA”, “U.S.A.”, “U.S.”, or “US”. Sometimes one dataset may have country names in all caps. Sometimes, country names have inadvertent leading or trailing spaces. We provide a second program, entitled countrynames, which renames many country names to follow a standard convention. The program is, of course, editable, so that researchers may opt to use their own naming preferences.

The fxrates command


  • namelist is a list of country abbreviations for the countries whose foreign exchange data you wish to download from the Federal Reserve’s website. Exchange rates for all available countries will be downloaded if namelist is omitted. The list of countries includes the following:
    al (Australia), au (Autria), be (Belgium), bz (Brazil), ca (Canada), ch (China, P.R.), dn (Denmark), eu (EMU member countries), ec (European Union ECU), fn (Finland), fr (France), ge (Germany), gr (Greece), hk (Hong Kong), in (India), ir (Ireland), it (Italy), ja (Japan), ma (Malaysia), mx (Mexico), ne (Netherlands), nz (New Zealand), no (Norway), po (Portugual), si (Singapore), sf (South Africa), ko (South Korea), sp (Spain), sl (Sri Lanka), sd (Sweden), sz (Switzerland), ta (Taiwan), th (Thailand), uk (United Kingdom) and ve (Venezuela).
  • period(2000/1999/1989) specifies which block of dates to download. The Federal Reserve foreign exchange database is separated into three blocks: one ending in 1989, a second for 1990-1999, and a third for 2000 through the present. The default (omitting the period) is to download the three separate files and merge them automatically, so that the user has all FX data available. You can specify one or more periods. If you know which data range you wish to download, however, you could save time by specifying which of the three blocks to download. Specifying all three periods is equivalent to the default of downloading all the data.
  • chg(ln/per/sper) is the periodic return. Three different percent-changes can be calculated for the adjusted closing price: natural log difference, percentage change and symmetrical percentage change. Whenever one of these is specified, a new variable is created with the appropriate prefix: “ln” for the first-difference of logs method, “per” prefix for the percent change, and “sper” as the prefix for the symmetric percent change.
  • save(filename) is the output file name. Stata data file is created under the current working directory.

How to install
Then, click on the fxrates link and then “click here to install”.

Example #1: Entire daily exchange rate dataset

This example uses fxrates to import the entire daily exchange rate dataset from the Federal Reserve. By not specifying the countries, fxrates downloads data from all countries. By not specifying the period, fxrates defaults to downloading data for all available dates.

Screen Shot 2016-08-14 at 7.30.03 PM

Screen Shot 2016-08-14 at 7.31.29 PM

Ouput such as “au does not have 00” indicates that there were no observations in a particular block of years (in this case, the 2000-present block) for the particular country. When this appears, it is most often the case that the currency had been discontinued, as when Austria joined the Euro.

Example #2: French Franc, German Deutschmark and Hong Kong Dollar

This second example downloads the exchange rates of the US dollar versus the French Franc, the German Deutschmark and the Hong Kong Dollar, for all the available dates.

Screen Shot 2016-08-14 at 7.34.41 PM

Example #3: Daily changes

In this example, we download the exchange rate data for US versus France, German, and Hong Kong. As no period was specified, fxrates downloads the data from all available dates. We also specified that fxrates calculate the daily percent change, calculated in two different ways: as the log first-difference, and as the arithmetic daily percent change. The log-difference percent change of the US-French exchange rate is reported as the variable ln_fr. The arithmetic percent change of the US-HK exchange rate is reported as the variable per_hk.

Screen Shot 2016-08-14 at 7.37.39 PM





The countrynames command



The command countrynames changes the name of a country in a dataset to correspond to a more standard set of names. By default, countrynames creates a new variable, _changed, containing numeric codes which indicate which country names have been changed. A code of 0 indicates no change; a code of 1 indicates that the country’s name has been changed. It is recommended that whenever two different cross-country datasets are being merged, countrynames is run on both datasets. This minimizes the chance that a difference in names between datasets will prevent a proper merge from occurring.

How to install
Then, click on the countrynames link and then “click here to install”.

Example #1: Usage

In this example, we use two macroeconomic datasets that have countries named slightly differently. One dataset is native to, and is shipped with Stata; the second is available on the Stata website.

Screen Shot 2016-08-14 at 8.02.20 PM

In fact, all of the spellings in the “educ99gdp” dataset correspond to the preferred names in countrynames, so nothing is required of us here. We could run countrynames just to be on the safe side, but it won’t have any effect as the countries here just happen to follow the countrynames names. It is, however, good practice to run countrynames whenever merging countries, to maximize the chances that the two datasets use the same country names.

The second dataset, using World Health Organization data, is from Kohler (2005). The data are available from the Stata website.

Screen Shot 2016-08-14 at 8.05.12 PM

We now run countrynames to standardize the names of the countries. This will rename “United States of America” to “United States”, as it was in the first dataset.

Screen Shot 2016-08-14 at 8.06.28 PM

Notice that _changed is equal to 1 for the “United States” entry, indicating that its name was once something different.

Having run countrynames on both datasets, we have increased the chances that countries in both datasets follow the same naming convention. We are now safe to merge the datasets.

Screen Shot 2016-08-14 at 8.07.55 PM

The merge results table above is important. It is the results of merging a dataset that used the countrynames command (master: who2001.dta) and a dataset that did not use the countrynames command (using: temp1.dta). If the using dataset includes a country name that is not renamed with countrynames, then it will appear in the merge results table above.

Screen Shot 2016-08-14 at 8.08.41 PM

How to add, remove or change country names within the command

It is possible to add, remove or change the country name entries within the countrynames command. After opening the countrynames.ado file with a do-file editor (any text editor), it is possible to delete country name entries, add new entries or to change spellings according to the user preferences. Any changes made to the countrynames.ado file should be saved. The discard command will refresh the countrynames command with the user updates along with all the ado installations to Stata. It is recommended to confirm the updates to the countrynames command with a merge table.