-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDCL_DiD.R
More file actions
113 lines (74 loc) · 2.65 KB
/
DCL_DiD.R
File metadata and controls
113 lines (74 loc) · 2.65 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
##Install packages
install.packages("ggplot2")
install.packages("wooldridge")
install.packages("lmtest")
install.packages("multiwayvcov")
install.packages("gghighlight")
install.packages("rmarkdown")
library (lmtest)
library (multiwayvcov)
library (wooldridge )
library(ggplot2)
library(dplyr)
library(gghighlight)
library(rmarkdown)
## Load data
setwd("C:~")
testdata <- read.csv("testdata.CSV", sep=";")
```
## Prepare and illustrate the data
testdata <- testdata %>%
mutate(
group = case_when(
wage == 0 & year < 1981 ~ "wage_0_pre",
wage == 0 & year >= 1981 ~ "wage_0_post",
wage == 1 & year < 1981 ~ "wage_1_pre",
wage == 1 & year >= 1981 ~ "wage_1_post"
)
)
## Plot the DiD
testdata$wage = as.factor(testdata$wage)
ggplot(data = testdata, aes(x = year, y = employ, color = wage)) +
geom_point() +
stat_summary(fun = mean, geom = "line", aes(group = wage), linetype = "solid") +
geom_vline(xintercept = 1981, color = "red", linetype = "dashed") +
labs(
x = "Year",
y = "Employment in Percentage",
color = "Group",
title = "Impact of Minimum Wage Introduction on Employment",
subtitle = "Difference-in-Differences Analysis"
) +
scale_color_manual(values = c("red", "green"), labels = c("no min wage", "min wage")) +
theme_minimal()
## Naive estimation of the treatment
mean_post_treatment <- testdata %>%
filter(year >= 1981 & wage == 1) %>%
summarize(mean_employ = mean(employ))%>%
print(mean_post_treatment)
mean_post_non_treatment <- testdata %>%
filter(year >= 1981 & wage == 0) %>%
summarize(mean_employ = mean(employ))%>%
print(mean_post_non_treatment)
print(mean_post_treatment - mean_post_non_treatment)
## Estimation that accounts for business-cycles (common trend)
mean_pre_non_treatment <- testdata %>%
filter(year < 1981 & wage == 0) %>%
summarize(mean_employ = mean(employ))
print(mean_pre_non_treatment)
mean_post_non_treatment <- testdata %>%
filter(year >= 1981 & wage == 0) %>%
summarize(mean_employ = mean(employ))
print(mean_post_non_treatment)
print(mean_post_non_treatment - mean_pre_non_treatment)
## Better estimation employing the DiD-Design
mean_pre_treatment <- testdata %>%
filter(year < 1981 & wage == 1) %>%
summarize(mean_employ = mean(employ))
diff_d1.1 <- mean_pre_treatment - mean_pre_non_treatment
print(diff_d1.1)
diff_d1.2 <- mean_post_treatment - mean_post_non_treatment
print(diff_d1.2)
att <- diff_d1.2 - diff_d1.1
print(att)
## Withh att we end up with our corrected estimation taking the common trends into consideration