######## HAKELBERG, AHRENS, AND CRASNIC, THE GREAT CARIBBEAN DIVERGENCE ########

## Code for reproducing the analyses in the main paper and online supplementary
## material of:
## Hakelberg, Lukas, Leo Ahrens, and Loriana Crasnic, The Great Caribbean
## Divergence: Colonial Economic Structure and the Emergence of Tax Havens in
## the 'British West Indies', Review of International Political Economy

## 19 October 2025
## By Lukas Hakelberg

# I load the R packages I need for the analyses below.
library(tidyverse)
library(caseMatch)
library(readxl)
library(countrycode)
library(ggrepel)
library(ggthemes)
library(patchwork)
library(knitr)

# I load the data set accompanying this R script.
wowma_master <- read_csv("wowma_dataset_V0_2.csv")

############# BELOW IS THE CODE FOR FIGURE 1 IN THE MAIN PAPER #################

F1 <- wowma_master |>
  # I filter for the years 2011-2024 for which data is available from both the
  # BIS Locational Banking Statistics and the US Treasury's International 
  # capital system. I filter for the countries that were part of the British 
  # West Indies.
  filter(year %in% c(2011:2024), iso3 %in% c("AIA", "ATG", "BHS", "BMU", "BRB", 
                                             "BLZ", "VGB", "CYM", "GUY", "GRD", 
                                             "DMA", "VCT", "MSR", "TTO", "LCA", 
                                             "TCA", "JAM", "KNA")) |>
  # I normalize the data by GDP so that they reflect to what extent financial
  # positions are out of proportion with the size of the domestic economy.
  mutate(bis_total = bis_liabilities + bis_claims) |>
  mutate(bis_total_gdp = bis_total / gdp_millions) |>
  mutate(tic_total_gdp = tic_total / gdp_millions) |>
  # I calculate the 2011-2024 averages of the normalized data.
  group_by(iso3, maritime) |>
  summarise(position_avg = mean(bis_total_gdp, na.rm = TRUE), 
            tic_avg = mean(tic_total_gdp, na.rm = TRUE)) |>
  # I create a string variable from the dummy variable identifying maritime and
  # plantation economies to enable color coding in the subsequent step.
  mutate(Economy = if_else(maritime == 0, "plantation", "maritime")) |>
  # I calculate the logarithm of the variables to compress the skewed
  # distribution and fit all cases into one graph.
  mutate(log_position = log(position_avg), log_tic = log(tic_avg))

# I plot the data by type of economy to illustrate the difference between the 
# two groups. I increase the default font size for better readability of the 
# labels.
ggplot(data = F1, mapping = aes(x = log_position, y = log_tic)) + 
  geom_text(mapping = aes(label = iso3, color = Economy), 
            size = 14 / ggplot2::.pt) +
  labs(x = "Log Cross Border Position / GDP", 
       y = "Log Holdings of US Securities / GDP", 
       color = "Economy") + 
  theme_bw(base_size = 14) & theme(legend.position = "right") & 
  scale_color_colorblind()

# I save the figure with dimensions that fit an A4 paper. 
ggsave("cardiv_F1.pdf", width = 20, height = 12, units = c("cm"))


##### BELOW IS THE CODE FOR THE STATISTICAL MATCHING PROCEDURE (TABLE 1) #######

bwi_match <- wowma_master |>
  # I select the variables I need for the statistical matching procedure.
  select(iso3, year, maritime, population_unctad, ny_changes, lon_changes, 
         int_calls, ny_distance, serv_exp) |>
  # I calculate per capita services exports.
  mutate(pc_services = serv_exp / population_unctad) |>
  # I filter for the year 1956, the year of the Suez crisis, which created 
  # additional demand for tax havens. I filter for the countries belonging to
  # the BWI group, excluding Belize and Guyana, which are not islands.
  filter(year == 1956, iso3 %in% c("ATG", "BHS", "BMU", "BRB", "VGB", "CYM", 
                                   "GRD", "DMA", "VCT", "MSR", "TTO", "LCA", 
                                   "TCA", "JAM", "KNA")) 

# I define the covariates to be included in the matching procedure.
mvars <- c("population_unctad", "ny_distance", "ny_changes", "lon_changes", 
           "int_calls", "pc_services")
