Difference-in-differences II

Content for Thursday, March 13, 2025

Readings

This session is a continuation of session 8.

In-class stuff

Here are all the materials we’ll use in class:

LLMs

Text-generation Markov chains with R:

LLMs that work well with code:

  • Claude (run by Anthropic, based in the US)
  • DeepSeek (run by DeepSeek, based in China—see this and this)
  • ChatGPT, but through GitHub Copilot (run by OpenAI, based in the US)

GitHub Copilot:

Quarto websites

Resources:

Examples:

Other Quarto things

ggplotly() example:

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)

OJS example:

R

This is R code!

# Make the gapminder data available to Observable JS
ojs_define(gapminder = gapminder)
Observable

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
      }
    )
  ]}
)