DATETHU AUG 13
TIME1-4 PM
FORMATLESSON + LAB

CODING LESSON 1

Meet the evidence.

Learn what R, an LLM, a coding agent, and its harness actually do—then use each one without surrendering the policy question.

OPEN LAB 1 →OPEN SLIDES ↗

THE FIRST QUESTION

What, exactly, does the file contain?

A policy analysis can fail long before a model is fitted. It can fail when a row is misread, when an aggregate is mistaken for a country, when a missing value is treated as zero, or when two indicators that sound similar are assumed to measure the same thing. Lesson 1 begins with those decisions because they determine what every later graph and coefficient can mean.

The shared file follows countries and economies over time. That sounds straightforward, but the phrase “country-year data” still leaves important questions open. Which geographic units are included? Is every country observed in every year? Were the indicators collected in the same way? Does a higher number always mean more of the underlying concept? The code can count rows and summarize values. It cannot answer those interpretive questions without definitions and source documentation.

We will work toward five practical abilities: distinguish the tools in the project, run and read a short R script, identify the unit and key of a dataset, inspect coverage and missingness, and verify an explanation produced by a coding agent. These are modest operations, but together they create a defensible first account of the evidence. They also give students with very different coding histories a common language for asking for help without handing away the analysis.

The lesson uses one of four international development questions as a thread. You may examine health and income, girls’ secondary enrollment and adolescent fertility, electricity and internet access, or renewable electricity and carbon intensity. At this stage the question is descriptive or associational. We are learning what can be compared, not claiming that one variable causes another.

R, AI, AND THE WORKSPACE

The tools are connected, but they do different work.

R is the programming language that executes the instructions in our scripts. When R reads a file, filters rows, or calculates a mean, it performs a specified operation and returns a result. RStudio is the workspace around R: it gives us an editor, console, file browser, plots, and help. RStudio makes the work easier to see, but it does not change what the R code means.

Quarto combines narrative, code, figures, and output in a document that can be rendered again when the analysis changes. It will be available throughout camp because it is useful for slides and reproducible notes, not because every student must submit a polished report. A plain R script remains a perfectly good place to think.

Is it still worth learning to code?

Yes, but the target is changing. Andrew Ng argues that coding plus prompting can accomplish more than prompting alone: natural language makes it easier to begin, while code makes important instructions inspectable, repeatable, and testable. AI-assisted coding also lowers the cost of trying a small idea, seeing what breaks, and improving it. That makes building a faster route into learning rather than a reason to avoid learning.

For this camp, “learning to code” does not mean competing with an agent at recalling syntax. It means learning enough to read a proposal, predict what should happen, change the relevant part, test the result, and recognize when the code no longer matches the policy question. The 2024 Math Camp promised that students would leave ready for the semester, know enough R, and know how to craft questions and where to look for answers. We keep that promise and add one expectation: use help without surrendering judgment.

THE DESTINATION

You should leave ready to move in R, ask a useful question, find appropriate help, and make a defensible decision about what to keep. Independence does not mean working without help; it means retaining independence of judgment.

Artificial intelligence is the umbrella term. A large language model, or LLM, is one kind of AI: a system that generates language or code from an instruction and the context placed in front of it. It is helpful to imagine an unusually capable language engine. It can continue a pattern, explain a function, or draft R code, but the engine itself does not open a file, run R, browse documentation, or know whether a policy claim is true.

A chat interface puts a conversation window around that engine. A coding agent adds a loop and tools: inspect the project, request a file read or terminal command, observe the result, and decide what to do next. The system that assembles context, offers tools, enforces permissions, returns tool results, preserves history, and decides when the loop stops is often called the harness.

THE WORKSHOP ANALOGY

The LLM is the language engine. The harness is the workshop around it: workbench, toolbox, clipboard, locked cabinets, and measuring instruments. The coding agent is the engine operating inside that workshop. You are the investigator who writes the work order, grants access, watches the work, and decides whether the evidence supports keeping it.

MODELGenerates.

Produces text, code, or a request to use a tool.

HARNESSConnects.

Supplies context, tools, permissions, memory, and feedback.

AGENTActs in a loop.

Reads, proposes, runs, observes, and continues within its access.

INVESTIGATORJudges.

Frames the question and decides what counts as verification.

Codex is the baseline coding agent for Math Camp; Claude Code can be used as an alternative. These are product names, not names for one fixed model. A product may change models or interfaces while keeping a familiar project workflow. That is why we will spend less time comparing brands and more time inspecting context, tools, permissions, changes, and checks.

This is why the camp moves beyond a closed RStudio demonstration. Contemporary quantitative work increasingly takes place across scripts, documents, terminals, version histories, and AI-assisted tools. Learning to supervise that environment is now part of computational literacy. It does not replace knowing what a row means or how a transformation works. It makes those forms of knowledge more important because an agent can reproduce a mistake across an entire project very quickly.

ToolIts role in this lessonThe judgment it cannot make for us
RRead, count, transform, and summarize observations.Whether the policy question is well framed.
RStudioMake scripts, objects, files, and output visible together.Whether the code represents the intended population.
QuartoKeep prose, code, and results in a reproducible document.Whether a claim follows from the research design.
Codex or Claude CodeExplain project code and perform bounded, reviewable tasks.Whether its answer deserves our trust.

