๋ ๋จ๊ณ ์ฐจ์ด-์ฐจ์ด(two stage Difference-in-Differences, ์ดํ 2S-DID) ๋ถ์์ ํต๊ณ ๋ชจ๋ธ์ ํ ํํ๋ก์, ๋ณต์กํ ์ํฉ์์ ์ฒ๋ฆฌ ํจ๊ณผ๋ฅผ ์ถ์ ํ ๋ ์ฌ์ฉ๋ฉ๋๋ค. ๊ธฐ๋ณธ์ ์ธ ์ฐจ์ด-์ฐจ์ด(DID) ๋ชจ๋ธ์ ์ฒ๋ฆฌ ๊ทธ๋ฃน๊ณผ ๋์กฐ ๊ทธ๋ฃน ๊ฐ์ ์ฐจ์ด๋ฅผ ์๊ฐ์ ๋ฐ๋ผ ๋น๊ตํ์ฌ ์ฒ๋ฆฌ์ ํจ๊ณผ๋ฅผ ์ถ์ ํฉ๋๋ค. ๊ทธ๋ฌ๋, ๋๋๋ก ์ฐ๊ตฌ์๋ ์ฒ๋ฆฌ์ ํจ๊ณผ๊ฐ ๋ค๋ฅธ ์์ธ์ ์ํด ์ค๊ฐ๋๋์ง ์ฌ๋ถ๋ฅผ ์ดํดํ๊ธฐ๋ฅผ ์ํ ์ ์์ต๋๋ค. ์ด๋ด ๋ ๋ ๋จ๊ณ DID ๋ถ์์ด ์ฌ์ฉ๋ ์ ์์ต๋๋ค.
์ฒซ ๋ฒ์งธ ๋จ๊ณ: ์ฌ๊ธฐ์ ์ฐ๊ตฌ์๋ ํ๋์ ๊ฒฐ๊ณผ(์: ๊ต์ก ํ๋ก๊ทธ๋จ์ ์ฐธ์ฌ)๋ฅผ ์์ธกํ๊ธฐ ์ํ ํ๊ท ๋ชจ๋ธ์ ๋ง๋ญ๋๋ค. ์ด ๋จ๊ณ๋ ์ผ๋ฐ์ ์ผ๋ก ๊ณต๋ณ๋์ ํฌํจํ์ฌ ํด๋น ๊ฒฐ๊ณผ๊ฐ ์ฒ๋ฆฌ ์ฌ๋ถ(์: ์ ์ฑ ๋์ )์ ์ด๋ป๊ฒ ์์กดํ๋์ง๋ฅผ ์ถ์ ํฉ๋๋ค.
๋ ๋ฒ์งธ ๋จ๊ณ: ์ฒซ ๋ฒ์งธ ๋จ๊ณ์์ ์ป์ ์์ธก๋ ๊ฒฐ๊ณผ๋ฅผ ์ฌ์ฉํ์ฌ, ๋ ๋ค๋ฅธ ํ๊ท ๋ชจ๋ธ์ ํตํด ์ต์ข ๊ด์ฌ ์๋ ๊ฒฐ๊ณผ(์: ์๊ธ)์ ๋ํ ์ฒ๋ฆฌ์ ํจ๊ณผ๋ฅผ ์ถ์ ํฉ๋๋ค. ์ด ๋จ๊ณ์์๋ ์ฒซ ๋ฒ์งธ ๋จ๊ณ์ ์์ธก๊ฐ์ ๋ ๋ฆฝ ๋ณ์๋ก ํฌํจํ์ฌ, ์ฒ๋ฆฌ๊ฐ ์ต์ข ๊ฒฐ๊ณผ์ ๋ฏธ์น๋ ์ง์ ์ ์ธ ํจ๊ณผ๋ฅผ ์ธก์ ํฉ๋๋ค.
2S-DID๋ ํนํ ์ฒ๋ฆฌ๊ฐ ํ๋์ ๊ฒฐ๊ณผ๋ฅผ ํตํด ๊ฐ์ ์ ์ผ๋ก ๋ค๋ฅธ ๊ฒฐ๊ณผ์ ์ํฅ์ ๋ฏธ์น ๋ ์ ์ฉํฉ๋๋ค. ์ด ๋ฐฉ๋ฒ์ ํน์ ์ฒ๋ฆฌ๊ฐ ์์๋ ์ค๊ฐ ๊ฒฐ๊ณผ๋ฅผ ํตํด ์ต์ข ๊ฒฐ๊ณผ์ ๋ฏธ์น๋ ์ด์ฒด์ ์ธ ํจ๊ณผ๋ฅผ ์ดํดํ ์ ์๊ฒ ํด์ค๋๋ค. ์๋ฅผ ๋ค์ด, ์ต์ ์๊ธ ์ธ์์ด ๋ ธ๋ ์์ฅ ์ฐธ์ฌ๋ฅผ ์ฆ๊ฐ์ํค๊ณ , ์ด๊ฒ์ด ๋ค์ ์๊ธ์ ์ํฅ์ ๋ฏธ์น ์ ์์ต๋๋ค. ์ฌ๊ธฐ์ ๋ ธ๋ ์์ฅ ์ฐธ์ฌ๋ ์ค๊ฐ ๊ฒฐ๊ณผ์ด๋ฉฐ, ์๊ธ์ ์ต์ข ๊ฒฐ๊ณผ์ ๋๋ค.
์ด๋ฐ ์ข ๋ฅ์ ๋ถ์์ ๋ฐ์ดํฐ์ ์ธ๋ถ ์ฌํญ์ ๋ฉด๋ฐํ ํ์ ํ๊ณ , ๋ค์ํ ๊ฐ์ ๋ค์ ์ถฉ์กฑํ๋์ง ํ์ธํ๋ ๊ฒ์ด ์ค์ํฉ๋๋ค. ๋ง์ฝ ์ด ๊ฐ์ ๋ค์ด ์ถฉ์กฑ๋์ง ์์ผ๋ฉด, ์ถ์ ๋ ํจ๊ณผ๋ ํธํฅ๋ ์ ์์ต๋๋ค.
\[ y_{it} = \mu_{i} + \mu_{t} + \sum_{k=-L}^{-2} \tau^{k} D_{it}^{k} + \sum_{k=1}^{K} \tau^{k} D_{it}^{k} + \varepsilon_{it} \]
๋ชจ๋ธ์ ๊ดํด ์์ธํ ๋ด ์๋ค.
๋ ๋ฐฉํฅ ๊ณ ์ ํจ๊ณผ(TWFE): ์ด๊ฒ์ ์๊ฐ์ ๋ฐ๋ผ ๋ณํ๋ ์์์ ๊ฐ ๋จ์(์: ๊ฐ์ธ, ๊ธฐ์ , ์ง์ญ ๋ฑ)์ ํน์ฑ์ ๋์์ ํต์ ํ ์ ์๊ฒ ํด์ฃผ๋ ๋ชจ๋ธ์ ๋๋ค. ๋ชจ๋ธ์ ์์์ \(\mu_i\)๋ ๊ฐ ๋จ์์ ๊ณ ์ ํจ๊ณผ๋ฅผ, \(\mu_t\)๋ ๊ฐ ์๊ฐ์ ๊ณ ์ ํจ๊ณผ๋ฅผ, \(D_i\)๋ ์ฒ๋ฆฌ ์ฌ๋ถ๋ฅผ ๋ํ๋ด๋ฉฐ, \(\varepsilon_{it}\)๋ ์ค์ฐจ ํญ์ ๋๋ค.
๋์ ์ด๋ฒคํธ ์คํฐ๋ ๋ชจ๋ธ: ์ด ๋ชจ๋ธ์ ์ฒ๋ฆฌ๊ฐ
์์๋๊ธฐ ์ ๊ณผ ํ์ ์ฌ๋ฌ ์์ ์ ํฌํจํด์ ์ฒ๋ฆฌ ํจ๊ณผ๋ฅผ ์ถ์ ํฉ๋๋ค. ์ฌ๊ธฐ์
k๋ ์๊ฐ์ ํน์ ์ง์ ์ ๋ํ๋ด๋ฉฐ, ์ฒ๋ฆฌ ์์์ผ๋ก๋ถํฐ์ ๋ฆฌ๋์
๋๊ทธ(์ฆ, ์๋ค ์๊ฐ๋)๋ฅผ ๊ณ ๋ คํฉ๋๋ค.
์ด๋ฌํ ๋ชจํ์์๋ ์ผ๋ฐ ์ต์ ์ ๊ณฑ๋ฒ(Ordinary Least Squares, OLS)์ผ๋ก ์ด๋ฐ ๋ชจ๋ธ์ ์ถ์ ํ ๋ ๋ฐ์ํ ์ ์๋ ๋ฌธ์ ์ ์ ๊ณ ๋ คํด ๋ณด์์ผ ํฉ๋๋ค. ํนํ, ์ฒ๋ฆฌ ํจ๊ณผ์ ์ด์ง์ฑ์ด ํด ๋, ํ๊ท ์ฒ๋ฆฌ ํจ๊ณผ๋ฅผ ์๋ชป ์ถ์ ํ ์ ์๋ค๋ ๊ฒ์ ๋๋ค. ์ฆ, ๊ฐ ๊ทธ๋ฃน์์ ์ฒ๋ฆฌ๊ฐ ๋ฏธ์น๋ ์ํฅ์ด ์๋ก ๋ค๋ฅด๊ฒ ๋ํ๋ ์ ์์ต๋๋ค.
์ด๋ฅผ ํด๊ฒฐํ๋ ํ ๊ฐ์ง ๋ฐฉ๋ฒ์ ํ๋ฆฌ์-์-๋ฌ๋ฒจ(FWL: Frisch-Waugh-Lovell) ์ ๋ฆฌ๋ฅผ ํตํด ๊ณ ์ ํจ๊ณผ๋ฅผ ๊ณ ๋ คํ์ฌ ์ฒ๋ฆฌ ํจ๊ณผ๋ฅผ ๋ค์ ๊ณ์ฐํ๋ ๊ฒ์ ๋๋ค. ์ด ๋ฐฉ๋ฒ์ ์ฒ๋ฆฌ๋์ง ์์์ ์ํฉ์ โ์ฌ๊ตฌ์ฑโํ์ฌ, ์ฒ๋ฆฌ ํจ๊ณผ์ ์ถ์ ์น๊ฐ ์ค์ ํต์ ๊ทธ๋ฃน์ ๊ฒฐ๊ณผ์ ๋น๊ต๋ ์ ์๋๋ก ํฉ๋๋ค. ์ด๋ก ์ ์ผ๋ก๋ ์ฒ๋ฆฌ๋ฅผ ๋ฐ์ง ์์ ์ํ์ ๊ฒฐ๊ณผ๋ฅผ ์ผ๊ด๋๊ฒ ์ถ์ ํ ์ ์๋ค๋ฉด, ์ค์ ์ฒ๋ฆฌ๋ ๊ฒฐ๊ณผ์์ ์ด๋ฅผ ๋บ ๊ฐ์ด ์ฒ๋ฆฌ์ ์์ํ ํจ๊ณผ๋ฅผ ๋ํ๋ผ ๊ฒ์ ๋๋ค.
install.packages('did2s')
#or
#remotes::install_github("kylebutts/did2s")
์๋์ฐ ์ฌ์ฉ์ ์ฌ๋ฌ๋ถ Rtools๋ฅผ ๋จผ์ ์ค์นํด์ผ ํฉ๋๋ค. ๊ตฌ๊ธ ๊ฒ์ํด์ ์ค์นํ์ธ์.
library(did2s)
๊ฒฝ๊ณ : ํจํค์ง โdid2sโ๋ R ๋ฒ์ 4.2.3์์ ์์ฑ๋์์ต๋๋คํ์ํ ํจํค์ง๋ฅผ ๋ก๋ฉ์ค์
๋๋ค: fixest
did2s (v1.0.2). For more information on the methodology, visit <https://www.kylebutts.github.io/did2s>
To cite did2s in publications use:
Butts, Kyle (2021). did2s: Two-Stage Difference-in-Differences Following Gardner (2021). R
package version 1.0.2.
LaTeX ์ฌ์ฉ์๋ค์ ์ํ BibTeX ํญ๋ชฉ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค
@Manual{,
title = {did2s: Two-Stage Difference-in-Differences Following Gardner (2021)},
author = {Kyle Butts},
year = {2021},
url = {https://github.com/kylebutts/did2s/},
}
library(ggplot2)
library(dplyr)
data('df_het')
head(df_het)
df_het ๋ฐ์ดํฐ๋ฅผ ์ค๋ช ํ๊ฒ ์ต๋๋ค. ์ฌ๊ธฐ์ ์ค๋ช ํ๋ ๊ฐ์ ๋ฐ์ดํฐ์ ์ ํจ๋ ๋ฐ์ดํฐ ํ์์ ๊ฐ์ง๊ณ ์์ผ๋ฉฐ, ๋ ๊ฐ์ ์ฒ๋ฆฌ ๊ทธ๋ฃน๊ณผ ์ด์ง์ ์ธ ํจ๊ณผ๋ฅผ ํฌํจํ๊ณ ์์ต๋๋ค. ๋ฐ์ดํฐ ํ๋ ์์๋ ์ด 31,000๊ฐ์ ํ๊ณผ 15๊ฐ์ ๋ณ์๊ฐ ์์ต๋๋ค:
unit: ํจ๋ ๋ฐ์ดํฐ์์์ ๊ฐ๋ณ ๋์(์: ์ฌ๋, ๊ธฐ์
๋ฑ)์
๋ํ๋
๋๋ค.year: ํจ๋ ๋ฐ์ดํฐ์์์ ์๊ฐ์ ๋ํ๋ด๋ฉฐ, ๋ณดํต ์ฐ๋๋ฅผ
์๋ฏธํฉ๋๋ค.g: ์ฒ๋ฆฌ๊ฐ ์์๋๋ ์ฐ๋์
๋๋ค.dep_var: ๊ฒฐ๊ณผ ๋ณ์๋ก, ๋ถ์์ ์ฃผ์ ๊ด์ฌ์ฌ์ธ ๋ณ์๋ฅผ
๋ํ๋
๋๋ค.treat: ์ฒ๋ฆฌ ์ฌ๋ถ๋ฅผ ๋ํ๋ด๋ ์ฐธ/๊ฑฐ์ง ๋ณ์๋ก, ์ฒ๋ฆฌ๊ฐ
์ค์ ๋ก ์ ์ฉ๋ ์๊ธฐ๋ฅผ ๋ํ๋
๋๋ค.rel_year: ์ฒ๋ฆฌ ์์์ ๋ํ ์๋์ ์ธ ์ฐ๋๋ฅผ ๋ํ๋
๋๋ค.
โInfโ๋ ์ ๋ ์ฒ๋ฆฌ๋์ง ์๋ ๊ฒฝ์ฐ๋ฅผ ์๋ฏธํฉ๋๋ค.rel_year_binned: ์ฒ๋ฆฌ ์์์ ๋ํ ์๋์ ์ธ ์ฐ๋๋ฅผ
๋ํ๋ด์ง๋ง, -6 ์ดํ ๋ฐ 6 ์ด์์ ๊ฐ์ ๋ฒ์ฃผํ๋์ด ์ง๊ณ๋ฉ๋๋ค.unit_fe: ๊ฐ๋ณ ๋์์ ๋ํ ๊ณ ์ ํจ๊ณผ(Fixed
Effect)์
๋๋ค.year_fe: ์ฐ๋์ ๋ํ ๊ณ ์ ํจ๊ณผ์
๋๋ค.error: ๋๋ค ์ค๋ฅ ๊ตฌ์ฑ ์์๋ก, ๋ชจ๋ธ์ ๋ฌด์์์ฑ์
์ถ๊ฐํฉ๋๋ค.te: ์ฒ๋ฆฌ์ ์ ์ (๋ณํ์ง ์๋) ํจ๊ณผ๋ฅผ ๋ํ๋ด๋
๋ณ์์
๋๋ค.te_dynamic: ์ฒ๋ฆฌ์ ๋์ (๋ณํํ๋) ํจ๊ณผ๋ฅผ ๋ํ๋ด๋
๋ณ์์
๋๋ค.state: ๊ฐ๋ณ ๋์์ด ์ํ ์ฃผ๋ฅผ ๋ํ๋
๋๋ค.group: ๊ทธ๋ฃน์ ๋ฌธ์์ด ์ด๋ฆ์ผ๋ก, ๋ฐ์ดํฐ๊ฐ ์ํ ๋ฒ์ฃผ๋
์ง๋จ์ ๋ํ๋
๋๋ค.์ด ๋ฐ์ดํฐ๋ ์๊ฐ์ ๋ฐ๋ผ ๋ค๋ฅธ ๊ฐ์ธ์ด๋ ๋จ์๋ค์ ๋ํด ์ฒ๋ฆฌ(์: ์ ์ฑ ๋ณ๊ฒฝ, ํ๋ก๊ทธ๋จ ๋์ ๋ฑ)๊ฐ ์ด๋ค ์ํฅ์ ๋ฏธ์ณค๋์ง๋ฅผ ๋ถ์ํ๊ธฐ ์ํ ๊ฒ์ผ๋ก ๋ณด์ ๋๋ค. ๊ฐ ๋ณ์๋ค์ ์ฒ๋ฆฌ์ ์ํฅ์ ํ๊ฐํ๊ณ , ๊ฒฐ๊ณผ๋ฅผ ํด์ํ๋ ๋ฐ ํ์ํ ๋ค์ํ ์ฐจ์์ ์ ๊ณตํฉ๋๋ค. ๋ฐ์ดํฐ์ ์ ๊ตฌ์กฐ๋ฅผ ํตํด ์ฐ๊ตฌ์๋ ์ฒ๋ฆฌ๊ฐ ์์๋๊ธฐ ์ ๊ณผ ํ์ ๊ฒฐ๊ณผ๋ฅผ ๋น๊ตํ๊ณ , ์ฒ๋ฆฌ์ ์ํฅ์ด ์๊ฐ์ ๋ฐ๋ผ ์ด๋ป๊ฒ ๋ณํ๋์ง, ๊ทธ๋ฆฌ๊ณ ์ด๋ฌํ ํจ๊ณผ๊ฐ ๊ฐ๋ณ ๋์์ด๋ ๊ทธ๋ฃน๋ง๋ค ์ด๋ป๊ฒ ๋ค๋ฅธ์ง๋ฅผ ๋ถ์ํ ์ ์์ต๋๋ค.
df_het %>%
group_by(year,g) %>%
summarize(outcome = mean(dep_var)) %>%
ungroup() %>%
ggplot(aes(x=year,y=outcome,col=as.factor(g))) +
geom_point() +
geom_line() +
theme_bw()
`summarise()` has grouped output by 'year'. You can override using the `.groups` argument.
์ฒ๋ฆฌ๊ฐ ์์๋ 2000๋ ๊ณผ 2010๋ ์ ๋ฐ๋ผ ๊ธฐ์ธ๊ธฐ์ ๋ณํ๊ฐ ๊ธ๊ฒฉํ ๋ํ๋๋ ๊ฒ์ ๋ณผ ์ ์์ต๋๋ค.
โ์ ์ ์ฐจ์ด-์ฐจ์ด ์ถ์ (static DiD estimation)โ์ด๋ ๋ณํ์ง ์๋ ํจ๊ณผ๋ฅผ
๊ฐ์ง ์ฐจ์ด-์ฐจ์ด ๋ชจ๋ธ์ ์ถ์ ํ๋ ๊ฒ์
๋๋ค. ์ฌ๊ธฐ์ ์ค๋ช
๋ ๋ด์ฉ์ ๋ฐ๋ฅด๋ฉด,
R์ fixest ํจํค์ง์ ๊ธฐ๋ฅ๋ค์ ํ์ฉํด ์ด ๊ณผ์ ์ ์ํํ ์
์์ต๋๋ค. ์ฌ๊ธฐ์ ๋ช ๊ฐ์ง ์ค์ํ ํฌ์ธํธ๊ฐ ์์ต๋๋ค:
๊ณ ์ ํจ๊ณผ ๋ช
์: fixest::feols
ํจ์๋ฅผ ์ฌ์ฉํ๋ฉด | ๊ธฐํธ๋ฅผ ์ด์ฉํด ๊ณ ์ ํจ๊ณผ๋ฅผ ์์ฝ๊ฒ ๋ช
์ํ
์ ์์ต๋๋ค. ๊ณ ์ ํจ๊ณผ๋ ์๊ฐ์ด๋ ๊ฐ์ฒด ๋ฑ์ ๋ฐ๋ฅธ ๋ณํ์ง ์๋ ํน์ฑ์
๋ชจ๋ธ์์ ํต์ ํ๋ ๊ฒ์ ๋งํฉ๋๋ค.
๊ฐ์ ๋ ์์ธ ๋ณ์ ์ง์: fixest::i๋
๋ฒ์ฃผํ ๋ณ์๋ฅผ ๋ ์ ์ฒ๋ฆฌํ ์ ์๋๋ก ํด์ฃผ๋ฉฐ, ์ด๋ ๋ชจ๋ธ์ ํด์์ ๊ฐ์ ํ
์ ์์ต๋๋ค.
did2s ํจ์์ fixest
๊ฐ์ฒด: did2s ํจ์๋ฅผ ์ฌ์ฉํด ์ถ์ ํ๋ฉด,
fixest ํจํค์ง์ ์ถ์ ๊ฐ์ฒด๋ฅผ ๋ฐํํฉ๋๋ค. ์ด๋
fixest::esttable (์ถ์ ๊ฒฐ๊ณผ๋ฅผ ํ๋ก ๋ํ๋ด๊ธฐ),
fixest::coefplot (๊ณ์๋ฅผ ๊ทธ๋ํ๋ก ๋ํ๋ด๊ธฐ), ๊ทธ๋ฆฌ๊ณ
fixest::iplot (์ํธ์์ฉ ํญ์ ํฌํจํ ๋ชจ๋ธ์ ๊ฒฐ๊ณผ๋ฅผ ๊ทธ๋ํ๋ก
๋ํ๋ด๊ธฐ) ๊ฐ์ fixest ํจํค์ง์ ๋ค๋ฅธ ํจ์๋ค๊ณผ
ํธํ๋ฉ๋๋ค.
์ด๋ฅผ ํตํด, ๊ณ ์ ํจ๊ณผ๋ฅผ ํฌํจํ ์ ์ DiD ๋ชจ๋ธ์ ์ถ์ ํ๊ณ , ์ด ๊ฒฐ๊ณผ๋ฅผ
๋ค์ํ ๋ฐฉ์์ผ๋ก ์๊ฐํํ๊ฑฐ๋ ํํํ ์ ์์ต๋๋ค. ์ด ๋ชจ๋ ๊ณผ์ ์ด
fixest ํจํค์ง ์์์ ์ด๋ฃจ์ด์ง๊ธฐ ๋๋ฌธ์, ๋ถ์ ๊ณผ์ ์ด
ํตํฉ๋๊ณ ํจ์จ์ ์
๋๋ค.
static = did2s(
df_het, #data
yname = 'dep_var',
first_stage = ~ 0 | state + year,
second_stage = ~ i(treat,ref=FALSE),
treatment = 'treat',
cluster_var = 'state'
)
Running Two-stage Difference-in-Differences
- first stage formula `~ 0 | state + year`
- second stage formula `~ i(treat, ref = FALSE)`
- The indicator variable that denotes when treatment is on is `treat`
- Standard errors will be clustered by `state`
๊ฒฐ๊ณผ๋ฅผ ๋ด ์๋ค.
fixest::esttable(static)
static
Dependent Var.: dep_var
treat = TRUE 2.152*** (0.0476)
_______________ _________________
S.E. type Custom
Observations 46,500
R2 0.33790
Adj. R2 0.33790
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
์ถ์ ๊ฒฐ๊ณผ๋ fixest::esttable ํจ์๋ก ์ถ๋ ฅ๋๋ฉฐ, โtreat =
TRUEโ์ ๊ณ์๋ ์ฒ๋ฆฌ ํจ๊ณผ๋ฅผ ๋ํ๋
๋๋ค. ์ฌ๊ธฐ์ ์ถ์ ๋ ํจ๊ณผ๋ 2.152๋ก,
๊ดํธ ์์ ์ซ์ 0.0476์ ๊ณ์์ ํ์ค ์ค์ฐจ๋ฅผ ๋ํ๋
๋๋ค. ๋ณํ ์ธ ๊ฐ๋ ์ด
ํจ๊ณผ๊ฐ ํต๊ณ์ ์ผ๋ก ๋งค์ฐ ์ ์๋ฏธํจ์ ๋ํ๋
๋๋ค(์ผ๋ฐ์ ์ผ๋ก p-value๊ฐ
0.001๋ณด๋ค ์์ ๋ ์ฌ์ฉ๋ฉ๋๋ค).
์ด ๊ฒฐ๊ณผ๋ โtreatโ ๋ณ์๊ฐ ์ฐธ์ผ ๋(์ฆ, ์ฒ๋ฆฌ๊ฐ ์ ์ฉ๋์์ ๋) ์์๋๋ ์ข ์ ๋ณ์ โdep_varโ์ ๋ณํ๋์ด ์ฝ 2.152 ๋จ์๋ผ๋ ๊ฒ์ ๋ณด์ฌ์ฃผ๋ฉฐ, ์ด ๋ณํ๋์ ํต๊ณ์ ์ผ๋ก ์ ์๋ฏธํ ๊ฒ์ผ๋ก ๋ํ๋ฌ์ต๋๋ค. ์ด๋ ์ฒ๋ฆฌ(์: ์ ์ฑ , ํ๋ก๊ทธ๋จ ๋ฑ)๊ฐ ๊ธ์ ์ ์ธ ์ํฅ์ ๋ฏธ์ณค์์ ๋ํ๋ผ ์ ์์ต๋๋ค.
es <- did2s(df_het,
yname='dep_var',
first_stage = ~0|state+year,
second_stage = ~i(rel_year,ref=c(-1,Inf)),
treatment = 'treat',
cluster_var='state')
Running Two-stage Difference-in-Differences
- first stage formula `~ 0 | state + year`
- second stage formula `~ i(rel_year, ref = c(-1, Inf))`
- The indicator variable that denotes when treatment is on is `treat`
- Standard errors will be clustered by `state`
์ฐธ๊ณ ๋ก i()๋ fixest์ ์๋ ํจ์์์. Create or interact variables with, factors๋ผ๋ ์ ๋ชฉ์ด ์์ง์. rel_year๋ฅผ ๊ฐ๊ฐ์ ์์ธ์ผ๋ก ์ฒ๋ฆฌํ๋ ๋ฐ ref๋ ์ฐธ์กฐ ๋ฒกํฐ์ ๊ฐ์ ๋๋ค. ๋ง์ฝ ref=TRUE์ด๋ฉด factor_var์ ์ฒซ ๋ฒ์งธ ๊ฐ์ ์ ๊ฑฐํฉ๋๋ค. ์ด๋ ๋ฒ์ฃผํ ๋ณ์์์ ๊ธฐ์ค ์นดํ ๊ณ ๋ฆฌ ์์ค์ ๊ฒฐ์ ํ๋๋ฐ ์ฌ์ฉํ๊ณ , c(-1,Inf)์ ๊ฐ์ ๊ฒฝ์ฐ์๋ reference๋ฅผ -1๋ถํฐ ๋ฌดํ๋๋ก ์ก๊ณ ์์ต๋๋ค.
๊ฒฐ๊ณผ๋ฅผ ์ดํด๋ณด๊ฒ ์ต๋๋ค.
fixest::esttable(es)
es
Dependent Var.: dep_var
rel_year = -20 -0.0793. (0.0461)
rel_year = -19 -0.0271 (0.0532)
rel_year = -18 -0.0272 (0.0486)
rel_year = -17 -0.0336 (0.0428)
rel_year = -16 -0.0558 (0.0529)
rel_year = -15 0.0168 (0.0507)
rel_year = -14 -0.0209 (0.0493)
rel_year = -13 -0.0222 (0.0398)
rel_year = -12 0.0054 (0.0457)
rel_year = -11 -0.0479 (0.0594)
rel_year = -10 -0.0325 (0.0341)
rel_year = -9 -0.0375 (0.0304)
rel_year = -8 -0.0309 (0.0321)
rel_year = -7 -0.0071 (0.0363)
rel_year = -6 -0.0396 (0.0272)
rel_year = -5 -0.0792** (0.0304)
rel_year = -4 -0.0342 (0.0280)
rel_year = -3 -0.0152 (0.0305)
rel_year = -2 -0.0387 (0.0323)
rel_year = 0 1.304*** (0.0561)
rel_year = 1 1.533*** (0.0644)
rel_year = 2 1.597*** (0.0567)
rel_year = 3 1.719*** (0.0606)
rel_year = 4 1.846*** (0.0477)
rel_year = 5 1.991*** (0.0563)
rel_year = 6 2.079*** (0.0643)
rel_year = 7 2.165*** (0.0585)
rel_year = 8 2.259*** (0.0580)
rel_year = 9 2.278*** (0.0533)
rel_year = 10 2.415*** (0.0601)
rel_year = 11 2.456*** (0.0819)
rel_year = 12 2.507*** (0.0797)
rel_year = 13 2.481*** (0.0846)
rel_year = 14 2.626*** (0.0697)
rel_year = 15 2.813*** (0.0827)
rel_year = 16 2.763*** (0.0824)
rel_year = 17 2.811*** (0.0794)
rel_year = 18 2.777*** (0.0818)
rel_year = 19 2.786*** (0.0902)
rel_year = 20 2.815*** (0.0830)
_______________ __________________
S.E. type Custom
Observations 46,500
R2 0.36048
Adj. R2 0.35994
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
์๊ฐ์ ์ผ๋ก ์์๋ด ๋๋ค.
fixest::iplot(es,
main = "Event study: Staggered treatment",
xlab = "Relative time to treatment",
col = "steelblue",
ref.line = -0.5)
# Add the (mean) true effects
true_effects = head(tapply((df_het$te + df_het$te_dynamic), df_het$rel_year, mean), -1)
points(-20:20, true_effects, pch = 20, col = "black")
# Legend
legend(x=-20, y=3, col = c("steelblue", "black"), pch = c(20, 20),
legend = c("Two-stage estimate", "True effect"))
Comparison to TWFE๋ฅผ ์๊ฐํด ๋ด
์๋ค. 2S-DID์ ์ ํต์ ์ธ
TWFE ๊ฐ์ ๋ชจ๋ธ ์ถ์ ์ ๋ํด ์ดํดํ๊ธฐ๋ก ํฉ๋๋ค.
twfe = feols(dep_var ~ i(rel_year, ref=c(-1, Inf)) | unit + year, data = df_het)
๊ทธ๋ฆฌ๊ณ ์์ ๊ตฌํ ๊ฒฐ๊ณผ์ ๋น๊ตํฉ๋๋ค.
fixest::iplot(list(es, twfe), sep = 0.2, ref.line = -0.5,
col = c("steelblue", "#82b446"), pt.pch = c(20, 18),
xlab = "Relative time to treatment",
main = "Event study: Staggered treatment (comparison)")
points(-20:20, true_effects, pch = 21, col = "red")
# Legend
legend(x=-20, y=3, col = c("steelblue", "#82b446","red"), pch = c(20, 18,21),
legend = c("Two-stage estimate", "TWFE","True"))
์ฝ๋ ํด์ค์ ๋๋ค.
TWFE ์ถ์ : feols ํจ์๋ฅผ ์ฌ์ฉํด TWFE
๋ชจ๋ธ์ ์ถ์ ํฉ๋๋ค. ์ด ๋ชจ๋ธ์ dep_var (์ข
์ ๋ณ์)์
rel_year (์ฒ๋ฆฌ ์์ ๋๋น ์๋์ ์ธ ์ฐ๋)์ ๊ด๊ณ๋ฅผ ๋ถ์ํ๋ฉฐ,
์ฌ๊ธฐ์ -1๊ณผ Inf๋ฅผ ์ฐธ์กฐ ์นดํ
๊ณ ๋ฆฌ๋ก ์ค์ ํฉ๋๋ค.
์ด ์ถ์ ์์๋ ๋ํ ๊ฐ unit๊ณผ year์ ๋ํ ๊ณ ์
ํจ๊ณผ๋ฅผ ํฌํจํฉ๋๋ค. ๋ฐ์ดํฐ๋ df_het์์ ๊ฐ์ ธ์ต๋๋ค.
๊ทธ๋ํ ํ๋กํ
: fixest::iplot ํจ์๋
2S-DID ๋ชจ๋ธ(es)๊ณผ TWFE ๋ชจ๋ธ(twfe)์ ๊ฒฐ๊ณผ๋ฅผ
๋น๊ตํ๋ ๊ทธ๋ํ๋ฅผ ์์ฑํฉ๋๋ค. ์ฌ๊ธฐ์ sep๋ ์ถ์ ์น ๊ฐ์ ์์ง
๊ฐ๊ฒฉ์, ref.line์ ๊ธฐ์ค์ ์ ์์น๋ฅผ, col์ ์ ์
์์, pt.pch๋ ํฌ์ธํธ ๋ง์ปค์ ํํ๋ฅผ ์ ์ํฉ๋๋ค.
xlable๊ณผ main์ ๊ฐ๊ฐ x์ถ ๋ ์ด๋ธ๊ณผ ๊ทธ๋ํ์
์ ๋ชฉ์
๋๋ค.
๋ฒ๋ก ์ถ๊ฐ: legend ํจ์๋ฅผ ์ฌ์ฉํด
๊ทธ๋ํ์ ๋ฒ๋ก๋ฅผ ์ถ๊ฐํฉ๋๋ค. ์ด ๋ฒ๋ก๋ ๋ ์ถ์ ๋ฐฉ๋ฒ์ ๊ตฌ๋ณํ๊ธฐ ์ํด
์ฌ์ฉ๋ฉ๋๋ค. ์์น์ ์์, ํฌ์ธํธ ๋ง์ปค๊ฐ ์ ์๋ฉ๋๋ค.
๊ฐ์ฌํฉ๋๋ค.