@@ -4,7 +4,7 @@ jupytext:
44 extension : .md
55 format_name : myst
66 format_version : 0.13
7- jupytext_version : 1.16.1
7+ jupytext_version : 1.16.7
88kernelspec :
99 display_name : Python 3 (ipykernel)
1010 language : python
@@ -31,7 +31,7 @@ import yfinance as yf
3131import pandas as pd
3232import statsmodels.api as sm
3333
34- from pandas_datareader import wb
34+ import wbgapi as wb
3535from scipy.stats import norm, cauchy
3636from pandas.plotting import register_matplotlib_converters
3737register_matplotlib_converters()
@@ -790,24 +790,24 @@ def empirical_ccdf(data,
790790:tags: [hide-input]
791791
792792def extract_wb(varlist=['NY.GDP.MKTP.CD'],
793- c='all_countries ',
793+ c='all ',
794794 s=1900,
795795 e=2021,
796796 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"
802797
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+
805801 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
808805
809- df1 =df[df.index.isin(countries_name)]
810- return df1
806+ return df
807+ ```
808+
809+ ``` {code-cell} ipython3
810+ df_gdp1
811811```
812812
813813### Firm size
@@ -914,13 +914,25 @@ variable_code = ['NY.GDP.MKTP.CD', 'NY.GDP.PCAP.CD']
914914variable_names = ['GDP', 'GDP per capita']
915915
916916df_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,
920920 varnames=variable_names)
921921df_gdp1.dropna(inplace=True)
922922```
923923
924+ ``` {code-cell} ipython3
925+
926+ ```
927+
928+ ``` {code-cell} ipython3
929+
930+ ```
931+
932+ ``` {code-cell} ipython3
933+
934+ ```
935+
924936``` {code-cell} ipython3
925937---
926938mystnb:
0 commit comments