---
title: "ExportGenius Trade Analysis: Uzbekistan"
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
---
## **Tobacco exports**
```{r, error = F, message = F, warning = F}
rm(list = ls())
pacman::p_load(readxl, vtable, tidyverse,
lubridate, data.table, zoo,
readODS, patchwork, scales)
rm(list = ls())
df <- fread("/home/gagan/Desktop/soc_ace_2024/UZB-Detailed-Export-Tobacco.csv")
df$date <- dmy(df$Date)
df$date <- df$date
df$description <- df$`Product Description`
df$destination_country <- df$`Destination Country`
#table(df$destination_country)
df$destination_country <- ifelse(df$destination_country == "Europiean Union", "European Union",
ifelse(df$destination_country == "Unknwon", "Unknown",
ifelse(df$destination_country == "EUROPIEAN UNION", "European Union",
df$destination_country)))
df$supplier <- df$Exporter
df$importer <- df$Buyer
df$price_invoice <- df$`Total Value USD`/df$`Net Weight Kg`
df$total_value <- df$`Total Value USD`
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
#df[sapply(df, is.infinite)] <- NA
#df <- df[!(df$price_invoice > 1000),]
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 = "Uzbekistan 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 = "Uzbekistan 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 = "Uzbekistan Tobacco Exports by Destination",
x = "Date",
y = "Total Value") +
theme_bw()
plot03
max_price_index <- which.max(df$price_invoice)
# Remove the row with the highest value in the 'price' column
df <- df[-max_price_index, ]
df$filter01 <- ifelse(df$price_invoice > 150, 1, 0)
# table(df$filter01)
df <- df[df$price_invoice <=120, ]
df$price_difference <- df$price_invoice - df$price_benchmark
#df <- df[df$destination_country == "China", ]
df03 <- df[, c("date", "price_invoice", "price_benchmark")]
df_long <- reshape2::melt(df03,
id.vars = "date",
variable.name = "price_type",
value.name = "price")
df$price_difference <- df$price_invoice - df$price_benchmark
df$price_difference2 <- scale(df$price_difference)
df$price_benchmark2 <- scale(df$price_benchmark)
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) +
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 = "Uzbekistan Tobacco Exports: Price Differentials Over Time",
x = "Date",
y = "Price differential (standardized)") +
guides(color = FALSE)
plot04
```
## Uzbekistan Tobacco Exports: Notable Destination Countries
```{r, error = F, message = F, warning = F}
df11 <- df[df$destination_country %in% c("Armenia", "Belarus", "Georgia",
"Iraq", "Kazakhstan", "Kyrgyzstan", "Tajikistan", "Turkmenistan") ]
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 = "Uzbekistan Tobacco Exports",
x = "Date",
y = "Total Value") +
theme_bw()
plot11
```
```{r, 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 = "Uzbekistan Tobacco Exports: Price Differentials Over Time",
x = "Date",
y = "Price differential (standardized)") +
facet_wrap(~destination_country, ncol = 2)+
guides(color = FALSE)
plot12
```
## Uzbekistan - Armenia
```{r, error = F, message = F, warning = F}
df11 <- df[df$destination_country == "Armenia", ]
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 = "Uzbekistan Tobacco Exports: Armenia",
x = "Date",
y = "Total Value") +
theme_bw()
plot11
```
```{r, 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 = "Uzbekistan Tobacco Exports to Armenia: Price Differentials Over Time",
x = "Date",
y = "Price differential (standardized)") +
guides(color = FALSE)
plot12
```
## Uzbekistan - 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 = "Uzbekistan Tobacco Exports: Belarus",
x = "Date",
y = "Total Value") +
theme_bw()
plot11
```
```{r, 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 = "Uzbekistan Tobacco Exports to Belarus: Price Differentials Over Time",
x = "Date",
y = "Price differential (standardized)") +
guides(color = FALSE)
plot12
```
## Uzbekistan - Georgia
```{r, error = F, message = F, warning = F}
df11 <- df[df$destination_country == "Georgia", ]
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 = "Uzbekistan Tobacco Exports: Georgia",
x = "Date",
y = "Total Value") +
theme_bw()
plot11
```
```{r, 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 = "Uzbekistan Tobacco Exports to Georgia: Price Differentials Over Time",
x = "Date",
y = "Price differential (standardized)") +
guides(color = FALSE)
plot12
```
## Uzbekistan - Iraq
```{r, error = F, message = F, warning = F}
df11 <- df[df$destination_country == "Iraq", ]
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 = "Uzbekistan Tobacco Exports: Iraq",
x = "Date",
y = "Total Value") +
theme_bw()
plot11
```
```{r, 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 = "Uzbekistan Tobacco Exports to Iraq: Price Differentials Over Time",
x = "Date",
y = "Price differential (standardized)") +
guides(color = FALSE)
plot12
```
## Uzbekistan - Kazakhstan
```{r, 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 = "Uzbekistan Tobacco Exports: Kazakhstan",
x = "Date",
y = "Total Value") +
theme_bw()
plot11
```
```{r, 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 = "Uzbekistan Tobacco Exports to Kazakhstan: Price Differentials Over Time",
x = "Date",
y = "Price differential (standardized)") +
guides(color = FALSE)
plot12
```
## Uzbekistan - Kyrgyzstan
```{r, error = F, message = F, warning = F}
df11 <- df[df$destination_country == "Kyrgyzstan", ]
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 = "Uzbekistan Tobacco Exports: Kyrgyzstan",
x = "Date",
y = "Total Value") +
theme_bw()
plot11
```
```{r, 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 = "Uzbekistan Tobacco Exports to Kyrgyzstan: Price Differentials Over Time",
x = "Date",
y = "Price differential (standardized)") +
guides(color = FALSE)
plot12
```
## Uzbekistan - Tajikistan
```{r, error = F, message = F, warning = F}
df11 <- df[df$destination_country == "Tajikistan", ]
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 = "Uzbekistan Tobacco Exports: Tajikistan",
x = "Date",
y = "Total Value") +
theme_bw()
plot11
```
```{r, 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 = "Uzbekistan Tobacco Exports to Tajikistan: Price Differentials Over Time",
x = "Date",
y = "Price differential (standardized)") +
guides(color = FALSE)
plot12
```
## Uzbekistan - Turkmenistan
```{r, error = F, message = F, warning = F}
df11 <- df[df$destination_country == "Turkmenistan", ]
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 = "Uzbekistan Tobacco Exports: Turkmenistan",
x = "Date",
y = "Total Value") +
theme_bw()
plot11
```
```{r, 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 = "Uzbekistan Tobacco Exports to Turkmenistan: Price Differentials Over Time",
x = "Date",
y = "Price differential (standardized)") +
guides(color = FALSE)
plot12
```