-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_design.R
More file actions
62 lines (50 loc) · 1.86 KB
/
Copy pathexample_design.R
File metadata and controls
62 lines (50 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# install.packages("DeclareDesign")
library(DeclareDesign)
# Model ---------------------------------------------------------
population <- declare_population(
N = 2100,
noise = rnorm(N),
age = sample(18:75, N, replace = TRUE),
young = as.numeric(age < 40))
potential_outcomes <- declare_potential_outcomes(
Y_Z_0 = noise,
Y_Z_1 = Y_Z_0 + 0.25 + 0.1 * young)
# Inquiry -------------------------------------------------------
estimand_ate <- declare_estimand(
ATE = mean(Y_Z_1 - Y_Z_0))
estimand_cate_diff <- declare_estimand(
CATE_diff = mean(Y_Z_1[young == 1] - Y_Z_0[young == 1]) -
mean(Y_Z_1[young == 0] - Y_Z_0[young == 0]))
# Data Strategy -------------------------------------------------
sampling <- declare_sampling(n = 250)
assignment <- declare_assignment(m = 125)
# Answer Strategy -----------------------------------------------
estimator_ate <- declare_estimator(Y ~ Z,
estimand = estimand_ate,
model = difference_in_means,
label = "estimator_ate")
estimator_cate <- declare_estimator(Y ~ Z * young,
estimand = estimand_cate_diff,
model = lm_robust,
term = "Z:young",
label = "estimator_cate")
# Design ---------------------------------------------------------
design <-
population +
potential_outcomes +
estimand_ate +
estimand_cate_diff +
sampling +
assignment +
declare_reveal() +
estimator_ate +
estimator_cate
# Diagnosands ----------------------------------------------------
diagnosands <- declare_diagnosands(
select = c(bias, power, mean_estimate)
)
diagnosis <- diagnose_design(
design, diagnosands = diagnosands,
sims = 100, bootstrap_sims = FALSE
)
diagnosis