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

Can't specify constant MTRs with regression approach #210

Closed johnnybonney closed 2 years ago

johnnybonney commented 2 years ago

When trying out the new regression approach (using the version on the branch enhance/direct-regress-lp), I have found that specifying a constant MTR function (e.g., m0 = ~1) leads to an opaque error. Here is an example:

library(data.table)
library(ivmte)

set.seed(1001)
N <- 5000

dt <- data.table(
  id = 1:N,
  u = runif(N),
  z = sample(0:1, N, replace = T),
  epsilon = rnorm(N, sd = .1)
)
dt[, p := 0.12 + z * 0.48]
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]

args_test <- list(
  data = dt,
  outcome = "y",
  target = "ate",
  propensity = d ~ z,
  m1 = ~u + I(u^2) + I(u^3),
  m0 = ~1,
  solver = "gurobi"
)
res_test <- do.call(ivmte, args_test)
Solver: Gurobi ('gurobi')

Obtaining propensity scores...

Generating target moments...
    Integrating terms for control group...
    Integrating terms for treated group...

Performing direct MTR regression...
    MTR is not point identified.

Performing audit procedure...
    Generating initial constraint grid...
Error in dimnames(x) <- dn : 
  length of 'dimnames' [2] not equal to array extent
a-torgovitsky commented 2 years ago

This seems odd too, right?

Performing direct MTR regression...
    MTR is not point identified.

Since with a constant it should be point identified?

jkcshea commented 2 years ago

Hm, yes, that is odd. I will investigate this as well.

jkcshea commented 2 years ago

I have found that specifying a constant MTR function (e.g., m0 = ~1) leads to an opaque error.

Resolved! Here's what happened: I was selecting the gamma moments for m0 from a named vector. Because m0 = ~ 1, I only select the moment for the intercept. So R converted my selection into a scalar without a name. That led to some naming issues later in the code, and thus the opaque error:

Error in dimnames(x) <- dn : 
  length of 'dimnames' [2] not equal to array extent

This seems odd too, right? Since with a constant it should be point identified?

This was simply because of the binary instrument, which led to a collinear $B$ matrix. Once the instrument takes on 4 values or more, everything is point identified.

johnnybonney commented 2 years ago

Perfect - thanks for the quick fix!

a-torgovitsky commented 2 years ago

This was simply because of the binary instrument, which led to a collinear matrix. Once the instrument takes on 4 values or more, everything is point identified.

Ah I see because m1 has a cubic specification. Missed that! Thanks