knitr::opts_chunk$set( cache = FALSE, collapse = TRUE, message = FALSE, comment = "#>" )
This vignette explains the functions within this package. The idea is to show how this package simplifies obtaining data from (api.tradestatistics.io)[https://api.tradestatistics.io].
library(tradestatistics)
Provided that this package obtains data from an API, it is useful to know which tables can be accessed:
ots_tables
The ITPD-E table means "International Trade and Production Database for Estimation" and does not contain imputed values.
The ITPD-S table means "International Trade and Production Database for Simulation" and contains imputed values using the gravity model of trade.
The most aggregated tables are itpde_imp/itpds_imp (for imports, or with _exp for exporter) which contains how many dollars each country imports and exports in a year.
The less aggregated tables are itpde/itpds which detail bilateral trade at industry level in a year.
For the complete detail you can check tradestatistics.io.
The Package Functions section explains that you don't need to memorize all ISO codes. The functions within this package are designed to match strings (i.e. "United States" or "America") to valid ISO codes (i.e. "USA").
Just as a reference, the table with all valid ISO codes can be accessed by running this:
ots_countries
The functions within this package are designed to match strings (i.e. "agriculture") to sector/industry codes.
ots_sectors ots_industries
The end user can use this function to find a dynamic ISO-3 code by providing a country name. This works by implementing partial search.
Basic examples:
# Single match with no replacement ots_country_code("Chile") # Single match with replacement ots_country_code("America") # Double match with no replacement ots_country_code("Germany")
The function ots_country_code() is used by ots_create_tidy_data() in a way that you can pass parameters
like ots_create_tidy_data(... importers = "Chile" ...) and it will automatically replace your input for a
valid code in case there is a match. This will be covered in detail in the Trade Data section.
The end user can find a code or a set of codes by looking for keywords for commodities or groups. The function
ots_commodity_code() allows to search from the official commodities and groups in the Harmonized system:
ots_sector_code(" AgriCulture ") ots_industry_code(" CeReaLS")
This function downloads data for a single year and needs (at least) some filter parameters according to the query type.
Here we cover aggregated tables to describe the usage.
If we want Chile-Argentina bilateral trade at community level in 2019:
ots_create_tidy_data( years = 2019, importers = "chl", exporters = "arg", table = "itpde_imp_exp" )
We can pass two years or more, several reporters/partners, and filter by commodities with exact codes or code matching based on keywords:
ots_create_tidy_data( years = 2018:2019, importers = c("chl", "Peru", "col"), exporters = c("arg", "Brazil"), table = "itpde_imp_exp" )
ots_create_tidy_data( years = 2018:2019, importers = c("chl", "Peru", "col"), exporters = c("arg", "Brazil"), table = "itpde_imp_exp_sec" )
ots_create_tidy_data( years = 2018:2019, importers = c("chl", "Peru", "col"), exporters = c("arg", "Brazil"), table = "itpde_ind" )
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.