-
Notifications
You must be signed in to change notification settings - Fork 239
Expand file tree
/
Copy pathipw.R
More file actions
67 lines (52 loc) · 1.61 KB
/
Copy pathipw.R
File metadata and controls
67 lines (52 loc) · 1.61 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
62
63
64
65
66
67
library(tidyverse)
library(haven)
#continuation
N <- nrow(nsw_dw_cpscontrol)
#- Manual with non-normalized weights using all data
nsw_dw_cpscontrol <- nsw_dw_cpscontrol %>%
mutate(d1 = treat/pscore,
d0 = (1-treat)/(1-pscore))
s1 <- sum(nsw_dw_cpscontrol$d1)
s0 <- sum(nsw_dw_cpscontrol$d0)
nsw_dw_cpscontrol <- nsw_dw_cpscontrol %>%
mutate(y1 = treat * re78/pscore,
y0 = (1-treat) * re78/(1-pscore),
ht = y1 - y0)
#- Manual with normalized weights
nsw_dw_cpscontrol <- nsw_dw_cpscontrol %>%
mutate(y1 = (treat*re78/pscore)/(s1/N),
y0 = ((1-treat)*re78/(1-pscore))/(s0/N),
norm = y1 - y0)
nsw_dw_cpscontrol %>%
pull(ht) %>%
mean()
nsw_dw_cpscontrol %>%
pull(norm) %>%
mean()
#-- trimming propensity score
nsw_dw_cpscontrol <- nsw_dw_cpscontrol %>%
select(-d1, -d0, -y1, -y0, -ht, -norm) %>%
filter(!(pscore >= 0.9)) %>%
filter(!(pscore <= 0.1))
N <- nrow(nsw_dw_cpscontrol)
#- Manual with non-normalized weights using trimmed data
nsw_dw_cpscontrol <- nsw_dw_cpscontrol %>%
mutate(d1 = treat/pscore,
d0 = (1-treat)/(1-pscore))
s1 <- sum(nsw_dw_cpscontrol$d1)
s0 <- sum(nsw_dw_cpscontrol$d0)
nsw_dw_cpscontrol <- nsw_dw_cpscontrol %>%
mutate(y1 = treat * re78/pscore,
y0 = (1-treat) * re78/(1-pscore),
ht = y1 - y0)
#- Manual with normalized weights with trimmed data
nsw_dw_cpscontrol <- nsw_dw_cpscontrol %>%
mutate(y1 = (treat*re78/pscore)/(s1/N),
y0 = ((1-treat)*re78/(1-pscore))/(s0/N),
norm = y1 - y0)
nsw_dw_cpscontrol %>%
pull(ht) %>%
mean()
nsw_dw_cpscontrol %>%
pull(norm) %>%
mean()