Conectarse a la base de Datos del Banco Mundial con R

Los software más utilizados en econometría están siendo conectados a la base de indicadores económicos y sociales del Banco Mundial. Estos software son Stata y R, pero poco me interesa Stata hasta poder conseguir una licencia legal, por eso lo enseñaré en R project que puede obtenerse gratuito en la página web www.r-project.org.

Vamos con R:

Primero hay que instalar el paquete WDI

install.packages("WDI")

Una vez instalado activarlo

library(WDI)

Si nos interesa el PIB, entonces es GDP en inglés. Podemos preguntarle a R ¿Qué indicadores contienen al PIB?


indicadores<-WDIsearch("gdp")

Para que lo podamos mirar en columnas el nombre del indicador y su descripción

View(indicadores)

Supongamos que nos interesa el valor agregado de la agricultura como porcentaje del PIB. Es el indicador 70 como indica la tabla de tu R. Construimos la sintaxis para jalar ese indicador.

agricu.porc.pib<-WDI(country="all", indicator=indicadores[70,1], start=2005, end=2005)

Función WDI, países todos si es conveniente sino pues también podemos hacerle saber que nos interesa Nicaragua o un conjunto de países específicos. Luego posición del indicador y el o los años.

Listo:
agricu.porc.pib
    iso2c                                        country NV.AGR.TOTL.ZS year