# I define the variables to be excluded from the matching procedure.
dropvars <- c("iso3", "year", "maritime", "serv_exp")

# I define the parameters and run the matching procedure. I choose Mahalanobis 
# matching because it's Nielsen's (2016) preferred matching method as it 
# standardizes variables with different scales and takes correlations between 
# them into account. I maximize the variance on treatment variable "maritime" 
# to ensure that maritime economies are matched to plantation economies.
bwi_results <- case.match(data = bwi_match, id.var = "iso3", case.N = 2, 
                          design.type =  "most similar", 
                          distance = "mahalanobis", 
                          number.of.matches.to.return = 5, 
                          treatment.var = "maritime", leaveout.vars = dropvars, 
                          max.variance = TRUE)$cases

# I build a table for the paper that includes the matching distances for all 
# pairs and the values of the matching covariates for all countries.
T1 <- bwi_results |>
  select(distances, `unit id 1`, `unit id 2`) |>
  left_join(bwi_match |>
              select(iso3, all_of(mvars)) |>
              rename_with(~ paste0("unit id 1", .x), -iso3),
            by = c("unit id 1" = "iso3")) |>
  left_join(bwi_match |>
              select(iso3, all_of(mvars)) |>
              rename_with(~ paste0("unit id 2", .x), -iso3), 
            by = c("unit id 2" = "iso3")) |>
  arrange(distances) |>
  mutate(rank = row_number()) |>
  select(rank, `unit id 1`, `unit id 2`, distances, everything())

# I repeat the procedure above, using Standardized instead of Mahalanobis 
# matching.
bwi_results_std <- case.match(data = bwi_match, id.var = "iso3", case.N = 2, 
                          design.type =  "most similar", 
                          distance = "mahalanobis", 
                          number.of.matches.to.return = 5, 
                          treatment.var = "maritime", leaveout.vars = dropvars, 
                          max.variance = TRUE)$cases
# I produce a table containing the information displayed in Table B1 in the 
# online appendix.
B1 <- bwi_results_std |>
  select(distances, `unit id 1`, `unit id 2`) |>
  left_join(bwi_match |>
              select(iso3, all_of(mvars)) |>
              rename_with(~ paste0("unit id 1", .x), -iso3), 
            by = c("unit id 1" = "iso3")) |>
  left_join(bwi_match |>
              select(iso3, all_of(mvars)) |>
              rename_with(~ paste0("unit id 2", .x), -iso3), 
            by = c("unit id 2" = "iso3")) |>
  arrange(distances) |>
  mutate(rank = row_number()) |>
  select(rank, `unit id 1`, `unit id 2`, distances, everything())


######## BELOW IS THE CODE FOR FIGURE D1 IN THE SUPPLEMENTARY MATERIAL #########

bwikm2 <- wowma_master |>
  # I select the variables I need to produce a line graph showing the evolution
  # of merchandise exports per km2 in maritime and plantation economies.
  # I filter for years between 1900 and 1938 to reflect the economic situation
  # before the Second World War. I filter for countries belonging the the BWI
  # group, excluding Belize and Guyana, which are not islands. 
  select(iso3, year, maritime, km2, export_pound_current) |>
  filter(year %in% c(1900:1938), iso3 %in% c("AIA", "ATG", "BHS", "BRB", "BMU",
                                             "VGB","CYM", "DMA", "GRD", "MSR", 
                                             "KNA", "LCA", "VCT", "TCA", "TTO", 
                                             "JAM")) |>
  # I normalize export data by km2 to proxy the agricultural productivity of the
  # land. 
  mutate(export_km = export_pound_current / km2)

bwikm2avg <- bwikm2 |>
  # I calculate the group averages for maritime and plantation economies.
  group_by(iso3, year, maritime) |>
  summarise(export_km_avg = mean(export_km, na.rm = TRUE)) |>
  group_by(year, maritime) |>
  summarise(export_km_econ_avg = mean(export_km_avg, na.rm = TRUE)) |>
  # I create a string variable from the maritime dummy to facilitate color
  # coding in the subsequent step.
  mutate(Economy = if_else(maritime == 0, "plantation", "maritime"))

