--- title: "Exercise template for 'Causal inference'" author: Your name format: html --- ```{r} #| message: false #| include: false library(dplyr, warn.conflicts = FALSE) library(ggplot2) library(modelsummary) if (knitr::is_latex_output()) { knitr::knit_meta_add(list(rmarkdown::latex_dependency("float"))) } ``` ## Econometrics The [book's simulation](https://iangow.github.io/far_book/causal-inf.html#econometrics-a-brief-illustration) supplies the starting data and models. Here $y_i$ is `income`, $x_{i1}$ is `education`, $x_{i2}$ is `industry` (industriousness), and $x_{i3}$ is `intelligence`. ```{r} #| include: false set.seed(2021) n <- 100000 df <- tibble( industry = rnorm(n), intelligence = rnorm(n), education = 3 * intelligence + 4 * industry + rnorm(n), income = 10 + 5 * education + 6 * intelligence + 7 * industry + rnorm(n)) ``` ```{r} #| include: false fms <- list(lm(income ~ education, data = df), lm(income ~ education + industry + intelligence, data = df), lm(income ~ industry + intelligence, data = df)) ``` ```{r} #| message: false #| echo: false #| tbl-cap: Income regressed on education and other variables #| label: tbl-income #| tbl-pos: H modelsummary(fms, estimate = "{estimate}", statistic = NULL, gof_map = c("nobs", "r.squared")) ``` ### Exercises 1. Looking at the simulation code, what are the true values of $\beta := \left(\beta_0, \beta_1, \beta_2, \beta_3 \right)$ and $\alpha := \left(\alpha_0, \alpha_2, \alpha_3 \right)$? 2. Do any of the three equations reported in @tbl-income provide good estimates of $\beta$? 3. Consider regression (3) in @tbl-income. With regard to the first of the two equations, are there any issues with regard to estimating $\beta$? What (if any) OLS assumption is violated? 4. What happens if you substitute the second equation (for $x_{i1}$) into the first equation (for $y_i$)? Does this equation satisfy OLS assumptions in some way? 5. Using the structural equations, what happens if we arbitrarily increase the value of `industry` ($x_{i2}$) by one unit? What happens to `education` ($x_{i1}$)? What happens to `income` ($y_i$)? 6. Can you read the effect sizes from the previous question off any of the regression results in @tbl-income? If so, which one(s)? ## Basic causal relations ```{r} #| include: false set.seed(2021) n <- 100000 admissions <- tibble( test = rnorm(n), interview = rnorm(n), score = test + interview, cutoff = quantile(score, .90), admitted = score >= cutoff) ``` ```{r} #| include: false fms <- list(lm(interview ~ test, data = admissions), lm(interview ~ test, data = admissions, subset = !admitted), lm(interview ~ test, data = admissions, subset = admitted), lm(interview ~ test * admitted, data = admissions)) ``` The results from these models are presented in the following table. ```{r} #| message: false #| echo: false #| label: tbl-collider #| tbl-pos: H #| tbl-cap: Regression with collider variables modelsummary(fms, estimate = "{estimate}{stars}", statistic = NULL, gof_map = c("nobs", "r.squared"), stars = c('*' = .1, '**' = 0.05, '***' = .01)) ``` ### Exercises 1. Imagine that, while you understand the basic idea that both tests and interviews affect admissions, you only have access to the regression results reported in @tbl-collider. Which of the four models seems to best "describe the data"? Which of the four models seems to do worst? 2. How are the coefficients reported in @tbl-collider for model (4) related to those for models (2) and (3)? Is this coincidence? Or would we always expect these relations to hold? 3. As applied economists, we should be alert to the "endogeneity" of institutions. For example, if universities admitted students based on test and interview performance, they probably have good reasons for doing so. Can you think of reasons why a university might add test and interview performance into a single score? Does your story have implications for the relationship between test and interview performance? 4. Using `mutate()`, create a fourth variable `test_x_admitted` that is the product of `test` and `admitted` and run a version of model (4) in @tbl-collider that uses this variable. That is, regress `interview` on `test`, `admitted`, and `test_x_admitted`. Do you get the same results as are shown above for model (4) in @tbl-collider? Why or why not? ## Causal diagrams: Formalities ### Exercises 1. Draw the DAG for the structural model above relating intelligence, industriousness, education, and income. For each $x$ variable, identify the sets of conditioning variables that satisfy the back-door criterion with respect to estimating a causal effect of the variable on $y$. 2. For any valid set of conditioning variables not considered in @tbl-income, run regressions to confirm that these indeed deliver good estimates of causal effects. ## Discrimination and bias ```{r} #| include: false n <- 100000 set.seed(2023) df <- tibble( female = runif(n) >= 0.5, discrimination = female, occupation = 1 + 0 * female - 2 * discrimination + rnorm(n), salary = 1 - 1 * discrimination + 2 * occupation + rnorm(n) ) fms <- list(lm(salary ~ female, data = df), lm(salary ~ female + occupation, data = df)) ``` ```{r} #| echo: false #| label: tbl-discrim #| tbl-pos: H #| tbl-cap: "Discrimination regressions" modelsummary(fms, estimate = "{estimate}{stars}", statistic = NULL, gof_map = c("nobs", "r.squared"), stars = c('*' = .1, '**' = 0.05, '***' = .01)) ``` ### Exercises 1. Given the equations for `occupation` and `salary` in the simulation above, what is the direct effect of discrimination on salary? What is the indirect effect (i.e., the effect via `occupation`) of discrimination on salary? What is the total effect of discrimination on salary? How do each of these effects show up in the regression results reported in @tbl-discrim? (*Note*: Because of sampling variation, the relationships will not be exact.) 2. Consider the possibility of an additional unobserved variable, ability ($A$), that affects role assignment ($O$) and also affects income ($Y$) directly. A DAG that captures this is provided in [the book's diagram with ability](https://iangow.github.io/far_book/causal-inf.html#fig-genderdisc2). What would be the correct conditioning strategy in this case? Would it now make sense to condition on $O$ if the goal is to estimate the total effect of discrimination on $Y$? (*Hint*: In answering this question, it may help to adapt the simulation above to generate an `ability` variable and to incorporate that in the model using code like the following.) The variable definitions below belong inside `tibble()`; it is disabled until incorporated into a complete simulation. ```{r} #| eval: false set.seed(2023) ability = rnorm(n), occupation = 1 + 0 * female - 2 * discrimination + 2 * ability + rnorm(n), salary = 1 - 1 * discrimination + 2 * occupation + 0.3 * ability + rnorm(n) ``` 3. Consider the additional possibility of different occupational preferences between males and females, as depicted in [the book's diagram with occupational preferences](https://iangow.github.io/far_book/causal-inf.html#fig-genderdisc3). Given this DAG, is it possible to identify a set of conditioning variables that allow you to estimate the total effect of discrimination on salary? What roles does $O$ have in this DAG? (*Hint*: Replace the `0` coefficient on `female` in the `occupation` equation used in the last question with a value of either `-1` or `+1`. Does the sign of this coefficient affect the sign of bias, if any?) Is it possible to estimate the *direct* effect of discrimination on salary? If so, how? If not, why?