1      1A                                     Arab World     7.85138172 2005
2      S3                         Caribbean small states     4.47845892 2005
3      Z4        East Asia & Pacific (all income levels)     3.66554573 2005
4      4E          East Asia & Pacific (developing only)    12.20919805 2005
5      XC                                      Euro area     1.82787204 2005
6      Z7      Europe & Central Asia (all income levels)     2.13224710 2005
7      7E        Europe & Central Asia (developing only)     8.78173179 2005
8      EU                                 European Union     1.72465673 2005
9      XE         Heavily indebted poor countries (HIPC)    28.57146942 2005
10     XD                                    High income     1.47400362 2005
11     XR                           High income: nonOECD     1.48607946 2005
12     XS                              High income: OECD     1.47355762 2005
13     ZJ  Latin America & Caribbean (all income levels)     5.98477398 2005
14     XJ    Latin America & Caribbean (developing only)     6.13228479 2005
15     XL   Least developed countries: UN classification    26.47922008 2005
16     XO                            Low & middle income    10.59878858 2005
17     XM                                     Low income    28.04273717 2005
18     XN                            Lower middle income    17.77794845 2005
19     ZQ Middle East & North Africa (all income levels)     7.76347015 2005
20     XQ   Middle East & North Africa (developing only)    10.92375390 2005
21     XP                                  Middle income    10.13130663 2005
22     XU                                  North America     1.25289580 2005
23     XY                                 Not classified             NA 2005
24     OE                                   OECD members     1.59965337 2005
25     S4                             Other small states     7.32728515 2005
26     S2                    Pacific island small states    16.93726769 2005
27     S1                                   Small states     6.45713973 2005
28     8S                                     South Asia    19.30337258 2005
29     ZG         Sub-Saharan Africa (all income levels)    16.52401046 2005
30     ZF           Sub-Saharan Africa (developing only)    16.53849362 2005
31     XT                            Upper middle income     8.00812136 2005
32     1W                                          World     3.03295598 2005
33     AF                                    Afghanistan    39.48041625 2005
34     AL                                        Albania    22.80000000 2005
35     DZ                                        Algeria     8.22165677 2005
36     AS                                 American Samoa             NA 2005
37     AD                                        Andorra             NA 2005
38     AO                                         Angola     8.48999382 2005
39     AG                            Antigua and Barbuda     2.02437833 2005
40     AR                                      Argentina     9.40102923 2005
41     AM                                        Armenia    20.89251738 2005
42     AW                                          Aruba             NA 2005
43     AU                                      Australia     3.26503695 2005
44     AT                                        Austria     1.60575523 2005
45     AZ                                     Azerbaijan     9.89547339 2005
46     BS                                   Bahamas, The     2.19414531 2005
47     BH                                        Bahrain             NA 2005
48     BD                                     Bangladesh    20.14203289 2005
49     BB                                       Barbados     3.76504181 2005
50     BY                                        Belarus     9.77364858 2005
51     BE                                        Belgium     0.82794375 2005
52     BZ                                         Belize    15.29950835 2005
53     BJ                                          Benin    32.19986734 2005
54     BM                                        Bermuda     0.84163085 2005
55     BT                                         Bhutan    23.17913145 2005
56     BO                                        Bolivia    14.37801370 2005
57     BA                         Bosnia and Herzegovina    10.54785469 2005
58     BW                                       Botswana     1.81917047 2005
59     BR                                         Brazil     5.70839076 2005
60     BN                              Brunei Darussalam     0.94659327 2005
61     BG                                       Bulgaria     9.06930548 2005
62     BF                                   Burkina Faso    34.12518227 2005
63     BI                                        Burundi    44.49652934 2005
64     KH                                       Cambodia    32.40133014 2005
65     CM                                       Cameroon    19.53492334 2005
66     CA                                         Canada     1.84062542 2005
67     CV                                     Cape Verde     9.01891850 2005
68     KY                                 Cayman Islands             NA 2005
69     CF                       Central African Republic    54.44285194 2005
70     TD                                           Chad    12.26984427 2005
71     JG                                Channel Islands             NA 2005
72     CL                                          Chile     4.64773615 2005
73     CN                                          China    12.12302312 2005
74     CO                                       Colombia     8.39322938 2005
75     KM                                        Comoros    51.01523700 2005
76     CD                               Congo, Dem. Rep.    45.52059724 2005
77     CG                                    Congo, Rep.     4.54418040 2005
78     CR                                     Costa Rica     8.73148960 2005
79     CI                                  Cote d'Ivoire    22.81608433 2005
80     HR                                        Croatia     5.04338355 2005
81     CU                                           Cuba     5.62288000 2005
82     CW                                        Curacao             NA 2005
83     CY                                         Cyprus     2.78836614 2005
84     CZ                                 Czech Republic             NA 2005
85     DK                                        Denmark     1.43033305 2005
86     DJ                                       Djibouti     3.53352507 2005
87     DM                                       Dominica    13.65771600 2005
88     DO                             Dominican Republic     7.45391854 2005
89     EC                                        Ecuador     7.04782412 2005
90     EG                               Egypt, Arab Rep.    14.86467224 2005
91     SV                                    El Salvador    10.61217774 2005
92     GQ                              Equatorial Guinea     2.61041624 2005
93     ER                                        Eritrea    24.20987982 2005
94     EE                                        Estonia             NA 2005
95     ET                                       Ethiopia    46.69088360 2005
96     FO                                 Faeroe Islands             NA 2005
97     FJ                                           Fiji    14.06289715 2005
98     FI                                        Finland     2.77010133 2005
99     FR                                         France     2.29322260 2005
100    PF                               French Polynesia             NA 2005
101    GA                                          Gabon     4.88744011 2005
102    GM                                    Gambia, The    28.40069653 2005
103    GE                                        Georgia    16.68902136 2005
104    DE                                        Germany     0.87322315 2005
105    GH                                          Ghana    40.93535116 2005
106    GR                                         Greece             NA 2005
107    GL                                      Greenland             NA 2005
108    GD                                        Grenada     3.39623611 2005
109    GU                                           Guam             NA 2005
110    GT                                      Guatemala    13.38352932 2005
111    GN                                         Guinea    24.15829870 2005
112    GW                                  Guinea-Bissau             NA 2005
113    GY                                         Guyana    34.60289320 2005
114    HT                                          Haiti             NA 2005
115    HN                                       Honduras    13.65229098 2005
116    HK                           Hong Kong SAR, China     0.08387009 2005
117    HU                                        Hungary     4.18430524 2005
118    IS                                        Iceland     6.31078759 2005
119    IN                                          India    18.81054227 2005
120    ID                                      Indonesia    13.12661836 2005
121    IR                             Iran, Islamic Rep.    10.18908055 2005
122    IQ                                           Iraq             NA 2005
123    IE                                        Ireland     1.58231971 2005
124    IM                                    Isle of Man             NA 2005
125    IL                                         Israel             NA 2005
126    IT                                          Italy     2.18897744 2005
127    JM                                        Jamaica     5.99164690 2005
128    JP                                          Japan     1.21668930 2005
129    JO                                         Jordan     3.08063181 2005
130    KZ                                     Kazakhstan     6.78789842 2005
131    KE                                          Kenya    27.19868287 2005
132    KI                                       Kiribati    25.58607539 2005
133    KP                               Korea, Dem. Rep.             NA 2005
134    KR                                    Korea, Rep.     3.33203246 2005
135    KV                                         Kosovo             NA 2005
136    KW                                         Kuwait             NA 2005
137    KG                                Kyrgyz Republic    31.94579994 2005
138    LA                                        Lao PDR    36.18082162 2005
139    LV                                         Latvia     3.96542706 2005
140    LB                                        Lebanon     6.24745103 2005
141    LS                                        Lesotho     9.01115691 2005
142    LR                                        Liberia             NA 2005
143    LY                                          Libya     2.33932825 2005
144    LI                                  Liechtenstein             NA 2005
145    LT                                      Lithuania     4.81515504 2005
146    LU                                     Luxembourg     0.44508632 2005
147    MO                               Macao SAR, China     0.00000000 2005
148    MK                                 Macedonia, FYR    12.32481746 2005
149    MG                                     Madagascar    28.29332681 2005
150    MW                                         Malawi    32.63406398 2005
151    MY                                       Malaysia     8.39397489 2005
152    MV                                       Maldives     9.94487682 2005
153    ML                                           Mali    36.57742402 2005
154    MT                                          Malta     2.63442800 2005
155    MH                               Marshall Islands             NA 2005
156    MR                                     Mauritania    30.51723945 2005
157    MU                                      Mauritius     6.03707219 2005
158    MX                                         Mexico     3.72232432 2005
159    FM                          Micronesia, Fed. Sts.             NA 2005
160    MD                                        Moldova    19.53082382 2005
161    MC                                         Monaco             NA 2005
162    MN                                       Mongolia    22.05895900 2005
163    ME                                     Montenegro    10.45709624 2005
164    MA                                        Morocco    14.67752281 2005
165    MZ                                     Mozambique    26.96016103 2005
166    MM                                        Myanmar             NA 2005
167    NA                                        Namibia    11.32748801 2005
168    NP                                          Nepal    36.34885184 2005
169    NL                                    Netherlands     2.09017454 2005
170    NC                                  New Caledonia             NA 2005
171    NZ                                    New Zealand     5.40291681 2005
172    NI                                      Nicaragua    18.98825838 2005
173    NE                                          Niger             NA 2005
174    NG                                        Nigeria    32.75542173 2005
175    MP                       Northern Mariana Islands             NA 2005
176    NO                                         Norway     1.52224435 2005
177    OM                                           Oman             NA 2005
178    PK                                       Pakistan    21.46540471 2005
179    PW                                          Palau     3.48305008 2005
180    PA                                         Panama     6.97917894 2005
181    PG                               Papua New Guinea    38.61126772 2005
182    PY                                       Paraguay    21.13138747 2005
183    PE                                           Peru     7.20677888 2005
184    PH                                    Philippines    12.66480278 2005
185    PL                                         Poland     4.52887991 2005
186    PT                                       Portugal     2.78834604 2005
187    PR                                    Puerto Rico     0.60290834 2005
188    QA                                          Qatar             NA 2005
189    RO                                        Romania    10.13688017 2005
190    RU                             Russian Federation     4.96657343 2005
191    RW                                         Rwanda    38.38843090 2005
192    WS                                          Samoa    13.23569044 2005
193    SM                                     San Marino             NA 2005
194    ST                          Sao Tome and Principe    16.80607369 2005
195    SA                                   Saudi Arabia     3.23718193 2005
196    SN                                        Senegal    16.66096779 2005
197    RS                                         Serbia    12.05448258 2005
198    SC                                     Seychelles     2.36422695 2005
199    SL                                   Sierra Leone    51.56660647 2005
200    SG                                      Singapore     0.05419845 2005
201    SX                      Sint Maarten (Dutch part)             NA 2005
202    SK                                Slovak Republic     3.65029348 2005
203    SI                                       Slovenia     2.71340826 2005
204    SB                                Solomon Islands    34.45556864 2005
205    SO                                        Somalia             NA 2005
206    ZA                                   South Africa     2.66953686 2005
207    SS                                    South Sudan             NA 2005
208    ES                                          Spain     3.20145629 2005
209    LK                                      Sri Lanka    11.81947682 2005
210    KN                            St. Kitts and Nevis     2.25399579 2005
211    LC                                      St. Lucia     3.75025817 2005
212    MF                       St. Martin (French part)             NA 2005
213    VC                 St. Vincent and the Grenadines     6.28290587 2005
214    SD                                          Sudan    31.98474506 2005
215    SR                                       Suriname     5.41938385 2005
216    SZ                                      Swaziland     8.79471283 2005
217    SE                                         Sweden     1.23639717 2005
218    CH                                    Switzerland     1.26760064 2005
219    SY                           Syrian Arab Republic    19.48961261 2005
220    TJ                                     Tajikistan    23.97520072 2005
221    TZ                                       Tanzania    31.75921358 2005
222    TH                                       Thailand    10.26510621 2005
223    TL                                    Timor-Leste             NA 2005
224    TG                                           Togo    39.40855815 2005
225    TO                                          Tonga    22.02593798 2005
226    TT                            Trinidad and Tobago     0.48953669 2005
227    TN                                        Tunisia    10.12734687 2005
228    TR                                         Turkey    10.79623017 2005
229    TM                                   Turkmenistan    18.80724562 2005
230    TC                       Turks and Caicos Islands             NA 2005
231    TV                                         Tuvalu             NA 2005
232    UG                                         Uganda    26.70464208 2005
233    UA                                        Ukraine    10.39983538 2005
234    AE                           United Arab Emirates     1.39541335 2005
235    GB                                 United Kingdom     0.67419835 2005
236    US                                  United States     1.21248397 2005
237    UY                                        Uruguay    10.37254080 2005
238    UZ                                     Uzbekistan    27.96856667 2005
239    VU                                        Vanuatu    21.94525904 2005
240    VE                                  Venezuela, RB     4.02286823 2005
241    VN                                        Vietnam    20.97017317 2005
242    VI                          Virgin Islands (U.S.)             NA 2005
243    PS                             West Bank and Gaza             NA 2005
244    YE                                    Yemen, Rep.    10.54766696 2005
245    ZM                                         Zambia    23.31833168 2005
246    ZW                                       Zimbabwe    18.57727858 2005




Podemos hacer el llamado al indicador para Nicaragua. 
 agricu.porc.pib$NV.AGR.TOTL.ZS[agricu.porc.pib$country=="Nicaragua"]
[1] 18.98826


Quiero graficarlo entonces utilizo plot con identificación de los nombres

plot(agricu.porc.pib$NV.AGR.TOTL.ZS,type="n", ylab="Porcentajes",xlab=NA, main="Valor Agregado de la Agricultura como porcentaje del pib", sub="Fuente: Banco Mundial, Indicador 2005")
text(agricu.porc.pib$NV.AGR.TOTL.ZS, agricu.porc.pib$country)




Espero que les haya sido útil.

Sugerencias, comentarios o aportes a:
morales.economia@gmail.com

Economista: Deybi Morales León

Saludos

Comentarios

Envíanos un mensaje

Nombre

Correo electrónico *

Mensaje *