ImpactMojo ImpactMojo
Browse Premium
Back to Labs
Interactive Course · Live code

R & Python for Development

A South Asia 101 — learn to code from absolute zero, with real R and Python running live in your browser. No installation, works on a modest laptop.

How the live code works. The first time you Run R or Python, your browser downloads the language engine once (R ≈ 7 MB, Python ≈ 10 MB; later modules fetch a package or two more). Give the first click 10–30 seconds; after that it's quick. A shared dataset (SURVEY_CSV) is loaded for you when the engine starts, so every code cell can use it.
Module 1 of 7

Your first line of code

Two languages run most development-sector data work: R (loved by statisticians and evaluators) and Python (loved by data scientists). You don't have to choose — this course teaches both, side by side. Click Run, then switch the tab from R to Python and Run again.

editable

        

A first calculation

Store five people's ages and compute the average. In R a list of numbers is c(...) and the mean is mean(...); in Python it's a list [...] and sum(...) / len(...).

editable

        
That's 80% of analysis: data goes into a variable, a function does something to it, you read the result.
Module 2 of 7

Data in, data out

Real analysis starts with a dataset — rows (people, households) and columns (variables). We've loaded a small illustrative household-survey sample into SURVEY_CSV for you. Illustrative data

Read it into a data frame — a spreadsheet-like table. In R, read.csv(text = SURVEY_CSV); in Python, pandas. Then peek at the first rows and the shape.

first Python run loads pandas

        

Look at one column

Columns are accessed by name: df$pc_exp in R, df["pc_exp"] in Python. Let's summarise monthly per-capita expenditure.

editable

        
In the field you'll read NFHS, ASER, PLFS or your own survey the same way — from a .csv file with read.csv("mydata.csv") or pd.read_csv("mydata.csv").
Module 3 of 7

Wrangling — filter and select

Most data work is reshaping: keep some rows, keep some columns. Say we want only rural households. In R (base) we index with a condition; in Python we use pandas.

editable

        

Add a new column

Flag "low expenditure" households (below ₹1,500/month). Assign a new column and count how many.

editable

        
Once you're comfortable, R's tidyverse (dplyr) and Python's pandas chaining make this even cleaner: df |> filter(area=="Rural") / df.query('area=="Rural"'). Same idea, nicer grammar. (Our Code Convert Pro tool translates between them.)
Module 4 of 7

Summaries & disaggregation

An average hides as much as it reveals. The real story is in the disaggregation — the same number split by gender, caste, or geography. (This is exactly the lens of the Data Feminism Lab.)

Mean expenditure by gender, then by gender × caste:

editable

        
Read the gaps. A single "average expenditure" number would erase the gap between, say, General-caste and SC/ST households, and between men and women within each group. Disaggregation is where inequality becomes visible.
Module 5 of 7

Your first chart

A picture makes a gap obvious. We'll draw a bar chart of mean expenditure by caste. In Python we use matplotlib and call show() (a helper we've provided) to display it; in R we use base barplot().

First run of this module downloads the plotting library (a few MB more). The chart appears below the code.
draws an image

        
The production-grade tools are R's ggplot2 and Python's matplotlib/seaborn. For design principles, see the Data Visualization 101.
Module 6 of 7

Regression & the idea of impact

A regression asks: as one thing changes, how does another move? Here — does an extra year of education go with higher expenditure? In R, lm(y ~ x); in Python, numpy.polyfit for the same slope.

editable

        

From correlation to impact

That slope is a correlation, not proof that education causes higher spending. Impact evaluation isolates cause — e.g. difference-in-differences compares the change in a treated group to the change in a comparison group. A tiny illustration: Illustrative

editable

        
Go deeper in the Causal Inference for Development course and Impact Evaluation 101. A great open text with R/Python/Stata code: Martin Huber, Causal Analysis (MIT Press).
Module 7 of 7

Reproducibility & sharing

Analysis you can't re-run is analysis nobody can trust. The habit: put your steps in a script, comment it, and share the script + data so anyone can reproduce your numbers. Here's the whole pipeline from this course in one runnable cell.

the full pipeline

        

You can now code with data

From "hello" to reading a survey, wrangling it, disaggregating, charting, and running a regression — in both R and Python, entirely in your browser.

RPythontidyverse / pandasWebR + PyodideNo install

Where to go next

Econometrics 101

Put the regression to work on real questions.

Data Feminism Lab

The ethics and power of disaggregation.

Code Convert Pro

Translate your code between R, Python, Stata and SPSS.

Sampling Toolkit

Design the survey your code will analyse.