library(tidyverse)
library(plotly)
library(gapminder)
plot_thing <- gapminder |>
filter(year == 2007) |>
ggplot(aes(x = gdpPercap, y = lifeExp, color = continent)) +
geom_point(aes(text = country)) + # text is a special aesthetic for plotly labels
scale_x_log10()
ggplotly(plot_thing)Regression discontinuity I
Readings
- Chapter 6 in Impact Evaluation in Practice (Gertler et al. 2016)
- Chapter 20 in The Effect (Huntington-Klein 2021)
Regression discontinuity
- The example page on regression discontinuity shows how to use R to analyze and estimate causal effects with regression discontinuity
Slides
The slides for today’s lesson are available online as an HTML file. Use the buttons below to open the slides either as an interactive website or as a static PDF (for printing or storing for later). You can also click in the slides below and navigate through them with your left and right arrow keys.
Fun fact: If you type ? (or shift + /) while going through the slides, you can see a list of special slide-specific commands.
Videos
Videos for each section of the lecture are available at this YouTube playlist.
- Introduction
- Arbitrary cutoffs and causal inference
- Drawing lines and measuring gaps
- Main RDD concerns
You can also watch the playlist (and skip around to different sections) here:
In-class stuff
Here are all the materials we’ll use in class:
Quarto website resources:
- Workshop on creating Quarto websites
- Creating a website
- Bootswatch themes
- Publishing with Posit Cloud Connect (see this too)
- Publishing with Netlify Drop
- Publishing with GitHub Pages
Examples:
- This class website :)
- My website (
source) - Project-specific websites:
- Interactive illustration website things: https://www.andrewheiss.com/teaching/
- Other websites:
Other Quarto things
- Citations
- Cross references
- Layout options
- Callouts
- Interactivity
- Plotly and
ggplotly() - Dashboards
- Observable JS + Observable Plot (like ggplot for Javascript)
- Examples:
- Plotly and
ggplotly() example:
OJS example:
This is R code!
# Make the gapminder data available to Observable JS
ojs_define(gapminder = gapminder)This is NOT R code! This is Observable JS code!
viewof current_year = Inputs.range(
[1952, 2007],
{value: 1952, step: 5, label: "Year:"}
)
// Rotate the data so that it works with OJS
gapminder_js = transpose(gapminder)
// Filter the data based on the selected year
gapminder_filtered = gapminder_js.filter(d => d.year == current_year)
// Plot this thing
Plot.plot({
x: {type: "log"},
marks: [
Plot.dot(gapminder_filtered, {
x: "gdpPercap", y: "lifeExp", fill: "continent", r: 6,
channels: {
Country: d => d.country
},
tip: true
}
)
]}
)