0.1 An overview of Trade War between USA and China

Trump declared the trade war between China and USA and announced tariffs of more than $200billion on Chinese goods. It is going to be the largest trade war in the history. News often reports this trade war not only it will have enormous impact on USA and China both politically and economically, but there is a risk that it may start a ripple effect and impact other countries and areas around the globe. However, we want to know how exactly it will effect the current trading status between USA and China.

0.2 Data Processing

We only considering country_or_area in China, China, Hong Kong SAR and USA. For flow status We are only considering export and import. In addition, Since China joined WTO in 2001, so we will perform analysis on the data from 2002 to 2016.

#country
trade1 <- filter(trade, trade$country_or_area == "China" | trade$country_or_area == "China, Hong Kong SAR" | trade$country_or_area =="USA")

# year >2001
trade1 <- filter(trade1, trade1$year > 2001)

trade2 <- filter(trade1, trade1$flow=="Export" | trade1$flow=="Import")
trade2$country <- ifelse(trade2$country_or_area == "China" | trade2$country_or_area =="China, Hong Kong SAR", "china" , "usa")

0.3 Top Categories for Export and Import

0.3.1 China

To our surprise, Pearls, and precious gem is the top category for Chinese Export. We see the vehicle related product is on the new tariff list. Therefore , we will do a more detailed investigation in this. In addition, it seems like the top import categories are not in the tariff lists.

## china export

chinaex <- filter (trade2, trade2$country=="china"  & trade2$flow== "Export")

# top 5 chinese export 
chinaex1 <- group_by(chinaex, category)
chinaex2 <- dplyr::summarise(chinaex1, sumusd=sum(trade_usd))

chinaex2 <- chinaex2[order(-chinaex2$sumusd),]
chinaex3 <- chinaex2[c(2:7),]

# top 5 chinese import 
chinaim <- filter (trade2, trade2$country=="china"  & trade2$flow== "Import")
chinaim1 <- group_by(chinaim, category)
chinaim2 <- dplyr::summarise(chinaim1, sumusd=sum(trade_usd))

chinaim2 <- chinaim2[order(-chinaim2$sumusd),]
chinaim3 <- chinaim2[c(2:7),]

ggplot(data=chinaex3, aes(x=reorder(category,sumusd), y=sumusd))+geom_bar(stat="identity", aes(fill=category))+theme(axis.text.x = element_text(angle = 60, hjust = 1))+coord_flip() +ggtitle("Top 6 Category for Chinese Export") + xlab("Category") +ylab("USD value")+theme(legend.position = "none")

ggplot(data=chinaim3, aes(x=reorder(category,sumusd), y=sumusd))+geom_bar(stat="identity", aes(fill=category))+theme(axis.text.x = element_text(angle = 60, hjust = 1))+coord_flip() +ggtitle("Top 6 Category for Chinese Import") + xlab("Category") +ylab("USD value")+theme(legend.position = "none")

0.3.2 USA

The top category for USA export, we see aircraft and aerospace related products. We know that majority of those aircraft products are sold to China. If China government started to add tax to USA aircraft related products, then it might slow down the trading frequency in aero space industry. Personally, I think it is interesting that cereals is the second top trading category.

## usa export

usaex <- filter (trade2, trade2$country=="usa"  & trade2$flow== "Export")

# top 5 usa export 
usaex1 <- group_by(usaex, category)
usaex2 <- dplyr::summarise(usaex1, sumusd=sum(trade_usd))

usaex2 <- usaex2[order(-usaex2$sumusd),]
usaex3 <- usaex2[c(3:7),]

# top 5 usa import 
usaim <- filter (trade2, trade2$country=="usa"  & trade2$flow== "Import")
usaim1 <- group_by(usaim, category)
usaim2 <- dplyr::summarise(usaim1, sumusd=sum(trade_usd))

usaim2 <- usaim2[order(-usaim2$sumusd),]
usaim3 <- usaim2[c( 3:8),]


#ausaim3 <- usaim2[c( 3:20),]
#achinaim3 <- chinaim2[c(2:20),]

#im3<- merge(ausaim3, achinaim3, by="category")


#ausaex3 <- usaex2[c( 3:30),]
#achinaex3 <- chinaex2[c(2:30),]

#ex3<- merge(ausaex3, achinaex3, by="category")


