-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy path3. Difference-In-Differences
26 lines (23 loc) · 1.14 KB
/
3. Difference-In-Differences
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
# Original post: https://towardsdatascience.com/does-minimum-wage-decrease-employment-a-difference-in-differences-approach-cb208ed07327
# by carefully selecting cases in the experimental groups, it is possible to detect the treatment effect even handling with obervational data.
# Difference-in-Differences, DID, is one of the most established methods of causal inference.
d <- read.csv(“wage_data.csv”,convert.factors = FALSE)
head(d[, c(“ID”, “nj”, “postperiod”, “emptot”)])
with(d,
(
mean(emptot[nj == 1 & postperiod == 1], na.rm = TRUE) — mean(emptot[nj == 1 & postperiod == 0], na.rm = TRUE)
)-
(mean(emptot[nj == 0 & postperiod == 1], na.rm = TRUE) — mean(emptot[nj == 0 & postperiod == 0], na.rm = TRUE)
)
)
ols <- lm(emptot ~ postperiod * nj, data = d)
coeftest(ols)
#A set of estimators and tests for panel data
library(plm)
library(lmtest)
d$Dit <- d$nj * d$postperiod
d <- plm.data(d, indexes = c("ID", "postperiod"))
did.reg <- plm(emptot ~ postperiod + Dit, data = d,model = "within")
coeftest(did.reg, vcov=function(x)
#Heteroskedasticity-Consistent Covariance Matrix Estimation
vcovHC(x, cluster="group", type="HC1"))