Error with staggered using Castle dataset
Closed this issue · 4 comments
kylebutts commented
I'm not sure what this error means, but could use the help.
# Castle Data
castle <- haven::read_dta("https://github.com/scunning1975/mixtape/raw/master/castle.dta")
# replace NA treatment_date with Inf
castle$treatment_date = ifelse(is.na(castle$treatment_date), Inf, castle$treatment_date)
staggered::staggered(
df = castle,
y = "l_homicide",
i = "sid",
t = "year",
g = "treatment_date",
estimand = "simple"
)
#> Error in if (varhat_conservative < 0) {: missing value where TRUE/FALSE needed
Created on 2021-07-15 by the reprex package (v2.0.0)
pedrohcgs commented
Should be fixed now. Issue was that Cohort treated in 2009 had a single unit, and that covariance was "breaking" and returning NaN. Now, I set it to 0 as covariance of a "constant" should be zero.
jonathandroth commented
I think we should drop observations with N_g = 1, because variance is not
estimable. Pretending that var(Y(g)) = 0 doesn't seem like a good solution
to me
…On Thu, Jul 15, 2021, 10:21 PM pedrohcgs ***@***.***> wrote:
Should be fixed now. Issue was that Cohort treated in 2009 had a single
unit, and that covariance was "breaking" and returning NaN. Now, I set it
to 0 as covariance of a "constant" should be zero.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#8 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AE6EXFFS6Z3SR4EHAIZ4NL3TX6XTFANCNFSM5ANU2HFQ>
.
pedrohcgs commented
After talking with @jonathandroth, we converged that we should drop cohorts with a singleton observation. Just pushed this to master.
@kylebutts let us know if this works!
kylebutts commented
Works for me!
# Castle Data
castle <- haven::read_dta("https://github.com/scunning1975/mixtape/raw/master/castle.dta")
# replace NA treatment_date with Inf
castle$treatment_date = ifelse(is.na(castle$treatment_date), Inf, castle$treatment_date)
staggered::staggered(
df = castle,
y = "l_homicide",
i = "sid",
t = "year",
g = "treatment_date",
estimand = "simple"
)
#> Warning in staggered::staggered(df = castle, y = "l_homicide", i = "sid", :
#> The treatment cohort g = 2009 has a single cross-sectional unit. We drop this
#> cohort.
#> estimate se se_neyman
#> 1 0.1461919 0.03035112 0.03958199
Created on 2021-07-17 by the reprex package (v2.0.0)