• R/O
  • SSH

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javaandroidc++linuxc#objective-ccocoa誰得qtrubypythongamewindowsbathyscaphephpguic翻訳omegattwitterframeworktestbtronarduinovb.net計画中(planning stage)directxpreviewerゲームエンジンdom

Commit MetaInfo

Revisãodafb5bcfb469b4217eac9736c06b60f915eb1932 (tree)
Hora2020-07-01 08:26:00
AutorLorenzo Isella <lorenzo.isella@gmai...>
CommiterLorenzo Isella

Mensagem de Log

Various modifications and I added the FTA table.

Mudança Sumário

Diff

diff -r 6a7ca62a7797 -r dafb5bcfb469 R-codes/pocket_guide.R
--- a/R-codes/pocket_guide.R Tue Jun 30 23:09:25 2020 +0200
+++ b/R-codes/pocket_guide.R Wed Jul 01 01:26:00 2020 +0200
@@ -1660,7 +1660,8 @@
16601660 mutate(cum_share=paste(cum_share, "%", sep="")) %>%
16611661 mutate(cum_share=if_else(country=="Extra EU27", "-", cum_share)) %>%
16621662 mutate(rank=if_else(rank=="0", "", rank)) %>%
1663- format_all(1)
1663+ format_all(1) %>%
1664+ select(country, everything())
16641665
16651666
16661667
@@ -1700,7 +1701,8 @@
17001701 mutate(cum_share=paste(cum_share, "%", sep="")) %>%
17011702 mutate(cum_share=if_else(country=="Extra EU27", "-", cum_share)) %>%
17021703 mutate(rank=if_else(rank=="0", "", rank)) %>%
1703- format_all(1)
1704+ format_all(1) %>%
1705+ select(country, everything())
17041706
17051707
17061708
@@ -3095,6 +3097,315 @@
30953097 ## #########################################################################à
30963098
30973099
3100+fta_ini <- read_csv("input_data_files/FTAs.csv")
3101+
3102+fta <- fta_ini %>%
3103+ clean_names()%>%
3104+ mutate(cat_3= recode(cat_3,"Andean community"="Andean Community" ))
3105+
3106+
3107+fta_implemented <- fta %>%
3108+ filter(cat_1=="FTAs implemented") %>%
3109+ select(country_label, iso_code)
3110+
3111+
3112+eu27_trade <- df_eu27_trade_ini %>%
3113+ select(partnerlabel, year, e_value, i_value) %>%
3114+ mutate(year=as.integer(year), e_value=e_value/1e6, i_value=i_value/1e6) %>%
3115+ filter(year %in% c(max(year), max(year)-1) ) %>%
3116+ pivot_wider(names_from=year, values_from=c(e_value,i_value)) %>%
3117+ ## mutate(e_value_growth=(e_value_2019-e_value_2018)/e_value_2018*100,
3118+ ## i_value_growth=(i_value_2019-i_value_2018)/i_value_2018*100
3119+ ## ) %>%
3120+ mutate(trade_2018=e_value_2018+i_value_2018,
3121+ trade_2019=e_value_2019+i_value_2019
3122+ )
3123+
3124+eu27_extra_eu <- eu27_trade %>%
3125+ filter(partnerlabel=="Extra EU27") %>%
3126+ mutate(e_value_2019_share=100,
3127+ i_value_2019_share=100,
3128+ trade_2019_share=100) %>%
3129+ mutate(e_value_growth=(e_value_2019-e_value_2018)/e_value_2018*100,
3130+ i_value_growth=(i_value_2019-i_value_2018)/i_value_2018*100,
3131+ trade_value_growth=(trade_2019-trade_2018)/trade_2018*100) %>%
3132+ select(partnerlabel,
3133+ e_value_2019,e_value_2019_share, e_value_growth,
3134+ i_value_2019,i_value_2019_share, i_value_growth,
3135+ trade_2019,trade_2019_share, trade_value_growth
3136+ ) %>%
3137+ mutate(partnerlabel="Total extra EU27 trade")
3138+
3139+
3140+## eu27_trade <- eu27_trade %>%
3141+## mutate(e_value_2018_share=e_value_2018/eu27_extra_eu$e_value_2018*100,
3142+## e_value_2019_share=e_value_2019/eu27_extra_eu$e_value_2019*100,
3143+## i_value_2018_share=i_value_2018/eu27_extra_eu$i_value_2018*100,
3144+## i_value_2019_share=i_value_2019/eu27_extra_eu$i_value_2019*100,
3145+## )
3146+
3147+
3148+
3149+eu27_trade_implemented <- eu27_trade %>%
3150+ filter(partnerlabel %in% fta_implemented$country_label ) %>%
3151+ summarise(across(where(is.numeric), sum, na.rm=T)) %>%
3152+ ungroup %>%
3153+ mutate(e_value_2019_share=e_value_2019/eu27_extra_eu$e_value_2019*100,
3154+ i_value_2019_share=i_value_2019/eu27_extra_eu$i_value_2019*100,
3155+ trade_2019_share=trade_2019/eu27_extra_eu$trade_2019*100) %>%
3156+ mutate(e_value_growth=(e_value_2019-e_value_2018)/e_value_2018*100,
3157+ i_value_growth=(i_value_2019-i_value_2018)/i_value_2018*100,
3158+ trade_value_growth=(trade_2019-trade_2018)/trade_2018*100) %>%
3159+ mutate(partnerlabel="FTAs implemented") %>%
3160+ select(partnerlabel,
3161+ e_value_2019,e_value_2019_share, e_value_growth,
3162+ i_value_2019,i_value_2019_share, i_value_growth,
3163+ trade_2019,trade_2019_share, trade_value_growth
3164+ )
3165+
3166+
3167+
3168+
3169+fta_first <- fta %>%
3170+ filter(cat_1=="FTAs implemented") %>%
3171+ filter(cat_2=="First generation of FTAs")
3172+
3173+
3174+
3175+eu27_trade_first <- eu27_trade %>%
3176+ inner_join(y=fta_first, by=c("partnerlabel"="country_label")) %>%
3177+ group_by(cat_3) %>%
3178+ summarise(across(where(is.numeric), sum, na.rm=T)) %>%
3179+ ungroup %>%
3180+ arrange(cat_3) %>%
3181+
3182+
3183+ add_row(cat_3="New generation of FTAs",
3184+ e_value_2018=sum(.$e_value_2018),
3185+ e_value_2019=sum(.$e_value_2019),
3186+ i_value_2018=sum(.$i_value_2018),
3187+ i_value_2019=sum(.$i_value_2019),
3188+ .before=1
3189+ ) %>%
3190+ mutate(trade_2018=e_value_2018+i_value_2018,
3191+ trade_2019=e_value_2019+i_value_2019
3192+ ) %>%
3193+ mutate(e_value_2019_share=e_value_2019/eu27_extra_eu$e_value_2019*100,
3194+ i_value_2019_share=i_value_2019/eu27_extra_eu$i_value_2019*100,
3195+ trade_2019_share=trade_2019/eu27_extra_eu$trade_2019*100) %>%
3196+ mutate(e_value_growth=(e_value_2019-e_value_2018)/e_value_2018*100,
3197+ i_value_growth=(i_value_2019-i_value_2018)/i_value_2018*100,
3198+ trade_value_growth=(trade_2019-trade_2018)/trade_2018*100) %>%
3199+ rename("partnerlabel"="cat_3") %>%
3200+ select(partnerlabel,
3201+ e_value_2019,e_value_2019_share, e_value_growth,
3202+ i_value_2019,i_value_2019_share, i_value_growth,
3203+ trade_2019,trade_2019_share, trade_value_growth
3204+ )
3205+
3206+
3207+
3208+
3209+fta_dcfta <- fta %>%
3210+ filter(cat_1=="FTAs implemented") %>%
3211+ filter(cat_2=="DCFTAs")
3212+
3213+
3214+eu27_trade_dcfta <- eu27_trade %>%
3215+ inner_join(y=fta_dcfta, by=c("partnerlabel"="country_label")) %>%
3216+ group_by(cat_3) %>%
3217+ summarise(across(where(is.numeric), sum, na.rm=T)) %>%
3218+ ungroup %>%
3219+ mutate(trade_2018=e_value_2018+i_value_2018,
3220+ trade_2019=e_value_2019+i_value_2019
3221+ ) %>%
3222+ mutate(e_value_2019_share=e_value_2019/eu27_extra_eu$e_value_2019*100,
3223+ i_value_2019_share=i_value_2019/eu27_extra_eu$i_value_2019*100,
3224+ trade_2019_share=trade_2019/eu27_extra_eu$trade_2019*100) %>%
3225+ mutate(e_value_growth=(e_value_2019-e_value_2018)/e_value_2018*100,
3226+ i_value_growth=(i_value_2019-i_value_2018)/i_value_2018*100,
3227+ trade_value_growth=(trade_2019-trade_2018)/trade_2018*100) %>%
3228+ rename("partnerlabel"="cat_3") %>%
3229+ select(partnerlabel,
3230+ e_value_2019,e_value_2019_share, e_value_growth,
3231+ i_value_2019,i_value_2019_share, i_value_growth,
3232+ trade_2019,trade_2019_share, trade_value_growth
3233+ )
3234+
3235+
3236+
3237+
3238+
3239+fta_epa <- fta %>%
3240+ filter(cat_1=="FTAs implemented") %>%
3241+ filter(cat_2=="EPAs (implemented)" )
3242+
3243+
3244+eu27_trade_epa <- eu27_trade %>%
3245+ inner_join(y=fta_epa, by=c("partnerlabel"="country_label")) %>%
3246+ ## group_by(cat_3) %>%
3247+ summarise(across(where(is.numeric), sum, na.rm=T)) %>%
3248+ ungroup %>%
3249+ mutate(trade_2018=e_value_2018+i_value_2018,
3250+ trade_2019=e_value_2019+i_value_2019
3251+ ) %>%
3252+ mutate(e_value_2019_share=e_value_2019/eu27_extra_eu$e_value_2019*100,
3253+ i_value_2019_share=i_value_2019/eu27_extra_eu$i_value_2019*100,
3254+ trade_2019_share=trade_2019/eu27_extra_eu$trade_2019*100) %>%
3255+ mutate(e_value_growth=(e_value_2019-e_value_2018)/e_value_2018*100,
3256+ i_value_growth=(i_value_2019-i_value_2018)/i_value_2018*100,
3257+ trade_value_growth=(trade_2019-trade_2018)/trade_2018*100) %>%
3258+ mutate(partnerlabel="EPAs") %>%
3259+ select(partnerlabel,
3260+ e_value_2019,e_value_2019_share, e_value_growth,
3261+ i_value_2019,i_value_2019_share, i_value_growth,
3262+ trade_2019,trade_2019_share, trade_value_growth
3263+ )
3264+
3265+
3266+
3267+
3268+
3269+fta_new <- fta %>%
3270+ filter(cat_1=="FTAs implemented") %>%
3271+ filter(cat_2== "New generation of FTAs")
3272+
3273+
3274+eu27_trade_new <- eu27_trade %>%
3275+ inner_join(y=fta_new, by=c("partnerlabel"="country_label")) %>%
3276+ group_by(cat_3) %>%
3277+ summarise(across(where(is.numeric), sum, na.rm=T)) %>%
3278+ ungroup %>%
3279+ mutate(cat_3=recode(cat_3, "Andean Community"="Peru-Colombia-Ecuador")) %>%
3280+ arrange(cat_3) %>%
3281+ mutate(trade_2018=e_value_2018+i_value_2018,
3282+ trade_2019=e_value_2019+i_value_2019
3283+ ) %>%
3284+ add_row(cat_3="New generation of FTAs",
3285+ e_value_2018=sum(.$e_value_2018),
3286+ e_value_2019=sum(.$e_value_2019),
3287+ i_value_2018=sum(.$i_value_2018),
3288+ i_value_2019=sum(.$i_value_2019),
3289+ .before=1
3290+ ) %>%
3291+ mutate(trade_2018=e_value_2018+i_value_2018,
3292+ trade_2019=e_value_2019+i_value_2019
3293+ )%>%
3294+ mutate(e_value_2019_share=e_value_2019/eu27_extra_eu$e_value_2019*100,
3295+ i_value_2019_share=i_value_2019/eu27_extra_eu$i_value_2019*100,
3296+ trade_2019_share=trade_2019/eu27_extra_eu$trade_2019*100) %>%
3297+ mutate(e_value_growth=(e_value_2019-e_value_2018)/e_value_2018*100,
3298+ i_value_growth=(i_value_2019-i_value_2018)/i_value_2018*100,
3299+ trade_value_growth=(trade_2019-trade_2018)/trade_2018*100) %>%
3300+ rename("partnerlabel"="cat_3") %>%
3301+ select(partnerlabel,
3302+ e_value_2019,e_value_2019_share, e_value_growth,
3303+ i_value_2019,i_value_2019_share, i_value_growth,
3304+ trade_2019,trade_2019_share, trade_value_growth
3305+ )
3306+
3307+
3308+
3309+
3310+
3311+fta_concluded <- fta %>%
3312+ filter(cat_1=="FTAs concluded (under adoption or ratification)")
3313+
3314+
3315+
3316+
3317+
3318+eu27_trade_concluded <- eu27_trade %>%
3319+ inner_join(y=fta_concluded, by=c("partnerlabel"="country_label")) %>%
3320+ group_by(cat_2) %>%
3321+ summarise(across(where(is.numeric), sum, na.rm=T)) %>%
3322+ ungroup %>%
3323+ add_row(cat_2="FTAs concluded",
3324+ e_value_2018=sum(.$e_value_2018),
3325+ e_value_2019=sum(.$e_value_2019),
3326+ i_value_2018=sum(.$i_value_2018),
3327+ i_value_2019=sum(.$i_value_2019),
3328+ .before=1
3329+ ) %>%
3330+ mutate(trade_2018=e_value_2018+i_value_2018,
3331+ trade_2019=e_value_2019+i_value_2019
3332+ )%>%
3333+ mutate(e_value_2019_share=e_value_2019/eu27_extra_eu$e_value_2019*100,
3334+ i_value_2019_share=i_value_2019/eu27_extra_eu$i_value_2019*100,
3335+ trade_2019_share=trade_2019/eu27_extra_eu$trade_2019*100) %>%
3336+ mutate(e_value_growth=(e_value_2019-e_value_2018)/e_value_2018*100,
3337+ i_value_growth=(i_value_2019-i_value_2018)/i_value_2018*100,
3338+ trade_value_growth=(trade_2019-trade_2018)/trade_2018*100) %>%
3339+ rename("partnerlabel"="cat_2") %>%
3340+ select(partnerlabel,
3341+ e_value_2019,e_value_2019_share, e_value_growth,
3342+ i_value_2019,i_value_2019_share, i_value_growth,
3343+ trade_2019,trade_2019_share, trade_value_growth
3344+ )
3345+
3346+
3347+
3348+
3349+
3350+
3351+
3352+eu27_trade_future <- eu27_trade %>%
3353+ filter(partnerlabel %in% c("Australia", "India", "Indonesia", "Malaysia",
3354+ "Philippines", "Thailand", "New Zealand") ) %>%
3355+ arrange(partnerlabel )%>%
3356+ add_row(partnerlabel="FTAs future",
3357+ e_value_2018=sum(.$e_value_2018),
3358+ e_value_2019=sum(.$e_value_2019),
3359+ i_value_2018=sum(.$i_value_2018),
3360+ i_value_2019=sum(.$i_value_2019),
3361+ .before=1
3362+ ) %>%
3363+ mutate(trade_2018=e_value_2018+i_value_2018,
3364+ trade_2019=e_value_2019+i_value_2019
3365+ )%>%
3366+
3367+ mutate(e_value_2019_share=e_value_2019/eu27_extra_eu$e_value_2019*100,
3368+ i_value_2019_share=i_value_2019/eu27_extra_eu$i_value_2019*100,
3369+ trade_2019_share=trade_2019/eu27_extra_eu$trade_2019*100) %>%
3370+ mutate(e_value_growth=(e_value_2019-e_value_2018)/e_value_2018*100,
3371+ i_value_growth=(i_value_2019-i_value_2018)/i_value_2018*100,
3372+ trade_value_growth=(trade_2019-trade_2018)/trade_2018*100)%>%
3373+ select(partnerlabel,
3374+ e_value_2019,e_value_2019_share, e_value_growth,
3375+ i_value_2019,i_value_2019_share, i_value_growth,
3376+ trade_2019,trade_2019_share, trade_value_growth
3377+ )
3378+
3379+
3380+
3381+
3382+
3383+
3384+
3385+
3386+
3387+
3388+
3389+
3390+
3391+
3392+fta_out <- bind_rows(eu27_extra_eu, eu27_trade_implemented,
3393+ eu27_trade_new, eu27_trade_dcfta,
3394+ eu27_trade_epa,eu27_trade_concluded,
3395+ eu27_trade_future
3396+ ) %>%
3397+ format_all(1) %>%
3398+ mutate(across(contains("growth"), ~paste(.x,"%", sep=""))) %>%
3399+ mutate(across(contains("share"), ~paste(.x,"%", sep="")))
3400+
3401+
3402+
3403+
3404+saveRDS(fta_out, "./RDS_output/table45.RDS")
3405+
3406+
3407+ write.xlsx(fta_out, file = "./excel_files/raw/table45.xlsx",
3408+ sheetName = "data", append = FALSE, row.names=F)
30983409
30993410
31003411