Instant PDF download, name-and-email checkout. Complete Book Bundle: every Economics, Statistics, Mathematics, Econometrics and Research Methods book
Econometrics

How to Run Your First Econometrics Computer Lab in Python, R or Stata (Even If Your Students Have Never Coded)

A practical guide to running your first econometrics lab in Python, R or Stata: a 60-minute plan, first regression code, common errors and fair assessment.

In 30 seconds
  • A first econometrics lab is where regression stops being algebra and becomes something students can do, check and explain.
  • Python, R and Stata all run the same OLS regression; pick the one your department can support, and use Google Colab if installation is the barrier.
  • Keep the first lab to one small dataset, one regression and one interpretation, inside a 60-minute plan with fixed timings.
  • Most first-lab failures are file paths, silent missing values, categories treated as numbers and default standard errors. Teach the fixes in advance.
  • Assess with a short write-up plus a script that runs from top to bottom, then progress to robust standard errors, dummies, IV and difference-in-differences.

You have a timetabled computer room, a class of thirty, and a scheme of work that says “Week 2: first regression lab”. Some of your students have written code before. Most have not. A few are quietly convinced they are “not computer people”. If the first session goes badly, the lab slot becomes an hour students dread all term.

This guide is for that first session, whether you teach a university first course or stretch strong A Level students with real data. It covers why labs matter, how to choose between Python, R and Stata, a timed 60-minute plan, the exact first regression to run in all three languages (with real output you can check), the errors you will see on the day, how to assess lab work fairly, and where to go next.

Econometrics Teacher Pack coverWant every week’s lab ready to run? Each chapter of the Econometrics Teacher Pack pairs a taught lesson with a computer-lab lesson, with Python code, R and Stata equivalents, and companion datasets.See the pack · $39

Why the econometrics lab matters in a first course

Econometrics is taught in two registers. In the lecture room it is algebra: the population regression function, the OLS estimator, the assumptions behind unbiasedness. In the lab it is a decision about which variables go into a model, a table of numbers on a screen and a sentence that has to say what those numbers mean. Students need both, but most only come to believe the theory once they have watched a coefficient change when they add a control variable themselves.

There is a wider argument too. Angrist and Pischke argue that applied econometrics has moved towards estimating specific causal effects and evaluating policy, while much undergraduate teaching still centres on abstract model-building and the classical assumptions[4]. A lab is the natural place to close that gap, because it is where students meet real data, real research designs and the practical question of whether a regression actually answers the question being asked. Their graduate-level companion, Mostly Harmless Econometrics, is built around exactly that empirical habit of mind[3].

Statistics educators make the same case. Two of the six recommendations in the American Statistical Association’s GAISE College Report are “Integrate real data with a context and purpose” and “Use technology to explore concepts and analyze data”[5]. An econometrics lab does both at once.

Key idea The aim of the first lab is not to teach programming. It is to show students that a regression is something they can run, read and explain in plain English. Everything else in the session should serve that single outcome.

Choosing Python, R or Stata (and when to use Google Colab)

All three tools estimate the same OLS regression and give the same coefficients, standard errors and R². The choice is about access, support and where your students are heading, not about which language is “best”. The two standard textbooks reflect this: Wooldridge’s Introductory Econometrics has data sets used widely with all three packages[1], and Stock and Watson’s Introduction to Econometrics is taught with each of them in different departments[2].

ToolStrengths for teachingWatch out forGood fit when
Python (pandas + statsmodels)Free; widely used in industry and data science; runs in a browser through Google Colab with no installationMore setup words (imports, data frames) before the first regression; several libraries to learnStudents may move into data, finance or technology roles; no licences available
R (base R, plus lmtest and sandwich later)Free; regression is one short line; strong for statistics and graphicsError messages can be cryptic; robust standard errors need extra packagesYour department already teaches statistics in R
StataShort, readable commands; robust standard errors are one option; very common in applied economics researchLicence cost; usually tied to lab machinesYour institution has site licences and students are heading to applied economics or policy work
Google Colab (Python in the browser)Zero installation; works on any laptop with a browser and a Google account; notebooks are easy to shareNeeds a reliable internet connection; uploaded files disappear when the session endsStudents use their own devices, or IT cannot install software in time
Teacher tip If you use Colab, put the data inside the first code cell for the first lab (as in the Python example below). That removes file uploads, file paths and lost files from the session entirely. Introduce reading a CSV file in the second lab, once students trust the environment.

A 60-minute plan for your first econometrics lab

The plan below assumes one hour, one small dataset, and students working in pairs at one machine. Pairs work well for a first lab: one types, one reads the instructions aloud, and they swap halfway. It also halves the number of machines you need to help.

