Skip to content

Instantly share code, notes, and snippets.

@acoppock
Created April 29, 2020 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acoppock/d4793bca5a6c1f013c52245ba3f828bd to your computer and use it in GitHub Desktop.
Save acoppock/d4793bca5a6c1f013c52245ba3f828bd to your computer and use it in GitHub Desktop.
ATTandCACE
library(DeclareDesign)
library(tidyverse)
design <-
declare_population(N = 50,
type = sample(c("complier", "nevertaker"), N, replace = TRUE)) +
declare_potential_outcomes(D ~ Z * (type == "complier")) +
declare_potential_outcomes(Y ~ 5 * Z + rnorm(N)) +
declare_assignment(prob = 0.5) +
declare_estimand(CACE = mean(Y_Z_1 - Y_Z_0),
subset = type == "complier") +
declare_estimand(ATT = mean(Y_Z_1 - Y_Z_0),
subset = D == 1)
# Different in a single draw
draw_estimands(design)
# Same in expectation
simulate_design(design, sims = 500) %>%
group_by(estimand_label) %>%
summarise(mean_estimand = mean(estimand))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment