Skip to content

Instantly share code, notes, and snippets.

@pachadotdev
Last active October 19, 2019 15:37
Show Gist options
  • Save pachadotdev/f81b5cff47ccbdcda472b2544bc6f37f to your computer and use it in GitHub Desktop.
Save pachadotdev/f81b5cff47ccbdcda472b2544bc6f37f to your computer and use it in GitHub Desktop.
library(dplyr)
library(tradestatistics)
fji_usa <- ots_create_tidy_data(
years = 2017, reporters = "fji", partners = "usa",
include_shortnames = T
)
fji_usa_2 <- fji_usa %>%
select(product_shortname_english, export_value_usd) %>%
arrange(-export_value_usd) %>%
mutate(export_value_share = round(100 * export_value_usd /
sum(export_value_usd, na.rm = T), 2))
eu28 <- ots_countries %>%
filter(eu28_member == 1) %>%
select(country_iso)
ame_eu28 <- ots_create_tidy_data(
years = 2017, reporters = "c-am", partners = "all",
table = "yrp"
)
ame_eu28_2 <- ame_eu28 %>%
mutate(is_eu28 = ifelse(partner_iso %in% eu28$country_iso, 1, 0)) %>%
group_by(reporter_iso, is_eu28) %>%
summarise(export_value_usd = sum(export_value_usd, na.rm = T)) %>%
group_by(reporter_iso) %>%
mutate(pct_to_eu28 = export_value_usd / sum(export_value_usd, na.rm = T)) %>%
filter(is_eu28 == 1) %>%
select(reporter_iso, export_value_usd, pct_to_eu28) %>%
arrange(-export_value_usd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment