jonathandroth/staggered

Error with staggered using Castle dataset

Closed this issue · 4 comments

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)

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.

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!

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)