1 データ

# Load the dataset
library(rio)
cepii1 <- import("../Data_output/cepii1.rds")

names(cepii1)
##  [1] "pairid"               "year"                 "iso3_o"              
##  [4] "iso3_d"               "iso3num_o"            "iso3num_d"           
##  [7] "dist"                 "comlang_off"          "gdp_o"               
## [10] "gdp_d"                "gatt_o"               "gatt_d"              
## [13] "wto_o"                "wto_d"                "eu_o"                
## [16] "eu_d"                 "fta_wto"              "tradeflow_comtrade_o"
## [19] "tradeflow_comtrade_d" "tradeflow_baci"       "tradeflow_imf_o"     
## [22] "tradeflow_imf_d"

2 Stataへのエクスポート

## 必要変数の選択
cepii_stata <- cepii1[, c("iso3_o", "iso3_d", "year", "tradeflow_baci", "dist", "gdp_o", "gdp_d")]

## 2020年のデータのみを抽出
cepii_stata <- cepii_stata[cepii_stata$year == 2015, ]
## 日本からの輸出データのみを抽出
cepii_stata_jpn <- cepii_stata[cepii_stata$iso3_o == "JPN", ]
## countrycodeパッケージを使って国名追加
library(countrycode)
cepii_stata_jpn$country_d <- countrycode(cepii_stata_jpn$iso3_d, "iso3c", "country.name")

## countriesパッケージを使って日本語国名追加
library(countries)
cepii_stata_jpn$country_d_jpn <- country_name(x = cepii_stata_jpn$country_d, to="name_ja")

## EUダミー
cepii_stata_jpn$EU <- ifelse(cepii_stata_jpn$iso3_d %in% c("AUT", "BEL", "BGR", "HRV", "CYP", "CZE", "DNK", "EST", "FIN", "FRA", "DEU", "GRC", "HUN", "IRL", "ITA", "LVA", "LTU", "LUX", "MLT", "NLD", "POL", "PRT", "ROU", "SVK", "SVN", "ESP", "SWE"), 1, 0)


## 輸出先をEUに限定
cepii_stata_jpn <- cepii_stata_jpn[cepii_stata_jpn$EU == 1, ]

## tradeflow_baciが欠損の場合除去
#cepii_stata_jpn <- cepii_stata_jpn[!is.na(cepii_stata_jpn$tradeflow_baci), ]


## Stataへのエクスポート
library(rio)
rio::export(cepii_stata_jpn, "../Data_output/cepii_stata_jpn.dta")

3 日本からの輸出額のデータ

** 日本からの輸出額と距離の関係
use "../Data_output/cepii_stata_jpn.dta", clear


** 平均値で輸出額をdemeanした変数
egen tradeflow_baci_mean = mean(tradeflow_baci)
egen tradeflow_baci_sd = sd(tradeflow_baci)
gen tradeflow_baci_demean = (tradeflow_baci - tradeflow_baci_mean)/tradeflow_baci_sd

** 平均値で距離をdemeanした変数
egen dist_mean = mean(dist)
egen dist_sd = sd(dist)
gen dist_demean = (dist - dist_mean)/dist_sd


** 対数
gen ln_tradeflow_baci = log(tradeflow_baci)
gen ln_dist = log(dist)
gen ln_gdp_o = log(gdp_o)
gen ln_gdp_d = log(gdp_d)
(1 missing value generated)

4 日本からの輸出額と距離の関係

** 散布図と回帰直線
twoway  (scatter tradeflow_baci_demean dist_demean, ///
         mlabel(country_d_jpn) mlabsize(small) ) ///
        (lfit tradeflow_baci_demean dist_demean), ///
    title("日本からEU各国への輸出額") ///
    xtitle("日本からの距離") ytitle("輸出額") leg(off)

graph export "../Figures/dist_export.png", replace
file /Users/ayumu/Documents/GitHub/CEPII_Gravity/Scripts/../Figures/dist_export.png saved as PNG
    format
dist_export
dist_export

5 日本からの輸出額と距離の関係(対数)

** 散布図と回帰直線
twoway  (scatter ln_tradeflow_baci ln_dist, ///
         mlabel(country_d_jpn) mlabsize(small) ) ///
        (lfit ln_tradeflow_baci ln_dist), ///
    title("日本からEU各国への輸出額") ///
    xtitle("日本からの距離の対数値") ytitle("輸出額の対数値") leg(off)

graph save "../Figures/dist_export_log.gph", replace
graph export "../Figures/dist_export_log.png", replace
file ../Figures/dist_export_log.gph saved

file /Users/ayumu/Documents/GitHub/CEPII_Gravity/Scripts/../Figures/dist_export_log.png saved as PNG
    format
dist_export_log
dist_export_log

6 日本からの輸出額とGDPの関係(対数)



** 散布図と回帰直線
twoway  (scatter ln_tradeflow_baci ln_gdp_d,  mlabel(country_d_jpn) mlabsize(small)   xlabel(16(2)23) ) (lfit ln_tradeflow_baci ln_gdp_d), title("日本からEU各国への輸出額") xtitle("輸入国のGDPの対数値") ytitle("輸出額の対数値") leg(off)

graph save "../Figures/gdp_export_log.gph", replace
graph export "../Figures/gdp_export_log.png", replace
file ../Figures/gdp_export_log.gph saved

file /Users/ayumu/Documents/GitHub/CEPII_Gravity/Scripts/../Figures/gdp_export_log.png saved as PNG
    format
gdp_export_log
gdp_export_log

6.1 グラフの結合

graph combine  "../Figures/dist_export_log.gph" ///   
    "../Figures/gdp_export_log.gph", ///
    xsize(8) ysize(6) ///
    title("日本からEU各国への輸出額") 

graph export "../Figures/combine.png", replace
file /Users/ayumu/Documents/GitHub/CEPII_Gravity/Scripts/../Figures/combine.png saved as PNG format
combine
combine

参考文献