Skip to content

Latest commit

 

History

History
64 lines (47 loc) · 2.3 KB

README.md

File metadata and controls

64 lines (47 loc) · 2.3 KB

ComtradeDatabaseDownloader

GitHub release (latest by date) GitHub release date

Download and wrangle global trade data from the UN Comtrade Database and output it to a dataframe object suited for Gravity Model estimation.

Prerequisites:

  • Access to a network with a premium site license subscription to the Comtrade Database.
  • Creation of an API token

Quick installation guide:

# install.packages("devtools")
devtools::install_github("andreas-andersen/ComtradeDatabaseDownloader")

Specify data frequency and periods to download and assign data.frame to an object.

df <- get_comtrade(
    freq = "monthly",
    startyear = 2020,
    startmonth = 1,
    endyear = 2020,
    endmonth = 3,
    token = "YOURTOKENHERE"
)

The above example will download Comtrade data containing the 3 monthly trade records from January 2020 to March 2020 and output the data.frame below.

Output data.frame

Additional features:

  • Fast reading/writing of .csv files using data.table::fread(). (Requires the bit64 package to store large integer values)
  • Automatic saving of progress in a temp file in case of connection errors.

Notes:

Sometimes, the Comtrade Database may reject your request for a file.

Error

If this happens, first make sure your Comtrade token is correct. Secondly, Comtrade seems to randomly reject requests, especially if many files have been downloaded in a row. The current version of the package will attempt to reconnect twice in case of a failed request. If this fails, try re-entering the same get_comtrade() command later. As long as this is done during the same R-session, the package will continue on from a temp file which has saved the progress.

You should estimate approx. 2.5 minutes to download and process one period (depending on your internet connection and processing power). In other words, downloading a full year of monthly data should take about 30 minutes.