TimePhaseWhat students doWhat you do
0–5 minHookAnswer one question on paper: “Does an extra year of education raise wages? By how much?”Take three guesses; write them on the board to return to at the end
5–15 minGet runningOpen the software or Colab; run a single line that prints “Hello” or 2 + 2Walk the room; fix logins and installs before any data appears
15–25 minMeet the dataEnter or load the 10-row dataset; print it; produce summary statistics and a scatter plotAsk: what is one observation? What are the units of each variable?
25–40 minFirst regressionRun the regression of wage on education; find the slope, its standard error, t and R² in the outputProject the output; annotate it live with the class
40–50 minInterpret and predictWrite one sentence interpreting the slope; predict the wage at 16 years of educationCheck sentences for units and the words “on average” and “associated with”
50–57 minStretch taskFaster pairs re-run with robust standard errors and compareSupport pairs still finishing the core task
57–60 minExit ticketAnswer: “What does the standard error of the slope tell you?”Collect and use the answers to plan the next lecture

The first ten minutes contain no econometrics on purpose: login and software problems are far easier to fix when nothing else is happening. If a pair is not running by minute 15, move them to Colab rather than debugging an installation in front of the class.

The first regression: one dataset, three languages

Use a dataset small enough to read on one screen. Ten rows is ideal for the first lab: students can see every observation, spot the pattern by eye, and check that the regression line fits what they see. Here is a made-up teaching dataset of ten workers, with years of education and hourly wage in dollars.

Workereduc (years)wage ($ per hour)
1108.20
2119.10
31210.40
4129.60
51311.80
61412.10
71413.50
81615.20
91614.00
101817.90

This is illustrative teaching data, not a real sample (mean education 13.6 years, mean wage $12.18).

Python (works in Google Colab as it stands)

import pandas as pd
import statsmodels.formula.api as smf

df = pd.DataFrame({
    "educ": [10, 11, 12, 12, 13, 14, 14, 16, 16, 18],
    "wage": [8.2, 9.1, 10.4, 9.6, 11.8, 12.1, 13.5, 15.2, 14.0, 17.9]
})
print(df.describe())

model = smf.ols("wage ~ educ", data=df).fit()
print(model.summary())

R

df <- data.frame(
  educ = c(10, 11, 12, 12, 13, 14, 14, 16, 16, 18),
  wage = c(8.2, 9.1, 10.4, 9.6, 11.8, 12.1, 13.5, 15.2, 14.0, 17.9)
)
summary(df)

model <- lm(wage ~ educ, data = df)
summary(model)

Stata

clear
input educ wage
10 8.2
11 9.1
12 10.4
12 9.6
13 11.8
14 12.1
14 13.5
16 15.2
16 14.0
18 17.9
end

summarize
regress wage educ

What the output says

We ran the Python code above on this dataset. The key lines of the statsmodels output are:

                 coef    std err          t      P>|t|
-------------------------------------------------------
Intercept     -3.9326      1.132     -3.476      0.008
educ           1.1848      0.082     14.455      0.000

R-squared: 0.963      No. Observations: 10

R and Stata report the same coefficients, standard errors, t statistics and R² (R shows “Multiple R-squared: 0.9631”; Stata shows “R-squared = 0.9631”). Here is how to walk students through each number.

OutputValueWhat to tell students
Slope coefficient on educ1.1848In this sample, each extra year of education is associated with an hourly wage about $1.18 higher, on average.
Intercept−3.9326The predicted wage at zero years of education. It is negative and meaningless here, because nobody in the data has fewer than 10 years. A good moment to discuss extrapolation.
Standard error of the slope0.082How much the slope estimate would vary from sample to sample. Smaller means a more precise estimate.
t statistic14.455The coefficient divided by its standard error (1.1848 / 0.0820 ≈ 14.46). It tests the null hypothesis that the true slope is zero.
p-value0.000 (shown rounded)Far below 0.05, so we reject the null of no relationship at any usual level. It is small, not exactly zero.
R²0.963About 96% of the variation in wages in this sample is explained by education. Real wage data give a much lower R², because many other things affect pay.
Classroom example Ask pairs to predict the wage of a worker with 16 years of education. Using the fitted line, wage = −3.9326 + 1.1848 × 16 ≈ $15.02 per hour. Then ask them to compare this with workers 8 and 9 in the table, who both have 16 years of education and earn $15.20 and $14.00. The gaps between actual and predicted values are the residuals, and students have just met them without being told the word.
Teacher tip Insist on the phrase “is associated with” in the first lab. It sets up the most important conversation of the course: why this regression does not show that education causes higher wages, and what kind of research design would. Ability, family background and many other factors are sitting in the error term.

