Session 7: The workshop

Four papers, one toolkit — the step-by-step plan

Thierry Warin, PhD

HEC Montréal

Outline · The workshop

  1. The plan
  2. Part 0 · Set up
  3. Part 1 · Each paper, the same way

What session 7 is for

The mathematics

  • Choose which of the course’s models fits a new outcome — a number, a yes/no, ordered or unordered categories
  • Read every result as a sentence, in units, and say what it does not license
  • Compare OLS with ridge, the lasso and the elastic net on data the models did not see

The Python

  • Load a paper’s data into pandas straight from a web address
  • Run the code cells of sessions 3 to 5 on new data, changing only the variable names
  • Run a whole analysis as one script in VS Codium, step by step, in a folder of your own

The international business

  • Use international-business data from published papers
  • Explain a result to someone who will not read the code
  • Read a result the way a referee would, before trusting it

Your Python so far

Everything you need to type is on one sheet — how to start Python in VS Codium on your platform, how to make a file and run it, the DataFrame basics, and every name from sessions 1 to 7, each with a line showing it in use.

Python Cheatsheet · Session 07 (PDF) · in the repository at 07-…/PYTHON-CHEATSHEET.pdf

One sheet per package, functions explained with pictures: pandas · NumPy · matplotlib · statsmodels · scikit-learn

Print it, or keep it open beside the editor. Nothing on it is examinable; all of it is assumed.

The plan

Where everything is

The scripts run in a folder of your own; the guides stay in 07-replication-workshop/02-practice/:

README.md this plan, with every command to copy
check_setup.py Part 0: is everything in place? — in the scripts’ zip
r1_…py to r4_…py one script per paper, cut into numbered steps — each step a code cell from sessions 3 to 5; each reads its data from the course site
replications/R1-…md to replications/R4-…md one guide per paper: the same steps, and what you should see

Keep the guide open on one side of the screen and the script on the other.

The three hours

When Part Guide Script
0:00 – 0:15 0 · Set up — a folder of your own README.md, Part 0 check_setup.py
0:15 – 0:55 Paper 1 · news sentiment · OLS, the three logits R1-fraiberger-2021.md r1_fraiberger_2021.py
0:55 – 1:35 Paper 2 · social groups · binary, ordinal, multinomial logits R2-saganowski-2019.md r2_saganowski_2019.py
1:35 – 1:45 Break
1:45 – 2:15 Paper 3 · FDI · OLS, ridge, lasso, elastic net R3-blonigen-piger-2014.md r3_blonigen_piger_2014.py
2:15 – 3:00 Paper 4 · tariffs · OLS, the three logits, ridge, lasso, elastic net R4-topalova-khandelwal-2011.md r4_topalova_khandelwal_2011.py

Behind? Move on at the planned time. Three papers read well beat four rushed.

Part 0 · Set up

A folder of your own, fifteen minutes

Not the course repository: make an empty folder — Desktop/session-07 — and open it in VS Codium (File → Open Folder…). Then, in its terminal:

open /Applications/Python\ 3*/Install\ Certificates.command   # python.org Python only, once
python3 -m venv .venv
source .venv/bin/activate
pip install pandas statsmodels scikit-learn matplotlib
curl -LO https://warint.github.io/quantitative-methods/session-07-scripts.zip
unzip session-07-scripts.zip
python check_setup.py
python3 -m venv .venv
source .venv/bin/activate
pip install pandas statsmodels scikit-learn matplotlib
curl -LO https://warint.github.io/quantitative-methods/session-07-scripts.zip
unzip session-07-scripts.zip
python check_setup.py
py -m venv .venv
.venv\Scripts\Activate.ps1
pip install pandas statsmodels scikit-learn matplotlib
$zip = "https://warint.github.io/quantitative-methods/session-07-scripts.zip"
Invoke-WebRequest $zip -OutFile session-07-scripts.zip
Expand-Archive session-07-scripts.zip -DestinationPath .
python check_setup.py

Every line of check_setup.py says OK? Choose this folder’s .venv as the interpreter (Ctrl/Cmd + Shift + P → Python: Select Interpreter), then open r1_fraiberger_2021.py.

Part 1 · Each paper, the same way

Thirty to forty minutes per paper

Minutes Do In the guide
0 – 3 Know the data: what one row is, which variables The data
3 – 5 See which session’s code each step copies The models, and where the code comes from
5 – 25 Run the steps, one at a time, checking each against You should see Steps
25 – 30 Read each result as a sentence, with units Interpretation
26 – 30 Say what it does not license What this does not license

A number that differs from You should see is not a failure — it is a finding. Stop, and find out whether it is your data, your code, or the version of a package.

If you work as a team

Split and teach

  • Each person takes one or two papers
  • At 2:15: five minutes each — the data, the models, the results in words
  • Everyone then knows all four

Pairs at one screen

  • One types, one reads the guide aloud and checks the numbers
  • Swap at every paper

Every member runs at least one script on their own machine.