Yu, Kuruppuarachchi, and Kumarasinghe (2024) は、炭素税と外国直接投資(FDI)の関係を時系列計量経済学の手法によって分析している。
この文書では、世界銀行の炭素税データのデータの読み込み、整形、および分析を行う。
Best, Burke, and Jotzo (2020) が用いてる世界銀行のデータを使用する。
rm(list = ls())
library(readxl)
cpdata <- read_excel("Data_raw/data-latest.xlsx", skip = 1)
# Rename "Jurisdiction covered" to "countryname"
names(cpdata)[names(cpdata) == "Jurisdiction covered"] <- "countryname"
# Rename "Unique ID" to "UniqueID"
names(cpdata)[names(cpdata) == "Unique ID"] <- "UniqueID"
# Rename "Instrument name" to "Instrument_name"
names(cpdata)[names(cpdata) == "Instrument name"] <- "Instrument_name"
cpdata = subset(cpdata, cpdata$UniqueID != "NA")
library(countrycode)
cpdata$iso3c <- countryname(cpdata$countryname, "iso3c")
# Keep rows only Status include letters "Implemented"
cpdata = subset(cpdata, grepl("Implemented", cpdata$Status))
# Drop rows where Type include letters "Subnational"
cpdata = subset(cpdata, !grepl("Subnational", cpdata$Type))
# Keep columns "iso3c", "UniqueID", "Instrument_name", "Type", "Status", "countryname"
cpdata = subset(cpdata, select = c(iso3c, UniqueID, Instrument_name, Type, Status, countryname))
# Split Status into "Implemented in" and numeric year
cpdata$year_start = as.numeric(gsub("Implemented in ", "", cpdata$Status))
# If Unique ID = "Tax_SL", then year = 1996
cpdata$year_start[cpdata$UniqueID == "Tax_SL"] = 1996
# If Unique ID = "ETS_AU1", then year = 2012
cpdata$year_start[cpdata$UniqueID == "ETS_AU1"] = 2012
# Set year_end = 2023 for all rows
cpdata$year_end = 2023
# Set year_end = 2022 for Unique ID = "Tax_SL"
cpdata$year_end[cpdata$UniqueID == "Tax_SL"] = 2022
# Set year_end = 2014 for Unique ID = "ETS_AU1"
cpdata$year_end[cpdata$UniqueID == "ETS_AU1"] = 2014
# cpdataをcsvファイルとして保存
write.csv(cpdata, "Data_output/cpdata.csv", row.names = FALSE)
# cpdataのTypeが"National carbon tax"のデータを抽出
cpdata_tax <- subset(cpdata, cpdata$Type == "National Carbon tax")
# iso3c、year_start、year_endの変数のみ残す
cpdata_tax <- cpdata_tax[, c("iso3c", "year_start", "year_end")]
# cpdataのTypeが"National ETS"のデータを抽出
cpdata_ets <- subset(cpdata, cpdata$Type == "National ETS")
# iso3c、year_start、year_endの変数のみ残す
cpdata_ets <- cpdata_ets[, c("iso3c", "year_start", "year_end")]
# country listの読み込み
library(haven)
country_eu <- read_dta("Data_raw/country_eu.dta")
# country_euのcountrycodeとcpdata_taxのiso3cをkeyとして接続
country_eu <- merge(country_eu, cpdata_tax, by.x = "countrycode", by.y = "iso3c", all.x = TRUE)
# if year>=year_statr and year<=year_end then carbon_tax=1 else 0
country_eu$carbon_tax <- ifelse(country_eu$year >= country_eu$year_start & country_eu$year <= country_eu$year_end, 1, 0)
# if year_start is missing, then carbon_tax=0
country_eu$carbon_tax[is.na(country_eu$year_start)] <- 0
# rename year_start to year_start_tax and year_end to year_end_tax
names(country_eu)[names(country_eu) == "year_start"] <- "year_start_tax"
names(country_eu)[names(country_eu) == "year_end"] <- "year_end_tax"
# country_euのcountrycodeとcpdata_etsのiso3cを接続
country_eu <- merge(country_eu, cpdata_ets, by.x = "countrycode", by.y = "iso3c", all.x = TRUE)
# if year>=year_statr and year<=year_end then ets=1 else 0
country_eu$ets <- ifelse(country_eu$year >= country_eu$year_start & country_eu$year <= country_eu$year_end, 1, 0)
# if year_start is missing, then ets=0
country_eu$ets[is.na(country_eu$year_start)] <- 0
# rename year_start to year_start_ets and year_end to year_end_ets
names(country_eu)[names(country_eu) == "year_start"] <- "year_start_ets"
names(country_eu)[names(country_eu) == "year_end"] <- "year_end_ets"
# EU加盟国の場合、2005年以降ets=1とする
country_eu$ets[country_eu$eu == 1 & country_eu$year >= 2005] <- 1
# EU加盟国の場合、year_start_ets>2005の場合、year_start_ets=2005とする
country_eu$year_start_ets[country_eu$eu == 1 & country_eu$year_start_ets > 2005] <- 2005
# EU加盟国の場合、year_start_ets==NAの場合、year_start_ets=2005とする
country_eu$year_start_ets[country_eu$eu == 1 & is.na(country_eu$year_start_ets)] <- 2005
# EU加盟国の場合、year_end_ets==NAの場合、year_end_ets=2023とする
country_eu$year_end_ets[country_eu$eu == 1 & is.na(country_eu$year_end_ets)] <- 2023
# country_euをcsvファイルとして保存
write.csv(country_eu, "Data_output/country_cp.csv", row.names = FALSE)