Closed mariofiorini closed 6 months ago
Thanks for reporting @mariofiorini.
IIRC this is an upstream limitation of marginaleffects. For example, see @vincentarelbundock's comment here about "group" being a reserved word. Vincent, is this still the case? Either way, I can a t least document it better.
Yes, upstream does have that limitation and I am afraid it will not be relaxed.
Sorry for the long delay on this, but it should be fixed if you grab the dev version now. Specifically, the fix:
etwfe
model formula.Illustration of the former case:
library(etwfe)
data("mpdta", package = "did")
mod =
etwfe::etwfe(
fml = lemp ~ lpop, # outcome ~ controls
tvar = year, # time variable
gvar = first.treat, # group variable
data = mpdta, # dataset
vcov = ~countyreal # vcov adjustment (here: clustered)
)
etwfe::emfx(mod)
#>
#> Term Contrast .Dtreat Estimate Std. Error z Pr(>|z|)
#> .Dtreat mean(TRUE) - mean(FALSE) TRUE -0.0506 0.0125 -4.05 <0.001
#> S 2.5 % 97.5 %
#> 14.3 -0.0751 -0.0261
#>
#> Columns: term, contrast, .Dtreat, estimate, std.error, statistic, p.value, s.value, conf.low, conf.high, predicted_lo, predicted_hi, predicted
#> Type: response
mpdta$group <- mpdta$countyreal
mod2 =
etwfe::etwfe(
fml = lemp ~ lpop, # outcome ~ controls
tvar = year, # time variable
gvar = first.treat, # group variable
data = mpdta, # dataset
vcov = ~countyreal # vcov adjustment (here: clustered)
)
etwfe::emfx(mod2)
#>
#> Term Contrast .Dtreat Estimate Std. Error z Pr(>|z|)
#> .Dtreat mean(TRUE) - mean(FALSE) TRUE -0.0506 0.0125 -4.05 <0.001
#> S 2.5 % 97.5 %
#> 14.3 -0.0751 -0.0261
#>
#> Columns: term, contrast, .Dtreat, estimate, std.error, statistic, p.value, s.value, conf.low, conf.high, predicted_lo, predicted_hi, predicted
#> Type: response
Created on 2024-02-23 with reprex v2.1.0
ok thanks
Hi @grantmcdermott, just noticed a possible bug? If the data being used already has a variable named "group" then the
emfx()
function does not seem to aggregate the effects. In the example below, I first run the same example that you have on your website, soemfx()
works as expected, and then modify the data adding a variable named group. Note that this new variable is not used in theetwfe()
function, and yetemfx()
does not aggregate the results. Cheers, Mario