ggplot(data=usaex3, aes(x=reorder(category,sumusd), y=sumusd))+geom_bar(stat="identity", aes(fill=category))+theme(axis.text.x = element_text(angle = 60, hjust = 1))+coord_flip() +ggtitle("Top 5 Category for USA Export") + xlab("Category") +ylab("USD value")+theme(legend.position = "none")

ggplot(data=usaim3, aes(x=reorder(category,sumusd), y=sumusd))+geom_bar(stat="identity", aes(fill=category))+theme(axis.text.x = element_text(angle = 60, hjust = 1))+coord_flip() +ggtitle("Top 6 Category for USA Import") + xlab("Category") +ylab("USD value")+theme(legend.position = "none")

0.4 Trade war Commodity

0.4.1 An overall review of tariff commodity trade in the world

In the previous section, we found the top trading value categories. In this section, We will focus on the commodities that are listed in the tariff lists. We will select the commodities including, swine, aircraft, electric, stell, medical device, cotton, aluminium and vehicles. We can see the China and USA import and Exoport are both around 100 Billion, which is consitent with the news statement (more than 200B trading goods will effected by the tariff war). Moreover, the graph showed China and USA import and export take about 20% of the trading of world tariff goods. We also noticed, the tariff war might have a larger impact in Chinese trading, because the percent of trading in tariff goods has higher rate than USA.

## Overall review of world tariff lists

overall <- filter(trade2, trade2$category=="all_commodities" )
overall1 <- group_by(overall, flow, country, year)
overall2 <- dplyr::summarise(overall1, sumusd=sum(trade_usd))

trade$gc<- ifelse (grepl("Swine", trade$commodity,  ignore.case=TRUE)=="TRUE","animal product",
             ifelse(grepl("Aircraft", trade$commodity, ignore.case=TRUE)=="TRUE","aircraft product",
            ifelse(grepl("electric", trade$commodity, ignore.case=TRUE)=="TRUE", "Electric product",
            ifelse(grepl("steel", trade$commodity, ignore.case=TRUE)=="TRUE", "Steel Product",
            ifelse(grepl("medical", trade$commodity, ignore.case=TRUE)=="TRUE", "Medical Product",
            ifelse(grepl("cotton", trade$commodity, ignore.case=TRUE)=="TRUE","Cotton Product",
           ifelse(grepl("aluminium", trade$commodity, ignore.case=TRUE)=="TRUE","Aluminium Product",
           ifelse(grepl("cars", trade$commodity, ignore.case=TRUE)=="TRUE","Auto Product",
                  ifelse(grepl("automobiles", trade$commodity, ignore.case=TRUE)=="TRUE","Auto Product",
            ifelse(grepl("vehicles", trade$commodity, ignore.case=TRUE)=="TRUE","Auto Product", "Other"))))))))))

atrade<- filter(trade, trade$gc != "Other")

atrade$country <- ifelse(atrade$country_or_area == "China" | atrade$country_or_area =="China, Hong Kong SAR", "china" , atrade$country_or_area)

atrade1 <- filter(atrade, (flow=="Import" | flow=="Export" ) & year >2001)

atrade2 <- group_by(atrade1, flow, year)
atrade3 <- dplyr::summarise(atrade2, sumusd=sum(trade_usd))

aim <- filter(atrade3 , flow=="Import")
aex <-filter(atrade3, flow=="Export")
colnames(aex)<-c("f", "year", "usd")

aall <- merge(aim, aex, x.by=year)



# USA + China percentage
ausa <- filter(atrade1, atrade1$country_or_area=="USA")
ausa2 <- group_by(ausa, flow, year)
ausa3 <- dplyr::summarise(ausa2, sumusd1=sum(trade_usd))
acn <- filter(atrade1, atrade1$country=="china")
acn2 <- group_by(acn, flow, year)
acn3 <- dplyr::summarise(acn2, cusd=sum(trade_usd))

aall$usai<- as.numeric(unlist(ausa3[c(16:30), c(3)]))
aall$usae<- as.numeric(unlist(ausa3[c(1:15), c(3)]))
aall$cni<- as.numeric(unlist(acn3[c(16:30), c(3)]))
aall$cne <- as.numeric(unlist(acn3[c(16:30), c(3)]))

#china & usa percentage over the world
aall$usacni <- aall$usai+aall$cni
aall$usacne <- aall$usae+aall$cne
aall$usacnipct <-  aall$usacni/aall$sumusd
aall$usacnepct <-  aall$usacne/aall$usd
aall$usaipct <-  aall$usai/aall$sumusd
aall$usaepct <-  aall$usae/aall$usd
aall$cnipct <-  aall$cni/aall$sumusd
aall$cnepct <-  aall$cne/aall$usd



# Line plot for overall tariff lists
p <- plot_ly(aall , x=~year, y=~usd, name= "Import", type="scatter",  mode="lines") %>%
    add_trace(y= ~sumusd , name="Export" , mode="lines+markers") %>%
    add_trace(y= ~usacni , name="China and USA Export" , mode="lines+markers") %>%
     add_trace(y= ~usacne , name="China and USA Import" , mode="lines+markers") %>%
    layout (  title= "Tariff Commodity Trade History in the World ")
p
# China and USA percentage 

p1 <- plot_ly(aall , x=~year, y=~usacnipct, name= "China & USA Export %", type="scatter",  mode="lines") %>%
     add_trace(y= ~usacnepct , name="China and USA Import %" , mode="lines+markers") %>%
     add_trace(y= ~usaepct , name="USA Export %" , mode="lines+markers") %>%
  add_trace(y= ~usaipct , name="USA Import %" , mode="lines+markers") %>%
    add_trace(y= ~cnepct , name="China Export %" , mode="lines+markers") %>%
    add_trace(y= ~cnipct , name="China Import %" , mode="lines+markers") %>%
    layout (  title= "China and USA percent in the Tariff Commodity Trade History")
p1

0.4.2 USA tariff trading goods distribution

0.4.2.1 USA Import

Among the tariff goods, Aircraft related products has the highest trading value, more that 97.5%. It carries almost the whole import market for USA, which is consistent with our previous result.

trade2$gc<- ifelse (grepl("Swine", trade2$commodity,  ignore.case=TRUE)=="TRUE","animal product",
             ifelse(grepl("Aircraft", trade2$commodity, ignore.case=TRUE)=="TRUE","aircraft product",
            ifelse(grepl("electric", trade2$commodity, ignore.case=TRUE)=="TRUE", "Electric product",
            ifelse(grepl("steel", trade2$commodity, ignore.case=TRUE)=="TRUE", "Steel Product",
            ifelse(grepl("medical", trade2$commodity, ignore.case=TRUE)=="TRUE", "Medical Product",
            ifelse(grepl("cotton", trade2$commodity, ignore.case=TRUE)=="TRUE","Cotton Product",
           ifelse(grepl("aluminium", trade2$commodity, ignore.case=TRUE)=="TRUE","Aluminium Product",
           ifelse(grepl("cars", trade2$commodity, ignore.case=TRUE)=="TRUE","Auto Product",
                  ifelse(grepl("automobiles", trade2$commodity, ignore.case=TRUE)=="TRUE","Auto Product",
            ifelse(grepl("vehicles", trade2$commodity, ignore.case=TRUE)=="TRUE","Auto Product", "Other"))))))))))

war <- filter(trade2, ( country== "china" | country=="usa" ) & gc != "Other")



# usa import
warusaim <- filter(war, war$country=="usa"  & war$flow== "Import")
warusaim1 <- group_by(warusaim, gc , year)
warusaim2 <- dplyr::summarise(warusaim1, sumusd=sum(trade_usd), tax=sum(trade_usd)*1.25)


mcp <- plot_ly(warusaim2 , x= ~ year , y=~sumusd , type="scatter", mode="markers",
               color=~gc, colors="Paired", sizes=c(min(warusaim2$sumusd),max(warusaim2$sumusd)),
               marker = list(opacity = 1.2, sizemode = 'diameter'),
              text= ~paste( year, tax, gc)) %>% layout(title="USA Import Value by year")
mcp
warusaim2$pct <- warusaim2$sumusd*100/30572595934
usaim <- filter(warusaim2, year >2015)
usaim
## # A tibble: 7 x 5
## # Groups:   gc [7]
##   gc                 year      sumusd         tax     pct
##   <chr>             <int>       <dbl>       <dbl>   <dbl>
## 1 aircraft product   2016 29798777699 37248472124 97.5   
## 2 Aluminium Product  2016   252316078   315395098  0.825 
## 3 animal product     2016   314963937   393704921  1.03  
## 4 Auto Product       2016    14784614    18480768  0.0484
## 5 Cotton Product     2016    67010014    83762518  0.219 
## 6 Electric product   2016    82112584   102640730  0.269 
## 7 Steel Product      2016    42631008    53288760  0.139

0.4.2.2 USA Export

For USA export, We can see aircraft and vehicle related products add up to more than 92%. China has the policy to increase tax on those products as well. Therefore, US might facing a slow down in aerospace and automobile industry as well.

# usa export

warusaime <- filter(war, war$country=="usa"  & war$flow== "Export")

warusaim1e <- group_by(warusaime, gc , year)
warusaim2e <- dplyr::summarise(warusaim1e, sumusd=sum(trade_usd), tax=sum(trade_usd)*1.25)


mcpe <- plot_ly(warusaim2e , x= ~ year , y=~sumusd , type="scatter", mode="markers",
               color=~gc, colors="Paired", sizes=c(min(warusaim2e$sumusd),max(warusaim2e$sumusd)),
               marker = list(opacity = 1.2, sizemode = 'diameter'),
              text= ~paste( year, tax, gc)) %>% layout(title="USA Export Value by year")
mcpe
uex<- filter(warusaim2e, year >2015)
uex$pct <- uex$sumusd*100/12485822159
uex
## # A tibble: 7 x 5
## # Groups:   gc [7]
##   gc                 year     sumusd         tax     pct
##   <chr>             <int>      <dbl>       <dbl>   <dbl>
## 1 aircraft product   2016 8116807529 10146009411 65.0   
## 2 Aluminium Product  2016   24066184    30082730  0.193 
## 3 animal product     2016   13697044    17121305  0.110 
## 4 Auto Product       2016 3380901666  4226127082 27.1   
## 5 Cotton Product     2016  268470096   335587620  2.15  
## 6 Electric product   2016  674263947   842829934  5.40  
## 7 Steel Product      2016    7615693     9519616  0.0610

0.4.3 Chiness tariff trading goods distribution

0.4.3.1 China Import Summary

We can see Chinese import goods is more diversified, Auto, Aluminium and aircraft has high ratios.

#china import 

warusaimc <- filter(war, war$country=="china"  & war$flow== "Import")

warusaim1c <- group_by(warusaimc, gc , year)
warusaim2c <- dplyr::summarise(warusaim1c, sumusd=sum(trade_usd), tax=sum(trade_usd)*1.25)



mcpc <- plot_ly(warusaim2c , x= ~ year , y=~sumusd , type="scatter", mode="markers",
               color=~gc, colors="Paired", sizes=c(min(warusaim2$sumusd),max(warusaim2$sumusd)),
               marker = list(opacity = 1.2, sizemode = 'diameter'),
              text= ~paste( year, tax, gc)) %>% layout(title="China Import Value by year")
mcpc
cim<- filter(warusaim2c, year >2015)
cim$pct <- cim$sumusd*100/123012246718
cim
## # A tibble: 8 x 5
## # Groups:   gc [8]
##   gc                 year      sumusd         tax    pct
##   <chr>             <int>       <dbl>       <dbl>  <dbl>
## 1 aircraft product   2016 24271798156 30339747695 19.7  
## 2 Aluminium Product  2016  9253714012 11567142515  7.52 
## 3 animal product     2016  8270521100 10338151375  6.72 
## 4 Auto Product       2016 66044291101 82555363876 53.7  
## 5 Cotton Product     2016 11195394363 13994242954  9.10 
## 6 Electric product   2016  3099130633  3873913291  2.52 
## 7 Medical Product    2016   605288619   756610774  0.492
## 8 Steel Product      2016   272108734   340135918  0.221

0.4.3.2 China Export summary

For Chinese Export goods, we can see Electric, Auto and Cotton are the top categories. USA may import clothes from other countries. I don’t know if the qualities are as good as Chinese products. :)

warusaimce <- filter(war, war$country=="china"  & war$flow== "Export")

