-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsim_test_package.R
More file actions
48 lines (31 loc) · 1.37 KB
/
sim_test_package.R
File metadata and controls
48 lines (31 loc) · 1.37 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
library(tidyverse)
library(panelsim)
require(ggplot2)
# see if DiD works
# loop 1,000 times
# canonical DiD: two time points, interact with time point
true_did_eff <- 0.2
main_coef_x <- -4
# assume treatment effects are homogeneous
first_run <- tw_data(N=1000,T=2,did.eff.mean = true_did_eff,did.eff.sd = 0,
cross.eff.mean = main_coef_x,case.int.sd = .5,
cross.int.sd = .5,cross.eff.sd = 0,
case.eff.sd = 0,case.eff.mean = .5,
cross.int.mean = .5,case.int.mean = 2)
calc_did <- parallel::mclapply(1:1000, function(i) {
did_canonical <- tw_data(N=1000,T=2,did.eff.mean = true_did_eff,
cross.eff.mean = main_coef_x,
cross.int.mean = .5,case.int.mean = 2,
prior_true_vals = first_run,
binary_outcome=F,binary_x=F)
did_est <- lm(y ~ x*factor(time), data=did_canonical$data)
tibble(ATE_DID=did_est$coefficients['x:factor(time)2'],
ATE_int=did_est$coefficients['factor(time)2'],
overall_int=did_est$coefficients['(Intercept)'],
coef_x=did_est$coefficients['x'])
},mc.cores=8) %>% bind_rows
summary(calc_did$ATE_DID)
summary(calc_did$ATE_int)
summary(calc_did$overall_int)
summary(calc_did$coef_x)
# try with treatment effects, look at what happens to the 1-way case FE