Setup Guide: Software for the Tutorials

Before You Begin

Lecture 1 explains why we work inside a project environment. This guide gives the commands that set one up. Work through it once, before the first tutorial, on the machine you will use all term.

Master’s track Language Follow
Economics R The R Route
Entrepreneurship R The R Route
Finance Python The Python Route

Installation is the one part of this course that can fail for reasons that have nothing to do with econometrics. Do it before the tutorial, not during it. If something breaks, note the exact error message: it is almost always enough to find the answer.

TipRead the Other Half Later

Everything here has a counterpart in the other language. Once your own setup works, skimming the other route shows you how the same ideas are expressed elsewhere.

The R Route

Step 1: Install R, Then RStudio

Install R first. R is the language itself. Then install RStudio Desktop, which is the editor you work in.

The order matters: RStudio looks for an R installation when it first starts. Once both are installed, open RStudio and check the Console, which prints the R version at startup.

ImportantTwo Separate Programs

Installing RStudio does not install R. If RStudio reports that it cannot find an R installation, R itself is missing.

Step 2: Install the Course Packages

Run this once, in the RStudio Console:

install.packages(c("tidyverse", "here"))

install.packages() downloads from CRAN and copies the package onto your disk. You never need to run it again for that package on that machine. Installing can take a few minutes, since the tidyverse is many packages at once.

Load them at the start of every session:

library(tidyverse)
library(here)

The distinction matters:

  • install.packages() is buying the book. It is permanent.
  • library() is taking it off the shelf and opening it.

A fresh R session starts with an empty shelf, which is why every script begins with its library() calls.

WarningA Common Error
Error in library(tidyverse) : there is no package called 'tidyverse'

means the package was never installed. Run install.packages("tidyverse") once, then library(tidyverse) again.

The :: Notation

here::here() means: the function here() from the package here. You will see this notation constantly, including throughout this site, because it works without loading the package first.

# These two are equivalent, given that here has been installed:
library(here)
here("data", "raw")

here::here("data", "raw")

Use :: when you want to be explicit about where a function comes from.

When Two Packages Share a Name

Loading the tidyverse prints a message like:

── Conflicts ──────────────────────────────────
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()

This is not an error. It is a notification. Both dplyr and stats define a function called filter(), and the package loaded most recently wins, so plain filter() now means dplyr::filter(). That is what we want in this course.

TipResolving a Conflict

If a function behaves unexpectedly, name it explicitly: dplyr::filter() or stats::filter().

Step 3: Create an RStudio Project

An RStudio Project is a folder with an .Rproj file in it. Opening that file sets R’s working directory to the project folder, which is what makes paths work on any machine.

In RStudio: File → New Project → New Directory → New Project, then give it a name.

empirical_economics/
├── empirical_economics.Rproj
├── data/
│   ├── raw/
│   └── processed/
├── code/
└── output/

Always open the project by double-clicking the .Rproj file, not by opening a loose script.

Inside a project, here() builds paths from the project root:

library(here)

macro <- read_csv(here("data", "raw", "macro.csv"))

The same line works on Windows, macOS, and Linux, and in the exam environment.

ImportantNever Use setwd()

setwd("C:/Users/yourname/Documents/...") hard-codes a path that exists only on your computer. Nobody else, including a grader, can run that script.

Step 4 (Optional): renv for Reproducibility

install.packages() puts packages in one shared library for your whole machine, so updating a package for one project changes every project. renv gives a project its own private library instead.

install.packages("renv")

renv::init()      # give this project its own library
renv::snapshot()  # record exact versions in renv.lock
renv::restore()   # rebuild that library on another machine

This is not required for the course, but it is the R answer to the same problem uv solves in Python.

R Setup Checklist

Open RStudio through your .Rproj file and run:

library(tidyverse)
library(here)

here()                    # should print your project folder
mean(c(2, 4, 6))          # should print 4

If all of these run without error, your R setup is complete.

The Python Route

Step 1: Install uv

Python by itself does not manage projects: you need a tool that installs packages and keeps them separate per project. uv does both, and it can install Python itself, so it is the only thing you install by hand.

# macOS and Linux (in a terminal)
curl -LsSf https://astral.sh/uv/install.sh | sh

# Windows (in PowerShell)
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"

Close the terminal, open a new one, and confirm:

uv --version

See the uv installation page if the command is not found.

Step 2: Install VS Code

Install VS Code, then install Microsoft’s Python extension from the Extensions panel. VS Code is a general-purpose editor; the extension is what makes it a Python environment.

NoteYou Do Not Need to Install Python Separately

uv will download and manage the Python interpreter for your project in the next step.

Step 3: Create a Project Environment

A virtual environment is a folder holding one project’s Python interpreter and its packages. Give every project its own, so an update for one project cannot break another.

Open a terminal in your project folder and run:

uv init          # writes pyproject.toml and .python-version
uv venv          # creates the environment in .venv/

pyproject.toml records which packages the project needs; .venv/ holds the packages themselves.

empirical_economics/
├── pyproject.toml
├── uv.lock
├── .venv/
├── data/
│   ├── raw/
│   └── processed/
├── code/
└── output/

Step 4: Add the Course Packages

# Add packages to this project:
uv add pandas statsmodels matplotlib requests

# Remove one again:
uv remove matplotlib

# Recreate the environment on another machine:
uv sync

uv add installs the package and records it in pyproject.toml, with the exact version pinned in uv.lock. uv sync reads those two files and reproduces the same environment elsewhere.

To run a script without activating anything, prefix the command with uv run:

uv run python analysis.py

Step 5: Point VS Code at Your Environment

  • Open your project folder in VS Code: File → Open Folder.
  • Run Python: Select Interpreter from the Command Palette (Ctrl+Shift+P, or Cmd+Shift+P on macOS).
  • Choose the interpreter inside .venv.
TipCheck the Interpreter First

If code works in a terminal but VS Code says a package is missing, the editor is almost certainly using a different Python interpreter. This is the single most common Python setup problem.

NoteActivating in a Plain Terminal

source .venv/bin/activate on macOS and Linux, or .venv\Scripts\activate on Windows, makes python refer to the project’s interpreter for the rest of that terminal session.

Python Setup Checklist

With your project folder open in VS Code and the .venv interpreter selected, run:

import pandas as pd

pd.Series([2, 4, 6]).mean()   # should print 4.0
pd.__version__

If both lines run without error, your Python setup is complete.

Reference

The Two Routes Side by Side

Task R Python
Install a package install.packages("x") uv add x
Load it in a script library(x) import x
Project marker project.Rproj pyproject.toml
Build a path here("data", "raw") Path("data") / "raw"
Pin versions renv::snapshot() uv.lock (automatic)
Rebuild elsewhere renv::restore() uv sync

The commands differ; the problems they solve are identical.

If Something Goes Wrong

Read the exact error message and search for it. Most setup errors are common and well documented. Then check the obvious:

  • Did you open the project (the .Rproj file, or the folder in VS Code)?
  • Did you install the package, and is this a fresh session that needs library() or import?
  • Is VS Code using the interpreter inside .venv?

Bring the error message to the tutorial. A screenshot of the message is worth more than a description of it.

Where to Read More