Coding Lesson 2 · Math Camp 2026
ARRIVAL PROMPT
If two analysts download “the same” public indicator one year apart, should their files be identical?
Choose yes, no, or “it depends.” Write the reason that would most affect your trust.
2 MINUTES
WED AUG 19 · 3-5 PM
Follow one public indicator from source to analysis table, then supervise an agent-assisted update without erasing the trail.
dplyr verbs with a purpose.iso3c + year key.Your inventory named:
Today we ask a harder question: How did those columns get into this file?
Exact download or API response.
Cleaned, reshaped, and joined tables.
Variables and sample for one question.
Figures, tables, models, and reports.
Imagine the raw download as evidence arriving in a sealed bag.
Put these actions in order:
Where should the key test appear more than once?
The teaching file ends in 2022 so everyone begins from one reference point.
A later World Bank release may:
One country-year per row. Indicators are columns.
Useful for a focused analysis.
One country-year-indicator per row.
Useful for comparing indicators or reshaping.
Tidy is not the same as complete, correct, or analysis-ready.
| Type | Example | Risk |
|---|---|---|
| Character | "KEN" |
spelling and whitespace |
| Numeric | 72.4 |
units and impossible ranges |
| Integer | 2022 |
accidental arithmetic |
| Logical | TRUE |
unclear construction rule |
| Missing | NA |
silent row loss |
| Verb | Question |
|---|---|
select() |
Which variables belong here? |
filter() |
Which observations belong here? |
mutate() |
What new variable am I defining? |
arrange() |
In what order should I inspect rows? |
group_by() |
Within which groups do I compare? |
summarise() |
Which aggregate answers my question? |
Name the first verb you would use for each task. More than one pipeline can be reasonable.
health <- wdi |>
select(
iso3c, country, year, income_level,
gdp_per_capita_ppp, under5_mortality
) |>
filter(year >= 2000) |>
mutate(log_income = log(gdp_per_capita_ppp))Every line should correspond to a sentence you can defend.
The source file has 4,991 rows.
After select(), filter(year >= 2000), and mutate(), how many rows should health have?
This assertion says: no economy appears more than once in the same year.
If it fails, stop before joining or summarizing.
| iso3c | region |
|---|---|
| KEN | SSA |
| KEN | Africa |
| iso3c | year | value |
|---|---|---|
| KEN | 2022 | 39 |
What happens when we join by iso3c?
Before a join, state:
duplicates <- country_metadata |>
count(iso3c) |>
filter(n > 1)
unmatched <- health |>
anti_join(country_metadata, by = "iso3c")anti_join() is a question: which rows have no match?
health |>
group_by(year) |>
summarise(
observed = sum(!is.na(under5_mortality)),
missing = sum(is.na(under5_mortality)),
.groups = "drop"
)Coverage can change across time and indicators.
The model uses only rows observed on both variables.
Which two row counts should you compare before interpreting the result?
health <- health |>
mutate(
analysis_sample =
!is.na(under5_mortality) &
!is.na(log_income)
)
count(health, analysis_sample)Named sample rules are easier to inspect than hidden filters.
For your policy track:
8 MINUTES
| Friendly name | Official code |
|---|---|
| GDP per capita, PPP | NY.GDP.PCAP.PP.KD |
| Under-five mortality | SH.DYN.MORT |
| Female secondary enrollment | SE.SEC.ENRR.FE |
| Internet use | IT.NET.USER.ZS |
A friendly label can hide a different unit or denominator.
Complete a precise sentence:
We use [indicator name and code], published by [source], measured in [unit], for [economies and years], retrieved on [date], and transformed by [script].
4 MINUTES
An agent can help:
It must not silently overwrite the frozen baseline.
Recover the existing pipeline. No edits.
Name sources, files, risks, and checks.
Create a new dated output. Protect the baseline.
Produce a receipt for additions, revisions, and failures.
At which rung would you stop if the indicator definition changed?
What evidence would you need before continuing?
Update the dataset to 2025.
Problems:
Goal: Extend one named WDI indicator beyond 2022.
Context: Read the build script and indicator dictionary.
Constraints: Use the official API. Do not overwrite the frozen files.
Preserve the indicator code and unit. Record the retrieval date.
Done when: A new dated file exists, country-year keys are unique,
and a comparison reports new rows, latest year, missingness,
and changed historical values.When the agent proposes code, inspect:
Do not confuse syntactic readability with source validity.
| Check | Question |
|---|---|
| New rows | Which country-years were added? |
| Revised rows | Which historical values changed? |
| Coverage | Which countries remain missing? |
| Latest year | Does it vary by indicator or country? |
| Metadata | Did names, units, or definitions change? |
In pairs, review the update contract and add:
6 MINUTES
For each agent round, record:
THU AUG 20 · 4-5 PM
You will supervise an update for one indicator and leave with:
Write one sentence for each:
3 MINUTES
API 209 · MATH CAMP 2026 · LESSON 2