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:
If you don't know a certain country code you can explore this data before using the functions.
library(oec)
country_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.
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).
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:
id
: SITC or HS product code (e.g. 5722 stands for "Initiating Devices" in SITC)id_len
: How many digits does id
contain, this can be useful to filter by depth when using HS codes (HS 6 digits is a more detailed version of HS 4 digits, and therefore you don't have to sum both or you'll be counting exports/imports twice)group_id
: An international categorization of group products defined after product IDgroup_name
: The english name corresponding to group_id
export_val
: Exports measured in United States Dollars (USD)import_val
: Imports mesured in United States Dollars (USD)export_val_growth_pct
: Nominal increase/decrease in exports measured as percentage with respect to last yearexport_val_growth_pct_5
: Nominal increase/decrease in exports measured as percentage with respect to five years agoexport_val_growth_val
: Nominal increase/decrease in exports measured in USD with respect to last yearexport_val_growth_val_5
: Nominal increase/decrease in exports measured in USD with respect to five years agoexport_rca
: Revealed Comparative Advantage (RCA) according to the equations exposed in The Atlas of Economic Complexityimport_val_growth_pct
: Nominal increase/decrease in imports measured as percentage with respect to last yearimport_val_growth_pct_5
: Nominal increase/decrease in imports measured as percentage with respect to five years agoimport_val_growth_val
: Nominal increase/decrease in imports measured in USD with respect to last yearimport_val_growth_val_5
: Nominal increase/decrease in imports measured in USD with respect to five years agotrade_exchange_val
: Corresponds to the sum of imports and exportspci
: Product Complexity Index (PCI) according to the equations exposed in The Atlas of Economic Complexitypci_rank
: Rank of a product given its PCI (e.g. the highest PCI obtains the #1)pci_rank_delta
: How many places a product increased or decreased with respect to last yeartop_exporter
: Which country exports the most of a producttop_importer
: Which country exports the most of a producttop_exporter_code
: ISO-3 code of top_exporter
top_importer_code
: ISO-3 code of top_importer
color
: Hex colors by product group, this can be useful to create visualizationsFor 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")
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.
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.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.