How to use this package

Mauricio Vargas S.

2019-04-05

Package data

Available tables

Provided this package takes data from an API, it is useful to know which tables can be accessed:

library(tradestatistics)
#> 
#>     Welcome to tradestatistics package. If you are going to use this
#>     package, it means that you are ok with the usage conditions explained
#>     on https://tradestatistics.io/datasets.html
#> 
#>     Commercial purposes are strictly out of the boundaries of what you 
#>     can do with this data according to UN Comtrade dissemination clauses.
#> 
#>     Our contents are distributed under Creative Commons 
#>     Attribution-NonCommercial 4.0 International License.
#> 

ots_attributes_tables
#> # A tibble: 15 x 3
#>    table      description                        source                    
#>    <chr>      <chr>                              <chr>                     
#>  1 countries  Countries metadata                 UN Comtrade               
#>  2 products   Product metadata                   UN Comtrade               
#>  3 reporters  Reporting countries                UN Comtrade               
#>  4 communiti… Product communities                Center for International …
#>  5 product_s… Product short names                The Observatory of Econom…
#>  6 country_r… Ranking of countries               UN Comtrade               
#>  7 product_r… Ranking of products                Open Trade Statistics     
#>  8 yrpc       Bilateral trade at product level … Open Trade Statistics     
#>  9 yrp        Bilateral trade at aggregated lev… Open Trade Statistics     
#> 10 yrc        Bilateral trade at aggregated lev… Open Trade Statistics     
#> 11 yrc_expor… Bilateral trade at aggregated lev… Open Trade Statistics     
#> 12 yrc_impor… Reporter trade at product level (… Open Trade Statistics     
#> 13 yr         Reporter trade at aggregated leve… Open Trade Statistics     
#> 14 yr_short   Reporter trade at aggregated leve… Open Trade Statistics     
#> 15 yc         Product trade at aggregated level… Open Trade Statistics

Country codes

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

Product codes

Open Trade Statistics (aka OTS) uses data classified under either HS92, HS96, HS02 and HS07 (Harmonized System) and SITC rev. 1 and rev. 2 (Standard International Trade Classification). A part of our project is to combine all of this under HS07 codes, and to make it available for the period 1962-2017 even for the years before 2007 when HS07 was not in use.

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).

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 contain 4 digits long codes in our cleaned datasets (there are 5 digits long SITC codes that we are not using):

Each product belongs to a group with a given name and number according to HS classification.

Package functions

Country code

The end user can use this function to find an ISO code by providing a country name. This works by implementing partial search.

Basic examples:

Product code

The end user can use this function to find a product code by providing a product name. This works by implementing partial search.

Trade data

This function downloads data for a single year and needs (at least) some filter parameters according to the query type.

Bilateral trade at product level (Year - Reporter - Partner - Product Code)

If we want Chile-Argentina bilateral trade at product level in 1965:

Which is the same as:

If we want Chile-Argentina bilateral trade at product level in 1965-1967:

If we want Chile-Argentina bilateral trade at product level in 1965, 1966 and 1968:

If we want Chile-Argentina bilateral trade at product level in 1965 and 1966 with respect to product “0101” (Horses, asses, mules and hinnies; live):

But if we want Chile-Argentina bilateral trade at product level in 1965 with respect to all the codes that match the string “horse” at product or group name:

Another option is to pass more than one year, reporter, partner and/or product (here “0101” means to perform an exact search while “apple” will do string matching):

This latter option works with a different number of reporters and partners:

Here some fields deserve an explanation:

  • product_code: HS07 product codes (e.g. according to the table within this package, 0101 stands for “Horses, etc.”)
  • product_code_length: How many digits does product_code 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_code: International categorization of group products defined after product ID
  • group_name: English name corresponding to group_id
  • export_value_usd: Exports measured in nominal United States Dollars (USD)
  • import_value_usd: Imports measured in nominal United States Dollars (USD)
  • export_value_usd_percentage_change_1_year: Nominal increase/decrease in exports measured as percentage with respect to last year
  • export_value_usd_percentage_change_5_years: Nominal increase/decrease in exports measured as percentage with respect to five years ago
  • export_value_usd_change_1_year: Nominal increase/decrease in exports measured in USD with respect to last year
  • export_value_usd_change_5_years: Nominal increase/decrease in exports measured in USD with respect to five years ago

Bilateral trade at aggregated level (Year - Reporter - Partner)

If we want Chile-Argentina bilateral trade at aggregated level in 1965:

If we want Chile-Argentina bilateral trade at aggregated level in 1965 and 1967:

Another option is to pass more than one year, reporter and/or partner:

Reporter trade at product level (Year - Reporter - Product Code)

If we want Chilean trade at product level in 1965:

If we want Chilean trade at product level in 1965 with respect to product “0101” (Horses, asses, mules and hinnies; live):

But if we want just products exported by Chile in 1965 that also match the string “horse” at product or group name:

Another option is to pass more than one year, reporter and/or product:

Here the export_rca* and import_rca* fields contain the Revealed Comparative Advantage (RCA) of an exported product with respect to all the products with the same number of digits. The definition of RCA is detailed on Open Trade Statistics Documentation.

Reporter trade at aggregated level (Year - Reporter)

If we want Chilean trade at aggregated level in 1965:

Another option is to pass more than one year and/or reporter:

Here some fields deserve an explanation:

  • eci_4_digits_product_code: Economic Complexity Index (ECI) which is detailed on Open Trade Statistics Documentation. This index is built by using just four digits product codes.
  • eci_rank_4_digits_product_code: The rank of a country given its ECI (e.g. the highest ECI obtains the #1)
  • eci_rank_4_digits_product_code_delta_1_year: How many places a country increased or decreased with respect to last year

Product trade at aggregated level (Year - Product Code)

If we want all products trade in 1965:

If we want traded values of product “0101” (Horses, asses, mules and hinnies; live) in 1965:

If we want traded values of all products that match the string “horse” at product or group name:

Here some fields deserve an explanation:

  • pci_4_digits_product_code: Product Complexity Index (PCI) which is detailed on Open Trade Statistics Documentation. This index is built by using just four digits product codes.
  • pci_6_digits_product_code: Similar to the previous field but built by using just six digits product codes.
  • pci_rank_4_digits_product_code: The rank of a product given its PCI (e.g. the highest PCI obtains the #1)
  • pci_rank_4_digits_product_code_delta_1_year: How many places a country increased or decreased with respect to last year