Created
July 1, 2022 10:27
-
-
Save jwbowers/d5faaa192d78695b3a0c23e172b2440a to your computer and use it in GitHub Desktop.
High_Dim_Cov_Adj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(estimatr) | |
library(fabricatr) | |
library(DeclareDesign) | |
set.seed(12345) | |
dat <- | |
fabricate( | |
N = 50, | |
x = sample(1:40, N, replace = TRUE), | |
xF = factor(x), | |
potential_outcomes(Y ~ 0.1 * Z + x + rnorm(N)), | |
Z = sample(0:1, N, replace = TRUE), | |
Y = reveal_outcomes(Y ~ Z) | |
) | |
des <- declare_population(dat) + | |
declare_assignment(Z=complete_ra(N=N))+ | |
declare_potential_outcomes(Y ~ 0.1 * Z + x + rnorm(N)) + | |
declare_inquiry(ATE=mean(Y_Z_1 - Y_Z_0))+ | |
declare_reveal(Y,Z) + | |
declare_estimator(Y~Z, | |
.method = lm_robust, | |
.summary = tidy, | |
term = "Z", | |
inquiry = "ATE", | |
label = "lm_unbiased") + | |
declare_estimator(Y~Z,covariates=~xF, | |
.method = lm_lin, | |
.summary = tidy, | |
term = "Z", | |
inquiry = "ATE", | |
label = "lm_lin") + | |
declare_estimator(Y~Z+xF, | |
.method = lm_robust, | |
.summary = tidy, | |
term = "Z", | |
inquiry = "ATE", | |
label = "lm_dummies") + | |
declare_estimator(Y~Z*xF, | |
.method = lm_robust, | |
.summary = tidy, | |
term = "Z", | |
inquiry = "ATE", | |
label = "lm_interact") | |
dat2 <- draw_data(des) | |
draw_estimand(des) | |
draw_estimates(des) | |
names(des) | |
## Just vary assignment: | |
diag <- diagnose_design(des,bootstrap_sims = 0,sims=c(1,1000,1,1,1,1,1,1,1)) | |
diag | |
lm_lin(Y ~ Z, covariates = ~as.factor(x), data = dat) | |
lm_robust(Y ~ Z + as.factor(x), data = dat) | |
summary(lm(Y ~ Z*as.factor(x), data = dat)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment