---
title: "ExportGenius Trade Analysis: Belarus"
author: Gagan Atreya
date: today
format:
html:
toc: true
toc-location: left
toc-depth: 4
theme: lumen
fontsize: large
code-fold: true
code-tools: true
code-summary: "Display code"
code-overflow: wrap
editor:
markdown:
wrap: 72
editor_options:
chunk_output_type: console
---
## **Tobacco exports**
```{r, error = F, message = F, warning = F}
## ----error = F, message = F, warning = F--------------------------------------------------------
rm(list = ls())
pacman::p_load(readxl, vtable, tidyverse,
lubridate, data.table, zoo,
readODS, patchwork, scales)
df <- fread("~/Desktop/soc_ace_2024/data/exportgenius/tobacco/belarus/Belarus-MirrorExport-Tobacco.csv")
df$date <- dmy(df$Date)
df$description <- df$`Product Description`
df$destination_country <- df$`Destination Country`
df$supplier <- df$Exporter
df$importer <- df$Buyer
df$total_value <- df$`Total Value USD`
df$weight <- df$`Gross Weight Kg`
df$price_invoice <- df$total_value/df$weight
df <- df[, c("date", "description", "destination_country",
"supplier", "importer", "price_invoice", "total_value")]
df02 <- fread("~/Desktop/soc_ace_2024/scripts/exportgenius/gold_analyses_latest/goldprice.csv")
df02$date <- ymd(df02$date)
df <- merge(df, df02, by = "date")
df$price_benchmark <- df$price_gram
## Remove outlier transaction:
# summary(df$total_value)
df <- df[df$total_value < 650000, ]
plot01 <- ggplot(df,
aes(x = date,
y = total_value)) +
geom_line() +
geom_point() +
# ylim(15, 120) +
geom_vline(xintercept = as.Date("2022-02-24"),
linetype = "dashed",
color = "black",
size = 0.45) +
labs(title = "Belarus Tobacco Exports",
x = "Date",
y = "Total Value") +
theme_bw()
plot01
plot02 <- df %>%
ggplot( aes(x = date,
y = total_value,
color = destination_country))+
geom_line()+
geom_vline(xintercept = as.Date("2022-02-24"),
linetype = "dashed",
color = "black",
size = 0.45) +
geom_point()+
labs(title = "Belarus Tobacco Exports",
x = "Date",
y = "Total value")+
theme_bw()
plot02
plot03 <- df %>%
ggplot( aes(x = date,
y = total_value)) +
geom_line()+
geom_point()+
geom_vline(xintercept = as.Date("2022-02-24"),
linetype = "dashed",
color = "black",
size = 0.45) +
facet_wrap(~destination_country, ncol = 3)+
labs(title = "Belarus Tobacco Exports by Destination",
x = "Date",
y = "Total Value") +
theme_bw()
plot03
df <- as.data.table(df)
df <- df[!is.na(price_invoice)]
df <- df[order(-price_invoice)]
df$price_difference <- df$price_invoice - df$price_benchmark
df03 <- df[, c("date", "price_invoice", "price_benchmark")]
df$price_difference2 <- scale(df$price_difference)
df$price_benchmark2 <- scale(df$price_benchmark)
df <- df[price_difference2 != max(price_difference2)]
plot04 <- ggplot(df, aes(x = date,
y = price_difference2)) +
geom_segment(aes(x = date,
xend = date,
y = 0,
yend = price_difference2
#,color = price_difference2 > 0
)) +
geom_point(color = "black", size = 2) +
# ylim(-2,2)+
geom_vline(xintercept = as.Date("2022-02-24"),
linetype = "dashed",
color = "black",
size = 0.45) +
theme_bw() +
scale_color_manual(values = c("red", "blue")) +
labs(title = "Belarus Tobacco Imports: Price Differentials Over Time",
x = "Date",
y = "Price differential (standardized)") +
guides(color = FALSE)
plot04
table(df$destination_country)
## ----error = F, message = F, warning = F--------------------------------------------------------
df11 <- df[df$destination_country %in% c("Belarus", "Kazakhstan",
"Russia", "Ukraine") ]
plot11 <- df11 %>%
ggplot( aes(x = date,
y = total_value)) +
geom_line()+
geom_point()+
geom_vline(xintercept = as.Date("2022-02-24"),
linetype = "dashed",
color = "black",
size = 0.45) +
facet_wrap(~destination_country, ncol = 2)+
labs(title = "Belarus Tobacco Exports",
x = "Date",
y = "Total Value") +
theme_bw()
plot11
## ----error = F, message = F, warning = F--------------------------------------------------------
plot12 <- ggplot(df11, aes(x = date,
y = price_difference2)) +
geom_segment(aes(x = date,
xend = date,
y = 0,
yend = price_difference2,
color = price_difference2 > 0)) +
geom_point(color = "black", size = 2) +
geom_vline(xintercept = as.Date("2022-02-24"),
linetype = "dashed",
color = "black",
size = 0.45) +
theme_bw() +
scale_color_manual(values = c("red", "blue")) +
labs(title = "Belarus Tobacco Exports: Price Differentials Over Time",
x = "Date",
y = "Price differential (standardized)") +
facet_wrap(~destination_country, ncol = 2)+
guides(color = FALSE)
plot12
```
### Belarus
```{r, error = F, message = F, warning = F}
df11 <- df[df$destination_country == "Belarus", ]
plot11 <- df11 %>%
ggplot( aes(x = date,
y = total_value)) +
geom_line()+
geom_point()+
geom_vline(xintercept = as.Date("2022-02-24"),
linetype = "dashed",
color = "black",
size = 0.45) +
facet_wrap(~destination_country, ncol = 2)+
labs(title = "Belarus Tobacco Exports: Belarus",
x = "Date",
y = "Total Value") +
theme_bw()
plot11
## ----error = F, message = F, warning = F--------------------------------------------------------
plot12 <- ggplot(df11, aes(x = date,
y = price_difference2)) +
geom_segment(aes(x = date,
xend = date,
y = 0,
yend = price_difference2,
color = price_difference2 > 0)) +
geom_point(color = "black", size = 2) +
geom_vline(xintercept = as.Date("2022-02-24"),
linetype = "dashed",
color = "black",
size = 0.45) +
theme_bw() +
scale_color_manual(values = c("red", "blue")) +
labs(title = "Belarus Tobacco Exports to Belarus: Price Differentials Over Time",
x = "Date",
y = "Price differential (standardized)") +
guides(color = FALSE)
plot12
```
### Kazakhstan
```{r, error = F, message = F, warning = F}
## ----error = F, message = F, warning = F--------------------------------------------------------
df11 <- df[df$destination_country == "Kazakhstan", ]
plot11 <- df11 %>%
ggplot( aes(x = date,
y = total_value)) +
geom_line()+
geom_point()+
geom_vline(xintercept = as.Date("2022-02-24"),
linetype = "dashed",
color = "black",
size = 0.45) +
facet_wrap(~destination_country, ncol = 2)+
labs(title = "Belarus Tobacco Exports: KAZ",
x = "Date",
y = "Total Value") +
theme_bw()
plot11
## ----error = F, message = F, warning = F--------------------------------------------------------
plot12 <- ggplot(df11, aes(x = date,
y = price_difference2)) +
geom_segment(aes(x = date,
xend = date,
y = 0,
yend = price_difference2,
color = price_difference2 > 0)) +
geom_point(color = "black", size = 2) +
geom_vline(xintercept = as.Date("2022-02-24"),
linetype = "dashed",
color = "black",
size = 0.45) +
theme_bw() +
scale_color_manual(values = c("red", "blue")) +
labs(title = "Belarus Tobacco Exports to KAZ: Price Differentials Over Time",
x = "Date",
y = "Price differential (standardized)") +
guides(color = FALSE)
plot12
```
### Russia
```{r, error = F, message = F, warning = F}
df11 <- df[df$destination_country == "Russia", ]
plot11 <- df11 %>%
ggplot( aes(x = date,
y = total_value)) +
geom_line()+
geom_point()+
geom_vline(xintercept = as.Date("2022-02-24"),
linetype = "dashed",
color = "black",
size = 0.45) +
facet_wrap(~destination_country, ncol = 2)+
labs(title = "Belarus Tobacco Exports",
x = "Date",
y = "Total Value") +
theme_bw()
plot11
## ----error = F, message = F, warning = F--------------------------------------------------------
plot12 <- ggplot(df11, aes(x = date,
y = price_difference2)) +
geom_segment(aes(x = date,
xend = date,
y = 0,
yend = price_difference2,
color = price_difference2 > 0)) +
geom_point(color = "black", size = 2) +
geom_vline(xintercept = as.Date("2022-02-24"),
linetype = "dashed",
color = "black",
size = 0.45) +
theme_bw() +
scale_color_manual(values = c("red", "blue")) +
labs(title = "Belarus Tobacco Exports to Russia: Price Differentials Over Time",
x = "Date",
y = "Price differential (standardized)") +
guides(color = FALSE)
plot12
```
### Ukraine
```{r, error = F, message = F, warning = F}
## ----error = F, message = F, warning = F--------------------------------------------------------
df11 <- df[df$destination_country == "Ukraine", ]
plot11 <- df11 %>%
ggplot( aes(x = date,
y = total_value)) +
geom_line()+
geom_point()+
geom_vline(xintercept = as.Date("2022-02-24"),
linetype = "dashed",
color = "black",
size = 0.45) +
facet_wrap(~destination_country, ncol = 2)+
labs(title = "Belarus Tobacco Exports: Ukraine",
x = "Date",
y = "Total Value") +
theme_bw()
plot11
## ----error = F, message = F, warning = F--------------------------------------------------------
plot12 <- ggplot(df11, aes(x = date,
y = price_difference2)) +
geom_segment(aes(x = date,
xend = date,
y = 0,
yend = price_difference2,
color = price_difference2 > 0)) +
geom_point(color = "black", size = 2) +
geom_vline(xintercept = as.Date("2022-02-24"),
linetype = "dashed",
color = "black",
size = 0.45) +
theme_bw() +
scale_color_manual(values = c("red", "blue")) +
labs(title = "Belarus Tobacco Exports to Ukraine: Price Differentials Over Time",
x = "Date",
y = "Price differential (standardized)") +
guides(color = FALSE)
plot12
```
## Belarus Tobacco Exports: Exporting Companies (Suppliers)
```{r, error = F, warning = F, message = F}
df$exporter <- df$supplier
df <- df[df$price_difference2 < 3, ]
df$exporter1 <- ifelse(str_detect(df$exporter, "INVEST") == T,
"LLC TABAK-INVEST",
ifelse(str_detect(df$exporter, "AURIUM") == T,
"AURIUM CORPORATION",
ifelse(str_detect(df$exporter, "ARIUM") == T,
"AURIUM CORPORATION", df$exporter)))
frequency_table <- df %>%
count(exporter1, name = "Frequency") %>%
arrange(desc(Frequency))
# Convert table to HTML and save it as a file
kable(frequency_table,
format = "html",
caption = "Belarus Tobacco Exports: Exporting Companies",
table.attr = "class='table table-striped'") %>%
kable_styling(full_width = FALSE)
## Extract first twenty companies:
l1 <- frequency_table[1:12, "exporter1"] %>% as.vector()
df500 <- df[df$exporter1 %in% l1$exporter, ]
plot03a <- df500 %>%
ggplot( aes(x = date,
y = total_value)) +
geom_line()+
geom_point()+
geom_vline(xintercept = as.Date("2022-02-24"),
linetype = "dashed",
color = "black",
size = 0.45) +
facet_wrap(~exporter1, ncol = 4)+
labs(title = "Belarus Tobacco Exports by Exporting Company (top 12)",
x = "Date",
y = "Total Value") +
theme_bw()
plot03a
plot06 <- ggplot(df500, aes(x = date,
y = price_difference2)) +
geom_segment(aes(x = date,
xend = date,
y = 0,
yend = price_difference2,
color = price_difference2 > 0)) +
geom_point(color = "black", size = 2) +
geom_vline(xintercept = as.Date("2022-02-24"),
linetype = "dashed",
color = "black",
size = 0.45) +
theme_bw() +
scale_color_manual(values = c("red", "blue")) +
labs(title = "Belarus Tobacco Exports by Exporting Company: Price Differentials Over Time",
subtitle = "(Top 12 companies)",
x = "Date",
y = "Price differential (standardized)") +
guides(color = FALSE) +
facet_wrap(~exporter1,
ncol = 4)
plot06
df500$filter <- ifelse(df500$exporter1 %in% c("LLC TABAK-INVEST",
"LLC TOBAKKO'S INTER"), 1, 0)
df600 <- df500[df500$filter == 1 , ]
plot07 <- ggplot(df600, aes(x = date,
y = price_difference2)) +
geom_segment(aes(x = date,
xend = date,
y = 0,
yend = price_difference2,
color = price_difference2 > 0)) +
geom_point(color = "black", size = 2) +
geom_vline(xintercept = as.Date("2022-02-24"),
linetype = "dashed",
color = "black",
size = 0.45) +
theme_bw() +
scale_color_manual(values = c("red", "blue")) +
labs(title = "Belarus Tobacco Exports by Exporting Company: Price Differentials Over Time",
subtitle = "(Top 2 companies)",
x = "Date",
y = "Price differential (standardized)") +
guides(color = FALSE) +
facet_wrap(~exporter1,
ncol = 1)
plot07
```