[This article was first published on R-Programming – Giles Dickenson-Jones, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Soon after Trump’s tariffs were announced, it was noted the ‘reciprocal’ tariffs looked suspiciously like the US trade deficit divided by imports.
Ever the skeptic, I couldn’t believe it could be this simple, so I decided to check it out myself with the help of R and UN Comtrade data. Here’s my answer, neatly documented in R code.
If you’re interested in reproducing this analysis you’ll need to get an API key for the comtradr package.
Code block: project setup:
#load packages
library(googlesheets4)
library(tidyverse)
library(countrycode)
library(comtradr)
#set comtrade api key
set_primary_comtrade_key(ref_comtrade_api_key)
ref_gsheet_url<-"https://docs.google.com/spreadsheets/d/1AbPFX21KKfiCr8WWA6fwfPVKAjE5MUCzdWVitV0ZuWM/edit?usp=sharing"
#read data from google sheet
dta_us_tariffs<-read_sheet(ref_gsheet_url)
#add countrycodes
dta_us_tariffs<- dta_us_tariffs |>
mutate(iso3c= countrycode(sourcevar=country, origin="country.name", destination="iso3c"))
#assign _KS as as code for Kosovo as per Comtrade country code list (KSV is also used by some providers)
dta_us_tariffs[dta_us_tariffs$country=="Kosovo","iso3c"]<-"_KS"
#create reference list of focus countries
ref_focus_countries<-dta_us_tariffs$iso3c
# get bilateral trade data for US
dta_comtrade <- ct_get_data(
reporter = 'USA',
partner=dta_us_tariffs$iso3c,
commodity_code = 'TOTAL',
start_date = 2024,
end_date = 2024,
flow_direction = c('import','export')
)
# select focus variables and round to billion USD
dta_comtrade<-dta_comtrade |>
select(ref_year,partner_iso,flow_desc,fobvalue) |>
mutate(fobvalue= fobvalue/10^9)
# Pivot dataframe by flow type
dta_comtrade<-dta_comtrade |>
pivot_wider(names_from=flow_desc, values_from = fobvalue)
#calculate trade balance
dta_comtrade<-dta_comtrade |>
mutate(trade_bal= Export- Import,
trade_bal_to_m_ratio= round(trade_bal/Import,2)*100)
#join comtrade data with tariff listing
dta_us_tariffs_and_trade_flows<-left_join(dta_us_tariffs,dta_comtrade, by=c('iso3c'="partner_iso"))
There’s more I’d like to do with this data, but for now I thought I’d share my code and the answer: yes. The reciprocal tariffs look almost identical to the trade balance to imports ratio.
@carlbergstrom.com has a great thread (skeet?) on this on Bluesky.

Code block:
#create filtered dataframe where tariff > standard rate
#drop EU countries as individual reciprocal tariffs weren't published
dta_plt_us_tariffs<- dta_us_tariffs_and_trade_flows |>
filter(us_tariffs_applied >10,
EU == "N")
#plot where tariff != reciprocal tariff
plt_us_tariffs<-ggplot(data=dta_plt_us_tariffs,
aes(y=us_claimed_reciprocal_tariff,
x=trade_bal_to_m_ratio))+
geom_text(aes(label =iso3c), size=2)+
theme_minimal()+
labs(x= "Imports / Trade Balance (%)",
y="Announced 'Reciprocal' Tariff")
plt_us_tariffs
To leave a comment for the author, please follow the link and comment on their blog: R-Programming – Giles Dickenson-Jones.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.