knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

The Observatory of Economic Complexity is the world's leading visualization engine for international trade data. oec provides an easy way to obtain data from the OEC by accessing its API.

Using the oec R package is all about efficiency, without this package you could obtain the same data from the API at the expense of using additional time and effort for the same results. As an API wrapper and utility program this package makes data obtaining faster and easier for you.

This is what the package does:

Package data

Country codes

If you don't know a certain country code you can explore this data before using the functions.

library(oec)

country_codes

Product codes

The OEC provides data classified using either HS92, HS96, HS02 and HS07 (Harmonized System) or SITC rev. 2 (Standard International Trade Classification).

As UN Comtrade explains both HS and SITC are trade classifications that are updated by releasing new revisions, and when a classification is released then it remains unaltered. For example, HS92 was released in 1992 and its product codes remain unaltered until today, while newer classifications (e.g. HS07) were created to include newer products (e.g. it was important to provide more details about electronic products that did not exist when HS92 was created).

The only difference between the OEC and official HS/SITC product names is that the OEC provides shortened product names (e.g. under SITC 6821 stands for "Copper and copper alloys, refined or not, unwrought" which we can simplify to "Copper (unwrought)").

Each of these classifications consists in numeric codes and a detailed product name associated to each code, for example HS92 (and all HS revisions) contain 4 and 6 digits long codes while SITC does only cointain 4 digits long codes:

hs92

Each product belongs to a group and the color column (given after product groups) allows to use the same palettes as the official website.

Package functions

get_data

This function downloads data for a single year and needs (at least) a pairs of countries and a valid year according to the trade classification.

The API returns data for different trade classifications: (i) SITC (1962-2016); (ii) HS92 (1992-2016); (iii) HS96 (1996-2016); (iv) HS02 (2002-2016); (v) HS07 (2007-2016).

Correct input

Chile-Argentina bilateral trade data in 2015 (SITC):

# What does Chile exchange with Argentina?  
# year 1980 - SITC (4 characters)
get_data("chl", "arg", 1980)

Here some columns deserve an explanation:

For the other classifications is similar:

# What does Chile exchange with Argentina?  
# year 2015 - HS07 (4 and 6 characters)
get_data("chl", "arg", 2015, "hs07")

If you need data for more than one year you can write the years as a vector:

# What does Chile exchange with Argentina?  
# years 2010 and 2015 - HS07 (4 and 6 characters)
get_data("chl", "arg", c(2010,2015), "hs07")

Incorrect input

Chile-Argentina bilateral trade data in 2000 (HS02):

# What does Chile exchange with Argentina?  
# year 2000 - HS02 (4 and 6 characters)
get_data("chl", "arg", 2000, "hs02")

The problem here is that HS02 data is only available since 2002.

Special cases

Andorra-France bilateral trade data in 2015 (SITC):

# What does Andorra exchange with France?  
# year 2015 - SITC (4 characters)
get_data("and", "fra", 2015)

The problem here is that Andorra did not report SITC data in 2015 but they reported HS07 data.

Andorra-France bilateral trade data in 2015 (HS07):

# What does Andorra exchange with France?  
# year 2015 - HS07 (4 and 6 characters)
get_data("and", "fra", 2015, "hs07")

The OEC has some situations as the example above. Not all countries report their trade numbers using all trade classifications.



pachamaltese/oec documentation built on May 24, 2019, 5:57 p.m.