• R/O
  • SSH

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisionead5c3b4e42a711babe2a69ef5f59a641abf6e4a (tree)
Time2021-01-17 07:07:42
AuthorLorenzo Isella <lorenzo.isella@gmai...>
CommiterLorenzo Isella

Log Message

I completed the code with all the ranking stuff.

Change Summary

Incremental Difference

diff -r 0ecd8ac171bf -r ead5c3b4e42a R-codes/process_baci.R
--- a/R-codes/process_baci.R Fri Jan 15 16:29:29 2021 +0100
+++ b/R-codes/process_baci.R Sat Jan 16 23:07:42 2021 +0100
@@ -1,7 +1,7 @@
11 rm(list=ls())
22
33
4-## last saved on Time-stamp: "2021-01-15 16:22:40 lorenzo"
4+## last saved on Time-stamp: "2021-01-16 23:06:49 lorenzo"
55
66
77
@@ -15,6 +15,9 @@
1515
1616
1717
18+
19+n_rank <- 20 ### number of values for the discretized ranking
20+
1821 eu_list <- c("BE", "BG","CZ", "DK", "DE", "EE", "IE", "GR",
1922 "ES", "FR", "IT", "CY", "LV", "LT", "LU", "HU", "MT",
2023 "NL", "AT","PL", "PT", "RO", "SI", "SK", "FI","SE", "HR" ) %>%
@@ -339,12 +342,42 @@
339342 full_join(y=a6) %>%
340343 full_join(y=a7) %>%
341344 full_join(y=a8) %>%
342- round_all(3) %>%
345+ ## round_all(3) %>%
343346 left_join(y=prod_codes, by=c("k"="code"))
344347
345348
346349
347350
351+## test_a2 <- a2 %>%
352+## mutate(N_rank=dense_rank(N_eu_imports)) %>%
353+## arrange(N_rank)
354+
355+
356+## test_a2_round <- a2 %>%
357+## round_all(3) %>%
358+## mutate(N_rank=dense_rank(N_eu_imports)) %>%
359+## arrange(N_rank)
360+
361+
362+
363+
364+## test_a4 <- a4 %>%
365+## mutate(HHI_rank=dense_rank(HHI_EU_imports)) %>%
366+## arrange(HHI_rank)
367+
368+
369+## test_a4_round <- a4 %>%
370+## round_all(3) %>%
371+## mutate(HHI_rank=dense_rank(HHI_EU_imports)) %>%
372+## arrange(HHI_rank)
373+
374+
375+
376+
377+
378+
379+
380+
348381 ## df_tot_round <- a1 %>%
349382 ## full_join(y=a2) %>%
350383 ## full_join(y=a3) %>%
@@ -378,7 +411,8 @@
378411
379412 extra_eu_imports <- df_imports_raw %>%
380413 select(k, i_value) %>%
381- group_by(k) %>%
414+ group_by(k) %>% ## I just consider the value of the imports from
415+ ### extra EU for every product line k
382416 summarise(extra_EU_import_value=sum(i_value, na.rm=T))
383417
384418
@@ -394,7 +428,7 @@
394428 mutate(rank_N_eu=dense_rank(N_eu_imports),
395429 rank_HHI_EU=dense_rank(desc(HHI_EU_imports)),
396430 rank_balance=dense_rank(balance_over_imports),
397- rank_price_diff=dense_rank(desc(import_price_difference)),
431+ rank_price_diff=dense_rank(desc(import_price_difference))
398432 ) %>%
399433 rowwise %>%
400434 mutate(mean_ranking=mean(c_across(rank_N_eu:rank_price_diff),na.rm=T)) %>%
@@ -440,11 +474,15 @@
440474 select(-q) %>%
441475 filter(i %in% codes_eu$country_code, j %in% codes_eu$country_code,
442476 t==max(t)) %>%
443- filter(k %in% unique(df_rank$k)) %>%
477+ filter(k %in% df_rank$k) %>%
444478 group_by(k) %>%
445479 summarise(number_EU_providers=length(unique(i)),
446480 value_intra_EU_exports=sum(v, na.rm=T)) %>%
447- ungroup
481+ ungroup ### it is very important that I use the unique number of EU
482+### exporters (unique(i)): in general they are repeated because, for a given
483+ # product k, one exporter can export to different EU countries.
484+###Instead, I can just sum the value of the exports because I do not need
485+### to consider whether the exporter exports to one or more EU countrues
448486
449487
450488
@@ -667,6 +705,21 @@
667705 save_excel(df_hs2, "share_hs2.xlsx")
668706
669707
708+
709+df_rank_final <- df_rank %>%
710+ mutate(rank_N_eu_discrete=ntile(N_eu_imports, n_rank),
711+ rank_HHI_EU_discrete=ntile(desc(HHI_EU_imports), n_rank),
712+ rank_balance_discrete=ntile(balance_over_imports,n_rank),
713+ rank_price_diff_discrete=ntile(desc(import_price_difference),n_rank)
714+ ) %>%
715+ rowwise %>%
716+ mutate(mean_ranking_discrete=mean(c_across(rank_N_eu_discrete:rank_price_diff_discrete),na.rm=T)) %>%
717+ ungroup
718+
719+
720+save_excel(df_rank_final, "final_ranking_complete.xlsx")
721+
722+
670723 print("So far so good")
671724
672725