Skip to content

Commit 7156a90

Browse files
committed
update DIDmultiplegt code
1 parent e81bad1 commit 7156a90

3 files changed

Lines changed: 17 additions & 14 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ Package: rdssbook
22
Title: Research Design: Declare, Diagnose, Redesign
33
Version: 0.0.1
44
Suggests: pak, ggcorrplot, modelr, ICC, gt, ggspatial, GGally, psych, rdrobust, DIDmultiplegt, car, checkpoint, dagitty, downlit, dplyr, estimatr, fabricatr, forcats, ggdag, ggforce, ggplot2, ggraph, ggrepel, ggridges, ggtext, glmnet, glue, grid, gridExtra, haven, jsonlite, kableExtra, knitr, latex2exp, lme4, magrittr, MASS, metafor, patchwork, prediction, purrr, randomizr, Rcpp, readr, remotes, reshape2, rmarkdown, rprojroot, rr, sf, shiny, stringr, texreg, tibble, tidyr, tidyverse, xml2, broom.mixed, parsermd, rstanarm, CausalQueries, DeclareDesign, DesignLibrary, ragg, margins, MatchIt, cjoint, spdep, grf, bbmle, rdss, vayr, dddag, randnet, interference
5-
Remotes: acoppock/vayr, DeclareDesign/dddag, cran/randnet, szonszein/interference, cran/DIDmultiplegt, cran/cjoint
5+
Remotes: acoppock/vayr, DeclareDesign/dddag, cran/randnet, szonszein/interference

errata.qmd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ These errata are errors in the printed book. These changes are implemented in th
2121
We are committed to maintaining the code in this book as the R ecosystem evolves. The following changes reflect differences between the printed book and the online version.
2222

2323
- On pg. 103, Declaration 9.3 now reads `.summary = ~tidy(., exponentiate = TRUE)` instead of `.summary = ~tidy_stan(., exponentiate = TRUE)`, reflecting the use of the standard `broom.mixed` package for tidying stan objects. In addition, the library `rdss` is replaced with the library `broom.mixed` in the declaration.
24+
- On pg. 212-213, Declaration 16.3 now uses updated syntax from the `DIDmultiplegt` package, specifically `mode = 'old'` is added. We also add `Sys.setenv(RGL_USE_NULL = TRUE)` to address package dependency issues.
Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
library(rdss) # for helper functions
2+
Sys.setenv(RGL_USE_NULL = TRUE) # required to use DIDmultiplegt
23
library(DIDmultiplegt)
34

45
N_units <- 20
56
N_time_periods <- 20
67

7-
declaration_16.3 <-
8+
declaration_16.3 <-
89
declare_model(
910
units = add_level(
10-
N = N_units,
11-
U_unit = rnorm(N),
11+
N = N_units,
12+
U_unit = rnorm(N),
1213
D_unit = if_else(U_unit > median(U_unit), 1, 0),
1314
D_time = sample(1:N_time_periods, N, replace = TRUE)
1415
),
@@ -18,21 +19,21 @@ declaration_16.3 <-
1819
nest = FALSE
1920
),
2021
unit_period = cross_levels(
21-
by = join_using(units, periods),
22+
by = join_using(units, periods),
2223
U = rnorm(N),
23-
potential_outcomes(Y ~ U + U_unit + U_time +
24-
D * (0.2 - 1 * (D_time - as.numeric(periods))),
24+
potential_outcomes(Y ~ U + U_unit + U_time +
25+
D * (0.2 - 1 * (D_time - as.numeric(periods))),
2526
conditions = list(D = c(0, 1))),
2627
D = if_else(D_unit == 1 & as.numeric(periods) >= D_time, 1, 0),
2728
D_lag = lag_by_group(D, groups = units, n = 1, order_by = periods)
2829
)
2930
) +
3031
declare_inquiry(
31-
ATT = mean(Y_D_1 - Y_D_0),
32+
ATT = mean(Y_D_1 - Y_D_0),
3233
subset = D == 1
33-
) +
34+
) +
3435
declare_inquiry(
35-
ATT_switchers = mean(Y_D_1 - Y_D_0),
36+
ATT_switchers = mean(Y_D_1 - Y_D_0),
3637
subset = D == 1 & D_lag == 0 & !is.na(D_lag)
3738
) +
3839
declare_measurement(Y = reveal_outcomes(Y ~ D)) +
@@ -43,11 +44,12 @@ declaration_16.3 <-
4344
label = "twoway-fe"
4445
) +
4546
declare_estimator(
46-
Y = "Y",
47-
G = "units",
48-
T = "periods",
47+
Y = "Y",
48+
G = "units",
49+
T = "periods",
4950
D = "D",
51+
mode = "old",
5052
handler = label_estimator(did_multiplegt_tidy),
5153
inquiry = c("ATT", "ATT_switchers"),
5254
label = "chaisemartin"
53-
)
55+
)

0 commit comments

Comments
 (0)