# I plot the data.
ggplot(data = bwikm2avg, mapping = aes(x = year, y = export_km_econ_avg))+
  geom_line(mapping = aes(color = Economy), alpha = 0.75, lineend = "round", 
            linewidth = 1.2, show.legend = TRUE) + 
  labs(x = "Year", y = "Exports in Current Pound Sterling per km2", 
       color = "Economy") + 
  theme_bw() + scale_color_colorblind() & theme(legend.position = "bottom")

# I save the line graph with dimensions that fit an A4 paper.  
ggsave("cardiv_C1.pdf", width = 20, height = 12, units = c("cm"))

######## BELOW IS THE CODE FOR FIGURE D2 IN THE SUPPLEMENTARY MATERIAL #########

D2datA <- wowma_master |>
  # I select the variables I need to produce a line graph showing the evolution 
  # of the budgetary balance. I filter for the years 1900 to 1950 to cover the
  # time period during which most BWI colonies adopted the income tax.
  filter(iso3 %in% c("CYM", "KNA"), year %in% c(1900:1950)) |>
  select(iso3, country, year, deficit_perc)

D2datB <- wowma_master |>
  # I select the variables I need to produce a line graph showing the evolution
  # of total exports. I filter for the years 1900 to 1940 to cover the time
  # period during which most BWI colonies adopted the income tax. I end the 
  # observation period in 1940 because the time series for total exports from 
  # the RICardo database end in 1938, but I still want a label for 1940 on the 
  # x axis for better orientation.
  filter(iso3 %in% c("CYM", "KNA"), year %in% c(1900:1940)) |>
  select(iso3, country, year, export_pound_current) |>
  # I calculate the log of total exports to compress the distribution of the
  # values and make them fit better into one graph.
  mutate(log_exp = log(export_pound_current))

# I specify that the line graph showing the budgetary balance is Panel A in
# Figure D2 and plot the data.
D2A <- ggplot(data = D2datA, mapping = aes(x = year, y = deficit_perc))+
  geom_line(mapping = aes(color = country), alpha = 0.75, lineend = "round", 
            linewidth = 1.2, show.legend = FALSE) + 
  # I add an intercept for the year in which St. Kitts & Nevis adopted the
  # income tax.
  geom_vline(aes(xintercept = 1922), linetype="dashed", 
             color = "gray", size=0.75) +
  labs(x = "Year", y = "Budgetary Balance as a Percentage of Revenue", 
       title = "A") + theme_bw() + scale_color_colorblind()

# I specify that the line graph showing total exports is Panel B in Figure D2
# and plot the data.
D2B <- ggplot(data = D2datB, mapping = aes(x = year, y = log_exp))+
  geom_line(mapping = aes(color = country), alpha = 0.75, 
            lineend = "round", linewidth = 1.2) + 
  # I add an intercept for the year in which St. Kitts & Nevis adopted the
  # income tax.
  geom_vline(aes(xintercept = 1922), linetype="dashed", 
             color = "gray", size=0.75)+
  labs(x = "Year", y = "Log of Total Exports", color = "Country", title = "B") + 
  theme_bw() + scale_color_colorblind()

# I combine the two panels into a single digure and collect labels from the 
# underlying panels.
D2A + D2B + plot_layout(axis_titles = "collect_x", guides = "collect") & 
  theme(legend.position = "bottom")

# I save the figure with dimensions that fit an A4 paper.
ggsave("figure_D2.pdf", width = 20, height = 12, units = c("cm"))


############### BELOW IS THE CODE FOR FIGURE 3 IN THE MAIN PAPER ###############

bwitax <- wowma_master |>
  # I select the variables I need to produce a line graph plotting income tax
  # adoptions in maritime and plantation economies over time. 
  select(iso3, year, maritime, pit) |>
  # I filter for years between 1860 and 1950 to cover the time period during 
  # which income taxes were adopted in the BWI. I filter for countries belonging
  # to the BWI group.
  filter(year %in% c(1860:1950), iso3 %in% c("ATG", "BHS", "BRB", "BMU","BLZ",
                                             "VGB","CYM", "DMA", "GRD", "MSR", 
                                             "NEV", "KIT", "KNA", "LCA", "VCT", 
                                             "TCA", "TOB", "TRI", "TTO" , "GUY", 
                                             "JAM")) |>
  # I calculate the share of adoptions by economic structure and year. 
  group_by(year, maritime) |>
  summarise(pit_avg = mean(pit, na.rm = TRUE)) |>
  # I create a string variable from the maritime dummy to facilitate the coding
  # of line types in the subsequent step.
  mutate(Economy = if_else(maritime == 0, "plantation", "maritime"))

bwidemo <- wowma_master |>
  # I select the variables I need to produce a line graph plotting adoptions of
  # responsible government in maritime and plantation economies.
  select(iso3, year, maritime, rep_gov) |>
  # I filter for years between 1950 and 1970 to cover the time period during
  # which responsible government was adopted in the BWI. I filter for countries
  # belonging to the BWI group.
  filter(year %in% c(1950:1970), iso3 %in% c("ATG", "BHS", "BRB", "BMU","BLZ",
                                             "VGB","CYM", "DMA", "GRD", "MSR", 
                                             "KNA", "LCA", "VCT", "TCA", "TTO", 
                                             "GUY", "JAM")) |>
  # I calculate the share of adoptions by economic structure and year.
  group_by(year, maritime) |>
  summarise(rep_avg = mean(rep_gov, na.rm = TRUE)) |>
  # I create a string variable from the maritime dummy to facilitate the coding
  # of line types in the subsequent step.
  mutate(Economy = if_else(maritime == 0, "plantation", "maritime"))

# I specify that the line graph showing income tax adoptions by economic
# structure and year is Panel A in Figure 3 and plot the data.
F3PA <- ggplot(data = bwitax, mapping = aes(x = year, y = pit_avg))+
  geom_step(mapping = aes(linetype = Economy), alpha = 0.75, lineend = "round",
            linewidth = 1.2, show.legend = FALSE) + 
  labs(x = "Year", y = "Share of Adopting Countries", title = "A: Income Tax") + 
  theme_bw(base_size = 14) + scale_color_colorblind()

# I specify that the line graph showing adoptions of responsible government by
# economic structure and year is Panel B in Figure 3 and plot the data.
F3PB <- ggplot(data = bwidemo, mapping = aes(x = year, y = rep_avg))+
  geom_step(mapping = aes(linetype = Economy), alpha = 0.75, lineend = "round", 
            linewidth = 1.2) +
  labs(x = "Year", y = "Share of Adopting Countries", 
       title = "B: Responsible Goverment") + 
  theme_bw(base_size = 14) + scale_color_colorblind()

# I combine the two line graphs into one graph with two panels. 
F3PA + F3PB + plot_layout(axis_titles = "collect_x", guides = "collect") & 
  theme(legend.position = "bottom")

# I save the graph with dimensions that fit an A4 paper.
ggsave ("cardiv_F3.pdf", width = 20, height = 10, units = c("cm"))
  

############# BELOW IS THE CODE FOR FIGURE 4 IN THE MAIN PAPER #################

bwibanks <- wowma_master |>
  # I select the variables I need to produce a line graph plotting the number of
  # banks by economic structure and year. 
  select(iso3, year, maritime, banks_no) |>
  # I filter for the decisive years before and after the Suez Crisis. I end the 
  # time series in 1965 because too many plantation economies become independent
  # thereafter, ending the time series on bank branches in British colonial
  # reports, which creates an unbalanced sample of maritime and plantation
  # economies for which data is available on the banks_no variable after 1965.
  # I filter for the countries belonging to the BWI group.
  filter(year %in% c(1950:1965),iso3 %in% c("ATG", "BHS", "BRB", "BMU","BLZ",
                                            "VGB","CYM", "DMA", "GRD", "MSR", 
                                            "KNA", "LCA", "VCT", "TCA", "TTO", 
                                            "GUY", "JAM")) |>
  # I calculate the group averages by economic structure and year.
  group_by(year, maritime) |>
  summarise(banks_avg = mean(banks_no, na.rm = TRUE)) |>
  # I create a string variable from the maritime dummy to facilitate the coding
  # of line types in the subsequent step.
  mutate(Economy = if_else(maritime == 0, "plantation", "maritime"))

