データの読み込み
library(readr)
country_cp <- read_csv("Data_output/country_cp.csv")
## Rows: 13616 Columns: 11
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): countrycode, country
## dbl (9): year, europe, eu, year_start_tax, year_end_tax, carbon_tax, year_st...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
FDIdata_long <- read_csv("Data_output/FDIdata_long.csv")
## Rows: 144786 Columns: 9
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (4): countryname, countryname_partner, countrycode, countrycode_partner
## dbl (5): imfn, imfn_partner, year, FDI, lnFDIstock
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
データの結合(1)
- FDIデータのcountrycodeとyearをキーにして、炭素税データを結合する。
# country_cpのyearとcountrycode、carbon_taxとets以外の変数を削除
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ purrr 1.0.2
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
country_cp <- country_cp %>% select(year, countrycode, carbon_tax, ets)
# yearとcountrycodeをキーにして結合。
FDIdata_merged <- merge(FDIdata_long, country_cp,
by.x = c("year", "countrycode"),
by.y = c("year", "countrycode"))
データの結合(2)
- FDIデータのcountrycode_partnerとyearをキーにして、炭素税データを結合する。
# yearとcountrycodeをキーにして結合。
FDIdata_merged <- merge(FDIdata_merged, country_cp,
by.x = c("year", "countrycode_partner"),
by.y = c("year", "countrycode"))
処置ダミー
# 投資受入国と投資元国の炭素税の有無によるダミー変数を作成する。
FDIdata_merged$carbon_tax_both <-
ifelse(FDIdata_merged$carbon_tax.x == 1
& FDIdata_merged$carbon_tax.y == 1, 1, 0)
# 投資受入国と投資元国の排出権取引制度(ets)の有無によるダミー変数を作成する。
FDIdata_merged$ets_both <-
ifelse(FDIdata_merged$ets.x == 1
& FDIdata_merged$ets.y == 1, 1, 0)
処置ダミーの確認
# 炭素税のダミー変数の年次頻度分布を確認
barplot(table(FDIdata_merged$carbon_tax_both, FDIdata_merged$year))

# ETSのダミー変数の年次頻度分布を確認
barplot(table(FDIdata_merged$ets_both, FDIdata_merged$year))

データの保存
write_csv(FDIdata_merged, "Data_output/FDIdata_merged.csv")