Common student errors on the day, and how to fix them

Every lab produces the same handful of problems. If you name them before students meet them, they become routine rather than frightening. Put this table on a slide or print it on the back of the lab sheet.

ProblemWhat students seeFix in PythonFix in RFix in Stata
File path“File not found” or “cannot open file”Upload the file in Colab’s Files panel, or check the working folder with os.getcwd()Use getwd() and setwd(), or an RStudio projectUse pwd and cd, or open Stata by double-clicking a do-file in the data folder
Missing valuesFewer observations than expected, with no warningCheck the reported “No. Observations” and use df.isna().sum()Check the degrees of freedom line; use colSums(is.na(df))Check “Number of obs”; use misstable summarize
Category treated as a numberOne strange coefficient on a variable like region coded 1–4Write C(region) in the formulaConvert with factor(region)Use i.region in the regression
Default standard errorsOutput assumes constant error variance.fit(cov_type=”HC1″)coeftest(model, vcov = vcovHC(model, type = “HC1”)) with lmtest and sandwichregress wage educ, robust

Missing values deserve special attention, because the software does not stop: statsmodels, lm and regress all drop incomplete rows and report results on the smaller sample. Make “check N” a habit from the first week.

On robust standard errors, one detail catches teachers out. Stata’s robust option and Python’s HC1 use the same small-sample correction, but R’s sandwich package defaults to a different version (HC3) unless you ask for HC1. If students compare outputs across languages, tell them to specify type = “HC1” in R. On our ten-row dataset, the HC1 robust standard error of the slope is 0.073, compared with 0.082 for the default.

Common pitfall Running notebook cells out of order in Colab or Jupyter. A student defines df in cell 4, changes it in cell 2, and gets results nobody can reproduce. Teach “Runtime, then Restart and run all” before any work is handed in.

What is inside the Econometrics Teacher Pack

  • 20 chapters, each with two lesson plans: Lesson 1 is a taught class and Lesson 2 is a computer lab (40 lesson plans in all).
  • 473 editable slides, including Python code with real output and R and Stata equivalents.
  • Companion datasets and code to run in the lab.
  • 20 worksheets, 20 tests and 60 exit tickets, plus mid-year and end-of-year exams (80 marks each).
  • A 28-week, two-semester scheme of work mapped to Wooldridge (7th edn) and Stock and Watson (4th edn), plus a teacher guide and an 84-diagram bank.
  • A real published study in every chapter, such as Card and Krueger (1994), Angrist and Krueger (1991) and Duflo (2001), with the textbook (589 pages) and practice book (1,161 worked questions) included.

See the pack · Download the free sample

Assessing lab work: short write-ups and reproducibility

Lab work is easy to over-assess. A ten-page report for every session will exhaust you and teach students that labs are about formatting. A better model is a short write-up after each lab, marked against a small number of clear criteria, with the code handed in alongside it.

Here is a one-page template that works well from the first lab onwards.

SectionLengthWhat you look for
Question1–2 sentencesA clear economic question, for example “How is education related to hourly wages?”
Data2–3 sentencesWhat one observation is, the sample size actually used in the regression, and any missing values dropped
ResultsA small tableCoefficient, standard error, N and R², with units
Interpretation3–4 sentencesThe slope in plain English with units and “on average”; a comment on precision or significance
Limitation2 sentencesOne reason the estimate may not be causal, such as an omitted variable

Alongside the write-up, ask for the script (a .py file or notebook, an .R script, or a Stata do-file). The test of reproducibility is simple: you, or a classmate, can run it from top to bottom on a fresh session and get the same numbers as the write-up. Make this worth a small fixed share of the marks every week. It costs little to check, and it builds the single most useful professional habit in applied work.

Progressing from the first lab: robust SEs, dummies, IV and DiD

Once students can run and read one regression, every later lab adds one new idea to the same routine: load, check, regress, interpret, write up. The sequence below follows the order of most first courses built on Wooldridge or Stock and Watson[1][2].

StageNew ideaPythonRStata
Robust standard errorsInference that does not assume constant error variance.fit(cov_type=”HC1″)coeftest(model, vcov = vcovHC(model, type = “HC1”))regress y x, robust
Multiple regressionHolding other factors constant; omitted variable bias“wage ~ educ + exper”lm(wage ~ educ + exper, data = df)regress wage educ exper
Dummy variablesGroup differences and the base category“wage ~ educ + C(female)”lm(wage ~ educ + factor(female), data = df)regress wage educ i.female
Instrumental variablesUsing an instrument for an endogenous regressorIV2SLS.from_formula(“y ~ 1 + [x ~ z]”, df) in linearmodelsivreg(y ~ x | z, data = df) from the ivreg or AER packageivregress 2sls y (x = z), robust
Difference-in-differencesComparing changes for treated and control groups“y ~ treat * post”lm(y ~ treat * post, data = df)regress y i.treat##i.post, robust