bwihthd <- wowma_master |>
  # I select the variables I need to produce a line graph showing adoptions of 
  # tax haven legislation by economic structure and year.
  select(iso3, year, maritime, hthd_total) |>
  # I filter for the decisive years around the Suez crisis of 1956. I filter for
  # the countries belonging to the BWI group.
  filter(year %in% c(1950:1970), 
         iso3 %in% c("ATG", "BHS", "BRB", "BMU","BLZ","VGB","CYM", "DMA", "GRD", 
                     "MSR", "KNA", "LCA", "VCT", "TCA", "TTO" , "GUY", "JAM"))|>
  # I calculate the group averages by economic structure and year.
  group_by(year, maritime) |>
  summarise(hthd_avg = mean(hthd_total, na.rm = TRUE)) |>
  # I create a string variable from the maritime dummy to facilitate the coding
  # of line types in the subsequent step.
  mutate(Economy = if_else(maritime == 0, "plantation", "maritime"))

cymkna <- wowma_master |>
  # I select the variables I need to produce line graphs comparing the number of
  # bank branches and tax haven legislation in the Cayman Islands and St. Kitts
  # & Nevis
  select(iso3, year, banks_no, hthd_total) |>
  # I filter for the Cayman Islands and St. Kitts & Nevis, the two country cases 
  # in the main paper. I filter for the decisive years around the Suez crisis of
  # 1956.
  filter(iso3 %in% c("CYM", "KNA"), year %in% c(1950:1970))

# I specify that the line graph comparing the number of bank branches in the 
# Cayman Islands and St. Kitts & Nevis is Panel A in Figure 4 and plot the
# data.
F4PA <- ggplot(data = cymkna, mapping = aes(x = year, y = banks_no))+
  geom_step(mapping = aes(linetype = iso3), alpha = 0.75, lineend = "round", 
            linewidth = 1.2, show.legend = FALSE) +
  geom_vline(aes(xintercept = 1956), linetype="dashed", color = "gray", 
             size=0.75) +
  labs(x = "Year", y = "No. of Commercial Banks", 
       title = "A: Banks in CYM & KNA") + theme_bw(base_size = 14)

# I specify that the line graph displaying the number of tax haven legislation
# in the Cayman Islands and St. Kitts & Nevis is Panel B in Figure 4 and plot
# the data.
F4PB <- ggplot(data = cymkna, mapping = aes(x = year, y = hthd_total))+
  geom_step(mapping = aes(linetype = iso3), alpha = 0.75, lineend = "round", 
            linewidth = 1.2) +
  geom_vline(aes(xintercept = 1956), linetype="dashed", color = "gray", 
             size=0.75)+
  labs(x = "Year", y = "Pcs. of Tax Haven Legislation", 
       linetype = "Country", title = "B: Legislation in CYM & KNA") + 
  theme_bw(base_size = 14)

# I specify that the line graph displaying the average number of bank branches 
# in maritime and plantation economies is Panel C in Figure 4 and plot the
# data.
F4PC <- ggplot(data = bwibanks, mapping = aes(x = year, y = banks_avg))+
  geom_step(mapping = aes(linetype = Economy), alpha = 0.75, lineend = "round", 
            linewidth = 1.2, show.legend = FALSE) +
  geom_vline(aes(xintercept = 1956), linetype="dashed", color = "gray", 
             size=0.75) +
  labs(x = "Year", y = "No. of Commercial Banks", 
       title = "C: Banks in the BWI") + theme_bw(base_size = 14)

# I specify that the line graph displaying the average number of tax haven 
# legislation in maritime and plantation economies is Panel D in Figure 4 and
# plot the data.
F4PD <- ggplot(data = bwihthd, mapping = aes(x = year, y = hthd_avg))+
  geom_step(mapping = aes(linetype = Economy), alpha = 0.75, lineend = "round", 
            linewidth = 1.2) +
  geom_vline(aes(xintercept = 1956), linetype="dashed", color = "gray", 
             size=0.75) +
  labs(x = "Year", y = "Pcs. of Tax Haven Legislation", 
       linetype = "Economy", title = "D: Legislation in the BWI") + 
  theme_bw(base_size = 14)

# I arrange the four panels of Figure 2 into two rows and collect the legend
# and guides from the underlying graphs.
row1 <- (F4PA + F4PB) + 
  plot_layout(axis_titles = "collect_x", 
              guides = "collect") & theme(legend.position = "bottom")

row2 <- (F4PC + F4PD) + 
  plot_layout(axis_titles = "collect_x", 
              guides = "collect") & theme(legend.position = "bottom")

final_plot <- (row1 / row2) + plot_layout(guides = "keep", 
                                          axis_titles = "collect")

final_plot

# I save the graph with dimensions that fit an A4 paper. 
ggsave("cardiv_F4.pdf", width = 20, height = 20, units = c("cm"))


######## BELOW IS THE CODE FOR FIGURE E1 IN THE SUPPLEMENTARY MATERIAL #########

E1 <- wowma_master |>
  # I filter for years between 2011 and 2024 for which data is available for 
  # most of the world's tropical island jurisdictions. I exclude Belize and 
  # Guyana, which were part of the BWI but are not islands.
  filter(year %in% c(2011:2024), !iso3 %in% c("BLZ", "GUY")) |>
  # I create the variables I need to compare the cross border financial
  # positions by GDP of the world's tropical island jurisdictions. 
  mutate(bis_total = bis_liabilities + bis_claims) |>
  mutate(bis_total_gdp = bis_total / gdp_millions) |>
  mutate(tic_total_gdp = tic_total / gdp_millions) |>
  # I group by country and economic structure to obtain average values across
  # the time period defined above and prepare the illustration of differences 
  # between maritime and plantation economies.
  group_by(iso3, maritime) |>
  summarise(position_avg = mean(bis_total_gdp, na.rm = TRUE), 
            tic_avg = mean(tic_total_gdp, na.rm = TRUE)) |>
  # I create a string variable from the maritime dummy to facilitate color
  # coding in the subsequent step.
  mutate(Economy = if_else(maritime == 0, "plantation", "maritime")) |>
  # I calculate the logarithm of average cross border financial positions to 
  # compress the skewed distribution of the underlying values. 
  mutate(log_position = log(position_avg), log_tic = log(tic_avg))

# I specify that the graph displaying cross-border financial positions by GDP 
# is Panel A in Figure E1 and plot the data.
E1A <- ggplot(data = E1, mapping = aes(x = log_position, y = log_tic)) + 
  geom_text(mapping = aes(label = iso3, color = Economy), 
            size = 3.3) +
  labs(x = "Log Cross Border Position / GDP", 
       y = "Log Holdings of US Securities / GDP", 
       title = "A: Financial Positions / GDP", color = "Economy") + 
  theme_bw() & scale_color_colorblind()

# I recreate the dataframe E1 but this time don't divide financial positions by 
# GDP.
E1alt <- wowma_master |>
  filter(year %in% c(2011:2024), !iso3 %in% c("BLZ", "GUY")) |>
  mutate(bis_total = bis_liabilities + bis_claims) |>
  group_by(iso3, maritime) |>
  summarise(position_avg = mean(bis_total, na.rm = TRUE), 
            tic_avg = mean(tic_total, na.rm = TRUE)) |>
  mutate(Economy = if_else(maritime == 0, "plantation", "maritime")) |>
  mutate(log_position = log(position_avg), log_tic = log(tic_avg))

# I specify that the graph displaying the absolute values of cross-border
# financial positions is Panel B in Figure E1 and plot the data.
E1B <- ggplot(data = E1alt, mapping = aes(x = log_position, y = log_tic)) + 
  geom_text(mapping = aes(label = iso3, color = Economy), size = 3.3) +
  labs(x = "Log Cross Border Position", 
       y = "Log Holdings of US Securities", 
       title = "B: Financial Positions, Absolute Values",  
       color = "Economy") + theme_bw() + coord_cartesian(xlim = c(4, 16)) + 
  scale_x_continuous(expand = c(0,0)) & scale_color_colorblind()

# I arrange the two panels below each other in the final graph and collect the
# labels from the underlying panels. 
(E1A / E1B) + plot_layout(guides = "collect") & 
  theme(legend.position = "right")

# I save the figure with dimensions that fit an A4 paper. 
ggsave("cardiv_E1.pdf", width = 20, height = 24, units = c("cm"))


