Countries with highest account surpluses

Meng Lu <lumeng.dev@gmail.com>
2015-6-27

Basic syntax of EntityValue

?EntityValue

EntityValue[(Entity["China", Entity["Country","China"], "Entity[\"Country\", \"China\"]", "country"]),"CurrentAccountBalance"]

EntityValue[(Entity["United States", Entity["Country","UnitedStates"], "Entity[\"Country\", \"UnitedStates\"]", "country"]),"CurrentAccountBalance"]

EntityValue[(Entity["United States", Entity["Country","UnitedStates"], "Entity[\"Country\", \"UnitedStates\"]", "country"]),(EntityProperty[(RowDefault["current account", " | ", (RowWithSeparators[;, ";", "quarterly", "seasonally adjusted"])]), EntityProperty["Country","CurrentAccount",{"Frequency"->"Quarterly","SeasonalAdjustment"->"SeasonallyAdjusted"}], "EntityProperty[\"Country\", \"CurrentAccount\", {\"Frequency\" -> \"Quarterly\", \"SeasonalAdjustment\" -> \"SeasonallyAdjusted\"}]"])]

data["raw"]=EntityValue[Entity["Country"],{"Name","Population","CurrentAccountBalance"}]

data["processed",1]=Composition[
Reverse,
SortBy[#,#[[2;;3]]&]&,
Cases[#,{_,__?QuantityQ}]&,
Map[{#[[1]],#[[3]]/#[[2]],#[[3]]}&,#]&
][data["raw"]]

data["per capita current account surplus"]=data["processed",1][[All,{1,2}]]

?Histogram

Histogram[data["per capita current account surplus"][[All,2]]]