Watch one tool-call loop

When an agent “reads a file,” the LLM does not reach into the computer. It produces a structured request such as “read this path.” The harness checks whether that tool and path are allowed, executes ordinary software, and sends the result back into the next model round. The same sequence applies to editing a file or running an R script. This gives us four points of supervision: the context provided, the action requested, the result returned, and the decision to continue.

Class simulation. One student plays the model, one plays the harness, one plays the R tool, and one plays the investigator. The “model” may only write a tool request. The “harness” decides whether it is permitted and carries the request to “R.” The investigator compares the returned result with the original question. The point is to make the invisible loop visible before anyone trusts it.

READING THE FILE

Begin with structure, coverage, and scale.

The first two hours move from the project as a whole to a small set of questions about the data. We will locate the script and data directories, distinguish code written in a source file from commands run in the console, and use assignment to create an R object. We will then inspect the object before selecting a policy track. The final hour is Lab 1, where temporary working groups build an evidence inventory and compare what they found.

Orient

Projects, paths, scripts, the console, and the environment.

Read R

Objects, functions, arguments, assignment, and pipes through a small example.

Inspect

Rows, variables, types, keys, ranges, years, and missing values.

Question

Choose a policy track and connect its concepts to documented variables.

Lab 1

Construct and review the evidence inventory.

The following script is our first pass. All object and function names use R’s usual lowercase style. Open the project itself before running the code so that the relative path begins in the project directory.

RFirst look at the teaching file
library(tidyverse)

wdi <- read_csv(
  "data/derived/math-camp-wdi-2000-2022.csv",
  show_col_types = FALSE
)

glimpse(wdi)
count(wdi, year)
summarise(wdi, economies = n_distinct(iso3c))

library(tidyverse) makes a collection of R packages available in the current session. In this script we need readr to read the comma-separated file and dplyr to count and summarize observations.

wdi <- read_csv(...) reads the named CSV file and assigns the resulting table to an object called wdi. The arrow points toward the object being created. Setting show_col_types = FALSE suppresses an informational message; it does not change the data.

glimpse(wdi) gives a compact view of the number of rows and columns, each column’s data type, and a few values. This is where we notice whether a year was read as a number, whether an indicator is numeric, and whether the identifiers look as expected.

count(wdi, year) groups the rows by year and reports how many appear in each group. Uneven counts are not automatically errors, but they tell us that year coverage needs an explanation.

summarise(wdi, economies = n_distinct(iso3c)) returns one number: the count of distinct economy identifiers. It does not tell us that every identifier is a sovereign country, so we still consult the documentation and inspect aggregate codes.

From here we add checks that follow from the substantive question. We count missing observations for the selected indicators, inspect minimum and maximum values in their documented units, and test whether iso3c together with year uniquely identifies a row. A surprising result is an invitation to investigate. It is not a reason to delete an observation until the source and definition justify doing so.

WORKING WITH AN AGENT

Ask for a claim you can check.

Our first agent conversation is deliberately narrow and read-only. We are not asking the agent to select the policy question, write the entire analysis, or reassure us that the data are clean. We are asking it to read a small piece of public project context and explain what it finds. A useful work order names the goal, points to the relevant files, sets boundaries, and describes what a satisfactory response would contain.

A bounded request
Explain the R inspection block in Lesson 1.

Read the script and the indicator dictionary in this project. Do not edit files.
For each line, describe the object or function, what result it returns, and which
claim about the dataset that result can support. Separate facts visible in the
files from interpretations. If the files do not establish something, say so.

Finish with three R checks I can run myself: one for the country-year key, one
for year coverage, and one for missing values in a selected indicator.

After reading the response, choose one numerical or structural statement and reproduce the supporting check in R. If the agent says that the file contains one row per country-year, run the uniqueness test. If it describes a variable’s unit, compare that description with the indicator dictionary. If it gives a row count, recreate the count rather than treating the response as a source.

PassQuestionVisible record
PredictWhat do I expect before asking?One sentence or sketched output.
DelegateWhat bounded action may the agent take?Goal, context, constraints, done when.
ObserveWhat did the harness read, run, or change?Tool calls, output, or diff.
VerifyWhich independent check bears on the claim?R result, documentation, or source.
NarrateWhat do I accept, revise, reject, or leave open?One judgment with evidence.

The most useful outcome is not always confirmation. A contradiction may reveal that the prompt was vague, that the agent read the wrong file, or that our own assumption was unsupported. An unresolved statement is also informative when we can name the external documentation or additional code required to settle it. Verification turns the agent response from an answer into evidence that can be examined.

Privacy and responsibility remain with the analyst. The camp project uses public teaching data. Restricted, identifiable, or confidential data should not be placed into a public AI tool. Proposed edits should be reviewed before they are kept, commands should be run in the intended project, and every result that enters the analysis remains the responsibility of the person presenting it.

SLIDES

Lesson deck.

The embedded deck is generated from slides/lesson-1/slides.qmd. Re-rendering that file replaces the deck without changing this page.

LESSON 1 / REVEALJSOPEN FULL SCREEN ↗