######## BELOW IS THE CODE FOR FIGURE C1 IN THE SUPPLEMENTARY MATERIAL #########

aiakna <- wowma_master |>
  # I select the variables I need to produce line graphs displaying the value of
  # US securities holdings in Anguilla and St. Kitts & Nevis.
  select(iso3, year, gdp_millions, tic_total) |>
  # I divide the value of holdings by GDP.
  mutate(tic_gdp = tic_total / gdp_millions) |>
  # I filter for years between 2011 and 2024, the time period for which data is 
  # available. I filter for Anguilla and St. Kitts & Nevis. 
  filter(year %in% c(2011:2024), iso3 %in% c("AIA", "KNA"))

# I specify that the line graph displaying absolute values is Panel A in Figure 
# C1 and plot the data.
aiakna1 <- ggplot(data = aiakna, mapping = aes(x = year, y = tic_total))+
  geom_line(mapping = aes(color = iso3), alpha = 0.75, lineend = "round",
            linewidth = 1.2, show.legend = FALSE) +
  # I add an intercept in 2017, the year Hurricane Irma hit Anguilla.
  geom_vline(aes(xintercept = 2017), linetype="dashed", color = "gray", 
             size=0.75) +
  annotate("text", x = 2017, y = max(aiakna$tic_total, na.rm = TRUE)*0.95, 
           label = "Hurricane Irma", 
           color = "gray", vjust = -0.9, hjust = -0.08, size = 4) +
  labs(x = "Year", y = "Value in Current US$, Millions", color = "Country", 
       title = "A: Total Values") + 
  theme_bw() + scale_color_colorblind()

# I specify that the line graph displaying values by GDP is Panel B in Figure 
# C1 and plot the data.
aiakna2 <- ggplot(data = aiakna, mapping = aes(x = year, y = tic_gdp))+
  geom_line(mapping = aes(color = iso3), alpha = 0.75, lineend = "round", 
            linewidth = 1.2) +
  geom_vline(aes(xintercept = 2017), linetype="dashed", color = "gray", 
             size=0.75) + 
  annotate("text", x = 2017, y = max(aiakna$tic_gdp, na.rm = TRUE)*0.95, 
           label = "Hurricane Irma", 
           color = "gray", vjust = -0.9, hjust = -0.08, size = 4) +
  labs(x = "Year", y = "Total Value by GDP", color = "Country", 
       title = "B: Total Values by GDP") + 
  theme_bw() + scale_color_colorblind()

# I arrange the two panels into one graph and collect labels from the underlying
# panels
aiakna1 + aiakna2 + plot_layout(axis_titles = "collect_x", guides = "collect") & 
  theme(legend.position = "bottom")

# I save the figure with dimensions that fit an A4 paper.
ggsave("cardiv_C1.pdf", width = 20, height = 12, units = c("cm"))


#### CODE FOR VERSION OF F1 THAT DOES NOT DIVIDE FINANCIAL POSITIONS BY GDP ####

F1alt <- wowma_master |>
  filter(year %in% c(2011:2024), iso3 %in% c("AIA", "ATG", "BHS", "BMU", "BRB", 
                                             "BLZ", "VGB", "CYM", "GUY", "GRD", 
                                             "DMA", "VCT", "MSR", "TTO", "LCA", 
                                             "TCA", "JAM", "KNA")) |>
  mutate(bis_total = bis_liabilities + bis_claims) |>
  mutate(bis_total_gdp = bis_total) |>
  mutate(tic_total_gdp = tic_total) |>
  group_by(iso3, maritime) |>
  summarise(position_avg = mean(bis_total_gdp, na.rm = TRUE), 
            tic_avg = mean(tic_total_gdp, na.rm = TRUE)) |>
  mutate(Economy = if_else(maritime == 0, "plantation", "maritime")) |>
  mutate(log_position = log(position_avg), log_tic = log(tic_avg))

ggplot(data = F1alt, mapping = aes(x = log_position, y = log_tic)) + 
  geom_text(mapping = aes(label = iso3, color = Economy), size = 3.3) +
  labs(x = "Log Cross Border Position", 
       y = "Log Holdings of US Securities", 
       color = "Economy") + 
  theme_bw() & theme(legend.position = "bottom") & scale_color_colorblind()

## END