@@ -4,7 +4,7 @@ jupytext:
4
4
extension : .md
5
5
format_name : myst
6
6
format_version : 0.13
7
- jupytext_version : 1.16.1
7
+ jupytext_version : 1.16.7
8
8
kernelspec :
9
9
display_name : Python 3 (ipykernel)
10
10
language : python
@@ -31,7 +31,7 @@ import yfinance as yf
31
31
import pandas as pd
32
32
import statsmodels.api as sm
33
33
34
- from pandas_datareader import wb
34
+ import wbgapi as wb
35
35
from scipy.stats import norm, cauchy
36
36
from pandas.plotting import register_matplotlib_converters
37
37
register_matplotlib_converters()
@@ -790,24 +790,24 @@ def empirical_ccdf(data,
790
790
:tags: [hide-input]
791
791
792
792
def extract_wb(varlist=['NY.GDP.MKTP.CD'],
793
- c='all_countries ',
793
+ c='all ',
794
794
s=1900,
795
795
e=2021,
796
796
varnames=None):
797
- if c == "all_countries":
798
- # Keep countries only (no aggregated regions)
799
- countries = wb.get_countries()
800
- countries_name = countries[countries['region'] != 'Aggregates']['name'].values
801
- c = "all"
802
797
803
- df = wb.download(indicator=varlist, country=c, start=s, end=e).stack().unstack(0).reset_index()
804
- df = df.drop(['level_1'], axis=1).transpose()
798
+ df = wb.data.DataFrame(varlist, economy=c, time=range(s, e+1, 1), skipAggs=True)
799
+ df.index.name = 'country'
800
+
805
801
if varnames is not None:
806
- df.columns = varnames
807
- df = df[1:]
802
+ df.columns = variable_names
803
+
804
+ df.index = df.index.map(lambda x: cntry_mapper[x]) #map iso3c to name values
808
805
809
- df1 =df[df.index.isin(countries_name)]
810
- return df1
806
+ return df
807
+ ```
808
+
809
+ ``` {code-cell} ipython3
810
+ df_gdp1
811
811
```
812
812
813
813
### Firm size
@@ -914,13 +914,25 @@ variable_code = ['NY.GDP.MKTP.CD', 'NY.GDP.PCAP.CD']
914
914
variable_names = ['GDP', 'GDP per capita']
915
915
916
916
df_gdp1 = extract_wb(varlist=variable_code,
917
- c="all_countries ",
918
- s=" 2021" ,
919
- e=" 2021" ,
917
+ c="all ",
918
+ s=2021,
919
+ e=2021,
920
920
varnames=variable_names)
921
921
df_gdp1.dropna(inplace=True)
922
922
```
923
923
924
+ ``` {code-cell} ipython3
925
+
926
+ ```
927
+
928
+ ``` {code-cell} ipython3
929
+
930
+ ```
931
+
932
+ ``` {code-cell} ipython3
933
+
934
+ ```
935
+
924
936
``` {code-cell} ipython3
925
937
---
926
938
mystnb:
0 commit comments