jkcshea / ivmte

An R package for implementing the method in Mogstad, Santos, and Torgovitsky (2018, Econometrica).
GNU General Public License v3.0
18 stars 2 forks source link

Error when knots are 0 or 1 #226

Closed johnnybonney closed 2 years ago

johnnybonney commented 2 years ago

If spline knots are included at 0 or 1, I get an unclear error about splines. This has happened a few times to me when I define knots based on the distribution of propensity scores, and end up with 0's or 1's. The error is specific enough that one should be able to intuit what's going on, but I admit it took me a minute the first couple of times...

It might be more informative to have ivmte throw the error directly, saying that knots can't be at 0 or 1.

Here's an example:

library(ivmte)

args <- list(data = AE,
             outcome = "worked",
             propensity = morekids ~ factor(samesex),
             m0 = ~uSplines(degree = 3, knots = c(0, 0.5)),
             m1 = ~uSplines(degree = 3, knots = c(0, 0.5)),
             target = "ate",
             solver = "gurobi")
est <- do.call(ivmte, args)

prints

Obtaining propensity scores...

Generating target moments...
    Integrating terms for control group...
    Integrating terms for treated group...
Error in rcpp_bSpline_integral(x = xx, df = df, degree = degree, internal_knots = knots,  : 
  Internal knots must be set inside boundary.
a-torgovitsky commented 2 years ago

Better would be to not throw an error at all? We should be able to detect that there are duplicated 0's and/or 1's and remove them

jkcshea commented 2 years ago

Done!

We should be able to detect that there are duplicated 0's and/or 1's and remove them

This is what we do now.