-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathREADME.Rmd
93 lines (73 loc) · 3.74 KB
/
README.Rmd
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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%",
options(width = 100)
)
```
# Extended Two-way Fixed Effects (ETWFE)
<!-- badges: start -->
[![CRAN version](https://www.r-pkg.org/badges/version/etwfe)](https://CRAN.R-project.org/package=etwfe)
[![R-universe status badge](https://grantmcdermott.r-universe.dev/badges/etwfe)](https://grantmcdermott.r-universe.dev)
[![Dev R-CMD-check](https://github.com/grantmcdermott/etwfe/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/grantmcdermott/etwfe/actions/workflows/R-CMD-check.yaml)
[![CRAN checks](https://badges.cranchecks.info/worst/etwfe.svg)](https://cran.r-project.org/web/checks/check_results_etwfe.html)
[![CRAN downloads](https://cranlogs.r-pkg.org/badges/etwfe)](https://cran.r-project.org/package=etwfe)
[![Dependencies](https://tinyverse.netlify.app/badge/etwfe)](https://CRAN.R-project.org/package=etwfe)
[![Docs](https://img.shields.io/badge/docs-homepage-blue.svg)](https://grantmcdermott.com/etwfe/index.html)
<!-- badges: end -->
The goal of **etwfe** is to estimate extended two-way fixed effects _a la_
Wooldridge ([2021](https://dx.doi.org/10.2139/ssrn.3906345),
[2023](https://doi.org/10.1093/ectj/utad016)). Briefly,
Wooldridge proposes a set of saturated interaction effects to overcome the
potential bias problems of vanilla TWFE in difference-in-differences designs.
The Wooldridge solution is intuitive and elegant, but rather tedious and error
prone to code up manually. The **etwfe** package aims to simplify the process by
providing convenience functions that do the work for you.
Documentation is available on the package [homepage](https://grantmcdermott.com/etwfe/).
## Installation
You can install **etwfe** from CRAN.
```r
install.packages("etwfe")
```
Or, you can grab the development version from R-universe.
``` r
install.packages("etwfe", repos = "https://grantmcdermott.r-universe.dev")
```
## Quickstart example
A detailed walkthrough of **etwfe** is provided in the introductory vignette
(available [online](https://grantmcdermott.com/etwfe/articles/etwfe.html), or
by typing `vignette("etwfe")` in your R console). But here's a quickstart
example to demonstrate the basic syntax.
Start by loading the package and some data.
```{r mpdta}
library(etwfe)
# install.packages("did")
data("mpdta", package = "did")
head(mpdta, 2)
```
**Step 1:** Run `etwfe()` to estimate a model with full saturated interactions.
```{r etwfe}
mod = etwfe(
fml = lemp ~ lpop, # outcome ~ controls
tvar = year, # time variable
gvar = first.treat, # group variable
data = mpdta, # dataset
vcov = ~countyreal # vcov adjustment (here: clustered)
)
mod
```
**Step 2:** Pass to `emfx()` to recover the ATTs of interest. In this case, an
event-study example.
```{r emfx}
emfx(mod, type = "event")
```
## Acknowledgements
- [Jeffrey Wooldridge](https://econ.msu.edu/about/directory/Wooldridge-Jeffrey) for the underlying ETWFE theory ([1](https://dx.doi.org/10.2139/ssrn.3906345), [2](https://doi.org/10.1093/ectj/utad016)).
- [Laurent Bergé](https://sites.google.com/site/laurentrberge/) ([**fixest**](https://lrberge.github.io/fixest/)) and [Vincent Arel-Bundock](https://arelbundock.com/) ([**marginaleffects**](https://marginaleffects.com/)) for maintaining the two wonderful R packages that do most of the heavy lifting under the hood here.
- [Fernando Rios-Avila](https://friosavila.github.io/) for the [`jwdid`](https://ideas.repec.org/c/boc/bocode/s459114.html) Stata module, which has provided a welcome foil for unit testing and whose elegant design helped inform my own choices for this R equivalent.