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

Cannot handle NULL shape constraint arguments #150

Closed johnnybonney closed 4 years ago

johnnybonney commented 4 years ago

The function breaks if shape constraint arguments are specified as NULL. Of course, it is easy to work around this by not specifying the argument at all, but my understanding is that it is pretty standard to allow for this kind of thing.

set.seed(1001)
N <- 2000

dt <- data.table(
  id = 1:N,
  u = runif(N),
  z = sample(1:4, N, replace = T),
  epsilon = rnorm(N, sd = .1)
)

dt[, p := (z == 1)*0.12 + (z == 2)*0.29 + (z == 3)*0.48 + (z == 4)*0.78]
dt[, d := as.integer(u <= p)]
dt[, y0 := 0.9 - 1.1*u + 0.3*u^2]
dt[, y1 := 0.35 - 0.3*u - 0.05*u^2]
dt[, y := y1*d + y0*(1 - d) + epsilon]

res <- ivmte(data = dt,
             propensity = d ~ factor(z),
             ivlike = c(y ~ d, y ~ factor(z)),
             target = "ate",
             lpsolver = "gurobi",
             m1 = ~u,
             m0 = ~u,
             m1.inc = NULL) # or m0.inc, m0.dec, m1.dec, mte.dec, mte.inc
LP solver: Gurobi ('gurobi')

Obtaining propensity scores...
Generating target moments...
    Integrating terms for control group...
    Integrating terms for treated group...
Generating IV-like moments...
    Moment 1...
    Moment 2...
    Moment 3...
    Moment 4...
    Moment 5...
    Moment 6...
Performing audit procedure...
    Generating audit grid...
 Error in if (try(m1.inc, silent = TRUE) == TRUE) { : 
  argument is of length zero 
jkcshea commented 4 years ago

Ah, this is something I had forgotten to check.

I've now incorporated a check to make sure that the monotonicity constraints are declared using only TRUE or FALSE (so NULL is not allowed), and that the shape constraints are declared using only numerical values.