Module 1 · Days 1–10 · Part I

Python for Macroeconomics

Core programming, data wrangling, and API interaction.

Start Day 1
0/10 days completed
0/10 videos published

What you'll learn

  1. 1
    Days 1–3
    Syntax, control flow, functions, and virtual environments (.venv).

    By the end: Students write a small reusable Python module of macro tools, run it inside a proper virtual environment, and use it to pull the live Bank of Canada overnight rate.

  2. 2
    Days 4–7
    Data manipulation with pandas, handling time-series indexing.

    By the end: Students build a clean, validated monthly and quarterly Canadian macro panel from real BoC, FRED and Statistics Canada data. This is the same logic as Cells 3–5 of Macro_Fall_2026.ipynb, but now they understand every line.

  3. 3
    Days 8–10
    Fetching indicators from the Bank of Canada, FRED and Statistics Canada via REST APIs.

    By the end: Students replace the "black box" get_course_data.py with their own tested extraction package, macro_extract. It fetches Bank of Canada, FRED and Statistics Canada series robustly, stores the raw responses, and writes one tidy staging file ready for DuckDB (Days 11–20).

Tools

PythonpandasrequestspytestGit

The ten days

Before you start: module setup and project structure

Audience: MSc Economics students with little or no programming experience Environment: GitHub Codespaces (VS Code in the browser) Time per day: ~2.5 hours (including breaks and exercises) Goal by end of Day 3: Students write a small reusable Python module of macro tools, run it inside a proper virtual environment, and use it to pull the live Bank of Canada overnight rate.


How to use this guide

Each day is split into timed blocks. Every block follows the same rhythm:

  1. Concept: a short explanation in economic terms.
  2. Examples: several small, progressive code snippets. Type them yourself; don't copy-paste.
  3. Try it: a quick exercise. Solutions are hidden in collapsible blocks.

The economic numbers used here come from our course notebook (Macro_Fall_2026.ipynb) or are clearly marked illustrative. On Days 8–10 we will replace hard-coded numbers with live API data.

Target folder structure (built up over three days)

macro-data-course/
├── .gitignore
├── requirements.txt
├── day01/
│   ├── hello.py
│   ├── rates.py
│   └── snapshot.py
├── day02/
│   ├── stance.py
│   ├── loops.py
│   └── clean_boc.py
└── day03/
    ├── macrotools.py
    ├── analysis.py
    └── fetch_boc.py