warusaim1ce <- group_by(warusaimce, gc , year)
warusaim2ce <- dplyr::summarise(warusaim1ce, sumusd=sum(trade_usd), tax=sum(trade_usd)*1.25)



mcpce <- plot_ly(warusaim2ce , x= ~ year , y=~sumusd , type="scatter", mode="markers",
               color=~gc, colors="Paired", sizes=c(min(warusaim2$sumusd),max(warusaim2$sumusd)),
               marker = list(opacity = 1.2, sizemode = 'diameter'),
              text= ~paste( year, tax, gc)) %>% layout(title="China Exmport Value by year")
mcpce
cex<- filter(warusaim2ce, year >2015)
cex$pct <- cex$tax*100/127224290874
cex
## # A tibble: 8 x 5
## # Groups:   gc [8]
##   gc                 year      sumusd         tax   pct
##   <chr>             <int>       <dbl>       <dbl> <dbl>
## 1 aircraft product   2016  4375064199  5468830249  4.30
## 2 Aluminium Product  2016 21637973010 27047466262 21.3 
## 3 animal product     2016  2573370254  3216712818  2.53
## 4 Auto Product       2016 32084743306 40105929132 31.5 
## 5 Cotton Product     2016 29734125792 37167657240 29.2 
## 6 Electric product   2016 33902663753 42378329691 33.3 
## 7 Medical Product    2016  1800108241  2250135301  1.77
## 8 Steel Product      2016  1116242319  1395302899  1.10

0.5 Tariff Policy Impact ?

We group all commodity trade value in Export and Import of the world and divided by the Tariff goods trade value. We see the Tariff goods has 4% of the total trading market. In addtion, China and USA together as 25% of those 4% trading. Therefore, we can conclude about 1% of total trading will be impacted by the new tariff policy in the world by the current data!

In reality, the story might be different, because I only used very basic method to extrapolate the data. If you know a better approach , please let me know! thanks for reading!

#summary of all commodity value
itrade <- filter (trade, trade$category=="all_commodities" & year>2001 & (flow=="Import" | flow=="Export"))
itrade1 <- group_by(itrade, flow , year)
itrade2 <- dplyr::summarise(itrade1, allusd=sum(trade_usd), tax=sum(trade_usd)*1.25)


aall$alle<- as.numeric(unlist(itrade2[c(1:15), c(3)]))
aall$alli <- as.numeric(unlist(itrade2[c(16:30), c(3)]))

aall$allepct <- aall$sumusd*100/aall$alli
aall$allipct <-aall$usd*100/aall$alle


p4 <- plot_ly(aall , x=~year, y=~allepct, name= "Tariff Goods Export proportion %", type="scatter",  mode="lines") %>%
     add_trace(y= ~allipct , name="Tariff Goods Import proportion %" , mode="lines+markers") %>%
    layout (  title= "Tariff Goods proportion in Export and Import")
p4
#warusaim1y <- group_by(warusaim,  year)
#warusaim2y <- dplyr::summarise(warusaim1y, sumusd=sum(trade_usd), tax=sum(trade_usd)*1.25)

#warusaim1g <- group_by(warusaim,  gc)
#warusaim2g <- dplyr::summarise(warusaim1g, sumusd=sum(trade_usd), tax=sum(trade_usd)*1.25)



#overall2c<- filter(overall2, flow=="Export" & country=="china")
#overall2u<- filter(overall2, flow=="Import" & country=="usa")

#impact <- merge(overall2c, warusaim2y,by="year")
#impact <- merge(overall2u, impact,by="year")
#impact$pct <- impact$sumusd.y/impact$sumusd.x
#impact$pctax <- impact$tax/impact$sumusd.x
#impact$diff <- impact$pctax-impact$pct
#impact$uc <- impact$sumusd/impact$sumusd.x


#impact1 <- merge(overall2c, warusaim2,by="year")
#impact1 <- merge(overall2u, impact1,by="year")
#impact1$pct <- impact1$sumusd.y/impact1$sumusd.x
#impact1$pctax <- impact1$tax/impact1$sumusd.x
#impact1$diff <- impact1$pctax-impact1$pct
#impact1$uc <- impact1$sumusd.x/impact1$sumusd


#impact1r <- filter(impact1, year>2015)
#sum(impact1r$tax)
#impact1r$imc <- impact1r$tax/sum(impact1r$tax)