Exercises in R

This section has link to the files for the demos and replication exercises that we will do in class. Here, you will find link to files with annotated code and csv files with data for the replication exercises.

Wednesday 2/5

Creating and Analyzing DAGs in ggdag (or Daggity).

Monday 2/20

Matching demo in R. I couldn’t figure out a cute way for you to be able to download this directly as a RMarkdown file (thwarted by quarto…). But this link will take you to the page in the course’s GitHub repository where the RMarkdown file is stored. Click on “Raw,” then you can copy and paste the code into an RMarkdown on your computer.

Wednesday 2/22

Matching demo with simulated data

Matching and Weighting replication exercise

In this replication exercise, you will use a subset of the data in the data folder found in the above link; the data is from Siegel et al. 2022 to play around with matching and weighting using a real dataset. On the Github, there are two csv files of data: colo_dat_full.csv and colo_data_for_matching.csv. colo_dat_full.csv has the entire time series of data for the full (unmatched) dataset of federal and private forests in Colorado. colo_data_for_matching.csv is a file that’s ready for the matching process without additional pre-processing: it has a row for each sample point in Colorado and five-year averages for the climate variables.

Monday 2/27

Diff-in-Diff regression demo in R Application and interpretation of differences-in-differences to examine effects of the Marshall Fire on vegetation in Boulder, CO. Data file is on GDrive.

Optional: Review of difference-in-difference covered in lecture in RMarkdown, see here

Monday 3/6

Panel regression demo in R This tutorial replicates the main analyses in Dee et al, contrasted with common approaches in ecology (mixed effect models and conditioning on observable covariates. For the rest of the supplemental analyses in Dee et al, see L.Dee’s GitHub

Wednesday 3/15

Instrumental variables demo in R. Link to an RMarkdown file that walks through the process of coding an analysis using an instrumental variable.

Wednesday 3/22

Regression discontinuity design demo in R. Link to an RMarkdown file that walks through the process of coding an analysis using regression discontinuity analysis.

Extra Code Resources - Optional Exercises and Examples

Intro: Data Don’t Speak

Code An example of from the online book, Causal inference in R Ch 5, that demonstrates that summary statistics and data visualization are insufficient to untangle causal effects. Instead, prior knowledge, theory, and assumptions are necessary.

Fun with spurious correlations & AI-generated explanations

Spurious correlations

The Potential Outcomes Framework helps clarify the estamind: what effect we are capturing.

Comparing different estimands - ATE, ATT versus ATU

Andrew Heiss has a great breakdown here

Measurement Error Creates Bias

code demo here

Bootstrapping standard errors for propensity score matching

Andrew Heiss has code and an example here