The last two rows are where your course connects with real research. Instrumental variables can be taught with the quarter-of-birth design of Angrist and Krueger (1991); difference-in-differences comes alive with Card and Krueger’s (1994) study of the minimum wage in New Jersey and Pennsylvania fast-food restaurants. Both are discussed at length in Mostly Harmless Econometrics[3], which is a valuable reference for the teacher even if it is beyond most first-year students. Using real studies in the lab is a direct answer to Angrist and Pischke’s call for more research design and causal questions in undergraduate econometrics[4].

Key idea In the difference-in-differences regression y ~ treat * post, the coefficient on the interaction treat × post is the difference-in-differences estimate. Show students that it equals the change in the treated group’s mean minus the change in the control group’s mean, by computing the four group means by hand first.

How the Econometrics Teacher Pack’s Lesson 2 labs work

If you would rather not build every lab from scratch, this is what the Econometrics Teacher Pack is for. Each of its 20 chapters has two 60-minute lesson plans. Lesson 1 is a taught class that introduces the idea. Lesson 2 is a computer lab, where students apply that idea to data.

The slides for the labs include Python code with its real output, so you can show exactly what students should see on screen, together with R and Stata equivalents for departments that use those tools. Companion datasets and code are included, so the lab is ready to run rather than ready to adapt. Each chapter is built around a real published study, such as Card and Krueger (1994), Angrist and Krueger (1991) and Duflo (2001), which lets the lab follow the research-design approach discussed above.

Every document is editable Word or PowerPoint plus print-ready PDF, licensed for one teacher or one school department.

Complete Teacher Bundle coverTeach more than one subject? All five teacher packs and every book for $79 (was $219).Complete Teacher Bundle · $79

Your first econometrics lab does not need to be ambitious. One small dataset, one regression, one clear sentence of interpretation and a script that runs from top to bottom is a very good first hour. If you would like the rest of the term’s labs ready to go, take a look at the Econometrics Teacher Pack, or download the free sample first to see how the taught lessons and computer labs fit together.

Frequently asked questions

Do my students need to install anything for the first lab?

Not if you use Google Colab. Students need only a browser and a Google account, and the Python code in this post runs in a Colab notebook as it stands. If your computer room has R, RStudio or Stata installed, check that every machine opens the software before the session, ideally the day before.

Which language should I choose if I can only teach one?

Choose the one your department can support. Python suits students heading towards data and industry roles, R suits departments that already teach statistics in it, and Stata suits applied economics where licences are available. The econometrics is identical in all three, so students who learn one can move to another later.

I am not a confident coder. Can I still run an econometrics lab?

Yes. The first labs use a handful of commands, and you need to recognise the common errors far more than you need to write elegant code. Run the lab yourself from start to finish on a student machine beforehand, keep the error-fix table above to hand, and let confident students help their neighbours.

How long before students can run a regression on their own?

That varies with the group, but a sensible aim is for most pairs to load a dataset, run a regression and interpret the slope without help after a few labs, provided each lab repeats the same routine and adds only one new idea.

References

  1. Wooldridge, J. M. (2020) Introductory Econometrics: A Modern Approach, 7th edn. Boston, MA: Cengage. cengage.com
  2. Stock, J. H. and Watson, M. W. (2020) Introduction to Econometrics, 4th edn. New York: Pearson. pearson.com
  3. Angrist, J. D. and Pischke, J.-S. (2009) Mostly Harmless Econometrics: An Empiricist’s Companion. Princeton, NJ: Princeton University Press. doi.org/10.1515/9781400829828
  4. Angrist, J. D. and Pischke, J.-S. (2017) “Undergraduate Econometrics Instruction: Through Our Classes, Darkly”, Journal of Economic Perspectives, 31(2), pp. 125–144. doi.org/10.1257/jep.31.2.125
  5. GAISE College Report ASA Revision Committee (2016) Guidelines for Assessment and Instruction in Statistics Education College Report 2016. Alexandria, VA: American Statistical Association. amstat.org
Econometrics Made Simple Complete Bundle: textbook and practice book
This topic has a full chapter in Econometrics Made Simple, with Python, R and Stata code and 1,161 worked practice questions in the bundle.Econometrics Made Simple Complete Bundle — Textbook + 1,161 Practice Questions
Get it for $19
E

The EconTutorials team writes clear, exam-focused lessons in economics and statistics for A-Level, IB, AP and university students, with more than 13 years of classroom teaching behind every guide and book in the Made Simple series.