Open MatthieuStigler opened 1 year ago
Also add N treated/control, needs version 0.2.4 !
library(multiDiff)
suppressPackageStartupMessages(library(texreg))
extract_mdd_DiD <- function(model, add_para = FALSE, include.n_treated = TRUE, ...) {
extr_out <- texreg:::extract.fixest(model, ...)
if(include.n_treated){
mdd_slot <- multiDiff:::intrnl_mdd_get_mdd_slot(model)
if(mdd_slot$n_seq!=2) stop("Arg. `include.n_treated` only works for standard DiD")
extr_out@gof.names <- c(extr_out@gof.names, "N control:", "N treated:")
extr_out@gof <- c(extr_out@gof, mdd_slot$n_units-mdd_slot$n_treated, mdd_slot$n_treated)
extr_out@gof.decimal <- c(extr_out@gof.decimal, FALSE, FALSE)
}
if(add_para) {
if(!all(c("para_test_joint_pval", "para_test_joint_pval") %in% names(model))) stop("Ooutput should have added slot 'para_test_joint'")
extr_out@gof.names <- c(extr_out@gof.names, "Parallel test: Wald stat", "Parallel test: p-val")
extr_out@gof <- c(extr_out@gof, model$para_test_joint_val, model$para_test_joint_pval)
extr_out@gof.decimal <- c(extr_out@gof.decimal, TRUE, TRUE)
}
extr_out
}
DID_dat <- mdd_data_format(sim_dat_common(timing_treatment = 5:10))
mdd_out <- mdd_DD_simple(DID_dat)
setMethod("extract", signature = className("mdd_DiD", "multiDiff"), definition = extract_mdd_DiD)
screenreg(mdd_out, include.n_treated=TRUE)
#>
#> ===================================
#> Model 1
#> -----------------------------------
#> tr 1.03 ***
#> (0.04)
#> -----------------------------------
#> Num. obs. 10000
#> Num. groups: unit 1000
#> Num. groups: Time 10
#> R^2 (full model) 0.67
#> R^2 (proj model) 0.05
#> Adj. R^2 (full model) 0.63
#> Adj. R^2 (proj model) 0.05
#> N control: 750
#> N treated: 250
#> ===================================
#> *** p < 0.001; ** p < 0.01; * p < 0.05
Created on 2023-06-13 with reprex v2.0.2
Function for synthdid:
extract.synth <- function(model) {
## this has more slots, but much slower
# s <- summary(model)
# names <- rownames(s$coef)
## simple way
out <- tidy(model)
co <- out$estimate
se <- out$std.error
pval <- out$p.value
# rs <- s$r.squared
# adj <- s$adj.r.squared
# n <- nobs(model)
# gof <- c(rs, adj, n)
# gof.names <- c("R$^2$", "Adj.\\ R$^2$", "Num.\\ obs.")
tr <- createTexreg(
coef.names = "treat_status",
coef = co,
se = se,
pvalues = pval,
# gof.names = gof.names,
# gof = gof
)
return(tr)
}
setMethod("extract", signature = className("synthdid_estimate", "multiDiff"), definition = extract.synth)
first attempt with https://github.com/MatthieuStigler/multiDiff/commit/cf549729e03d856e6055e38abf8b7b3e65f6869c, but:
multiDiff:::extract.gsynth
To be used with:
setMethod("extract", signature = "gsynth", definition = multiDiff:::extract.gsynth)
latest code for others: see ETH/Projects/Indonesia ZDC effect/IND_ZDC_deforest_impact_ana/code_setup/888_txrg_scripts_texreg.R
Here's one possibility, should think about how to add the para test!?
Created on 2023-06-07 with reprex v2.0.2