Hey everyone. To anyone who may use Python... A coworker and I wish to obtain some trade data from U.N. Comtrade. Here is a small example, using requests.
Code:
cls
clear *
python:
import requests
url='https://comtrade.un.org/api/get?max=100000&type=C&freq=M&px=S2&ps=201001&r=all&p=156&rg=2&cc=9101'
un_data=requests.get(url)
print(un_data.content)
end
This produces a.... thing. It looks like a dictionary. It looks like a dictionary, of some kind. How might I convert this to a dataframe so I can put it into Stata and work with it? All i need is for "yr", "period", "periodDesc":"January 2010", and so on, to have their own column, respectively. Note, I will cross post this on Stack and link it to it. The final thing should look like this
Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input long(yr period) str24 rtTitle long TradeValue
2017 201706 "Canada"                     147650
2017 201703 "China, Hong Kong SAR"      3749878
2017 201710 "Canada"                      57796
2017 201708 "China, Hong Kong SAR"      2637734
2017 201707 "Canada"                     250106
2017 201712 "China, Hong Kong SAR"      2283290
2017 201712 "Belgium"                     83828
2017 201704 "Rep. of Korea"               78321
2017 201707 "Belgium"                    105535
2017 201710 "ASEAN"                      255697
2017 201711 "ASEAN"                      809781
2017 201709 "Canada"                     237649
2017 201712 "Canada"                      19262
2017 201706 "ASEAN"                      351560
2017 201701 "Poland"                        186
2017 201705 "China, Hong Kong SAR"      2585817
2017 201711 "Belgium"                     54809
2017 201711 "South Africa"                    0
2017 201706 "Japan"                       23631
2017 201708 "EU"                        3992007
2017 201706 "United Kingdom"            1769918
2017 201708 "United Kingdom"            2754432
2017 201709 "United Kingdom"            2757139
2017 201705 "Japan"                       31784
2017 201702 "EU"                        4471396
2017 201701 "Denmark"                     62459
2017 201702 "Japan"                       26842
2017 201705 "United Kingdom"            2497820
2017 201706 "EU"                        3280962
2017 201708 "Jordan"                       1352
2017 201704 "Jordan"                       1127
2017 201709 "EU"                        4515770
2017 201703 "United Kingdom"             550694
2017 201706 "Denmark"                       157
2017 201705 "Switzerland"              24861018
2017 201705 "Spain"                        3910
2017 201702 "Spain"                        7367
2017 201705 "Portugal"                   554711
2017 201707 "Spain"                        2256
2017 201705 "Indonesia"                    4546
2017 201709 "Portugal"                   251010
2017 201711 "Spain"                       61724
2017 201702 "Portugal"                   345734
2017 201709 "Switzerland"              18864650
2017 201704 "Switzerland"              29645183
2017 201707 "Portugal"                   519235
2017 201708 "Spain"                       55665
2017 201704 "Portugal"                   214740
2017 201710 "Switzerland"              25679499
2017 201712 "Switzerland"              39337860
2017 201708 "Portugal"                    13542
2017 201708 "Malaysia"                     3501
2017 201710 "United States of America"   295324
2017 201703 "United States of America"    95075
2017 201711 "France"                     272189
2017 201703 "Malaysia"                     6931
2017 201705 "United States of America"   123130
2017 201706 "Malta"                        8422
2017 201710 "United Arab Emirates"        15488
2017 201710 "Thailand"                    62043
2017 201702 "France"                     136805
2017 201701 "United Arab Emirates"         1715
2017 201709 "France"                     368213
2017 201707 "United States of America"   156303
2017 201705 "France"                     329651
2017 201704 "United States of America"    48700
2017 201701 "Thailand"                        7
2017 201707 "Thailand"                    10563
2017 201710 "United Kingdom"            1535513
2017 201711 "United Kingdom"            1736628
2017 201703 "Japan"                       23308
2017 201704 "South Africa"                30253
2017 201704 "Japan"                        3089
2017 201702 "Denmark"                      4755
2017 201702 "Norway"                       6483
2017 201710 "Japan"                       10429
2017 201707 "Denmark"                    319572
2017 201712 "EU"                        4755897
2017 201711 "Honduras"                     9113
2017 201707 "Japan"                       16469
2017 201706 "South Africa"                  102
2017 201704 "United Kingdom"             837483
2017 201709 "Japan"                       19201
2017 201701 "EU"                        2397025
2017 201708 "Denmark"                     41270
2017 201711 "EU"                        5367992
2017 201701 "United Kingdom"            1426777
2017 201707 "United Kingdom"            3199253
2017 201703 "EU"                        3258888
2017 201710 "EU"                        3521723
2017 201704 "EU"                        2048226
2017 201705 "Denmark"                    201524
2017 201712 "United Kingdom"            2474348
2017 201709 "Norway"                       2554
2017 201707 "EU"                        5736215
2017 201702 "United Kingdom"            2473939
2017 201705 "EU"                        4782490
2017 201707 "Italy"                      543315
2017 201710 "Croatia"                     21260
2017 201705 "Singapore"                  260451
end