Comments (6)
Hi, @grantmcdermott
Nice! Thank you for providing the new version!
from etwfe.
Hi @paulofelipe, sorry this completely slipped through the cracks. I only saw it again now after responding to another issue. There's a lot going on in the above code. Can you simplify it and just highlight the key discrepancy that you're wondering about? That will make it easier for me to help you.
from etwfe.
Hi, @grantmcdermott. I apologize for not being concise in my initial question. My doubt pertains to the value obtained for the Simple ATT using the following code:
library(did)
library(etwfe)
library(broom)
library(stringr)
library(marginaleffects)
library(fixest)
library(dplyr)
mpdta <- did::mpdta %>%
mutate(
.Dtreat = treat * (year >= first.treat),
time_to_event = ifelse(first.treat != 0, year - first.treat, -1000)
)
etwfe_never <- etwfe(
fml = lemp ~ 1,
tvar = year,
gvar = first.treat,
data = mpdta,
ivar = countyreal,
cgroup = "never"
)
emfx(etwfe_never, "simple") %>%
tidy() %>%
print()
#> # A tibble: 1 × 13
#> term contrast .Dtreat estimate std.error statistic p.value s.value conf.low
#> <chr> <chr> <lgl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 .Dtreat mean(TR… TRUE -0.00166 0.00489 -0.339 0.735 0.445 -0.0112
#> # ℹ 4 more variables: conf.high <dbl>, predicted <dbl>, predicted_hi <dbl>,
#> # predicted_lo <dbl>
slopes(
model = etwfe_never,
newdata = mpdta %>% filter(.Dtreat == 1),
variable = ".Dtreat",
by = ".Dtreat"
) %>%
print()
#>
#> Term Contrast .Dtreat Estimate Std. Error z Pr(>|z|)
#> .Dtreat mean(TRUE) - mean(FALSE) 1 -0.0404 0.0196 -2.06 0.0396
#> S 2.5 % 97.5 %
#> 4.7 -0.0789 -0.00193
#>
#> Columns: term, contrast, .Dtreat, estimate, std.error, statistic, p.value, s.value, conf.low, conf.high, predicted, predicted_hi, predicted_lo
The obtained result (-0.00166) using the “never treated” group as the control diverges significantly from that obtained using the “not yet treated” control group (-0.0477) and from the manually calculated simple ATT values (-0.0404) using the marginaleffects package. Perhaps the code I used with the slopes() function is incorrect, but I can replicate the results (using emfx and slopes) when I change to cgroup = "notyet" in the etwfe() function.
Thanks in advance.
from etwfe.
Ah, I see. Thanks @paulofelipe. I think this might be a subsetting bug for the never-treated case. Let me dig a little deeper and confirm.
from etwfe.
Hi again @paulofelipe. Thanks again for reporting this and bearing with my tawdry response. It was indeed a bug, so I'm very grateful that you brought it to my attention. It should be fixed now if you grab the latest development version.
Quick MWE based off of your example.
library(etwfe)
data("mpdta", package = "did")
etwfe_never = etwfe(
fml = lemp ~ 1,
tvar = year,
gvar = first.treat,
data = mpdta,
ivar = countyreal,
cgroup = "never"
)
emfx(etwfe_never, "simple")
#>
#> Term Contrast .Dtreat Estimate Std. Error z Pr(>|z|)
#> .Dtreat mean(TRUE) - mean(FALSE) TRUE -0.04 0.0118 -3.39 <0.001
#> S 2.5 % 97.5 %
#> 10.5 -0.0631 -0.0168
#>
#> Columns: term, contrast, .Dtreat, estimate, std.error, statistic, p.value, s.value, conf.low, conf.high, predicted_lo, predicted_hi, predicted
#> Type: response
emfx(etwfe_never, "event")
#>
#> Term Contrast event Estimate Std. Error z Pr(>|z|)
#> .Dtreat mean(TRUE) - mean(FALSE) -4 0.00331 0.0246 0.135 0.89289
#> .Dtreat mean(TRUE) - mean(FALSE) -3 0.02502 0.0182 1.378 0.16812
#> .Dtreat mean(TRUE) - mean(FALSE) -2 0.02446 0.0143 1.714 0.08646
#> .Dtreat mean(TRUE) - mean(FALSE) -1 0.00000 NA NA NA
#> .Dtreat mean(TRUE) - mean(FALSE) 0 -0.01993 0.0119 -1.681 0.09277
#> .Dtreat mean(TRUE) - mean(FALSE) 1 -0.05096 0.0169 -3.020 0.00252
#> .Dtreat mean(TRUE) - mean(FALSE) 2 -0.13726 0.0366 -3.751 < 0.001
#> .Dtreat mean(TRUE) - mean(FALSE) 3 -0.10081 0.0345 -2.922 0.00348
#> S 2.5 % 97.5 %
#> 0.2 -0.0448 0.05143
#> 2.6 -0.0106 0.06060
#> 3.5 -0.0035 0.05242
#> NA NA NA
#> 3.4 -0.0432 0.00331
#> 8.6 -0.0840 -0.01789
#> 12.5 -0.2090 -0.06554
#> 8.2 -0.1684 -0.03318
#>
#> Columns: term, contrast, event, estimate, std.error, statistic, p.value, s.value, conf.low, conf.high, predicted_lo, predicted_hi, predicted
#> Type: response
Created on 2024-02-25 with reprex v2.1.0
from etwfe.
Fixed version (v0.4.0) is up on CRAN now too.
from etwfe.
Related Issues (20)
- Interacted Treatment Effect HOT 2
- .Dtreat should be logical instead of integer
- Allow time-varying covariates
- marginaleffects slow in large data sets HOT 8
- emfx could be smarter about xvar
- Error: Error in variable_classes[[v$name]] : subscript out of bounds HOT 6
- Two errors: (1) "Warning message: The demeaning algorithm did not converge, the results are not reliable. (tol: 1e-06, iter: 2036)" and (2) "Error: Class of the `.Dtreat` variable is class is not supported." HOT 4
- `marginaleffects` 0.10.0 is on its way to CRAN HOT 1
- Error: The function supplied to the `transform_pre` argument must accept two numeric vectors of predicted probabilities of length 0, and return a single numeric value or a numeric vector of length 0, with no missing value. HOT 2
- emfx() error when using offset in Poisson HOT 21
- Query RE Heterogeneous treatment effects HOT 13
- Error: Class of the `.Dtreat` variable is class is not supported. HOT 10
- Inference using fixest's aggregate command HOT 7
- Anticipation HOT 1
- Lee and Wooldridge HOT 1
- emfx() not aggregating when the data already includes a variable named 'group' HOT 4
- Including weights? HOT 1
- Interaction with continuous variable HOT 5
- Error when trying to use emfx function. "Models of class "etwfe" are not supported." HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from etwfe.