The previous 11 modules gave you the vocabulary. This one asks you to use it. Three real analyses on Kenyan data, each replicating an analysis published on this site, end-to-end in Python.
Project 1 — the bank-rates spread
Using the bankrates DataFrame (21 months of commercial bank lending and deposit rates), compute the spread (lending − deposit), plot it over time, and run a regression of the spread on a linear trend. Is the spread widening, narrowing, or stable? What does it tell you about competitive intensity in Kenyan banking?
bankrates['spread'] = bankrates['lending_rate'] - bankrates['deposit_rate']fig, ax = plt.subplots(figsize=(10, 5))ax.plot(bankrates['month'], bankrates['spread'])ax.set_title('Lending-deposit spread, Kenyan banks')plt.show()# Regression: spread on a linear time trendbankrates['t'] = range(len(bankrates))import statsmodels.formula.api as smfmodel = smf.ols('spread ~ t', data=bankrates).fit()print(model.summary())
Project 2 — pension allocation shift
The pension DataFrame has 14 half-years of pension-industry asset allocation by asset class. Compute the share of government securities each half-year, plot the trend, and identify the inflection point. What was happening macroeconomically at that inflection?
# Compute sharepension['govt_share'] = pension['govt_securities'] / pension['total']# Plotfig, ax = plt.subplots()ax.plot(pension['period'], pension['govt_share'])ax.set_ylabel('Share of govt securities')plt.show()
Project 3 — M-PESA growth rate
The mpesa DataFrame has Kenyan mobile-money volumes over time. Compute the year-over-year growth rate, plot it, and fit a linear trend. Is the growth rate decelerating? At what implied saturation level?
mpesa['yoy_growth'] = mpesa['volume_bn'].pct_change(periods=12)fig, ax = plt.subplots()ax.plot(mpesa['date'], mpesa['yoy_growth'])ax.set_ylabel('YoY growth (%)')plt.show()
What you've learned
If you can do these three projects without copying — load data, transform it, plot it, fit a model, interpret the output — you have working Python at an applied-economist level. The toolkit from here is mostly more libraries (scipy, scikit-learn, networkx) and more data, not more language. The language is mostly behind you.
What to do next
Pick a real question you care about. Pull data — Kenyan or otherwise. Build a notebook. Publish it. The single highest-leverage next step is doing one analysis end-to-end and writing it up. Everything else compounds from there.
Exercise
Design your first real-world Python project end-to-end. Pick one: (a) Pull and analyse the CBK weekly T-bill auction results to find the relationship between auction acceptance rate and subsequent yields. (b) Scrape Safaricom's annual M-Pesa transaction volumes and model growth rates. (c) Use Kenya NBS quarterly GDP data to build a leading-indicator model. For your chosen project: (1) Outline the steps from data acquisition to final report. (2) Identify the specific Python libraries at each step. (3) Estimate realistic time-to-completion. (4) Describe what 'publishing it' looks like as an artefact.