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...
Solver: Gurobi ('gurobi')
Generating initial constraint grid...
Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more levels
This is because of the following:
The initial grid is a design matrix constructed using a random sample from the support of the covariates.
In this example, you sampled only one value of x2.
However, the MTR formulas involve the term factor(x2).
So R throws an error since it is expecting at least 2 values of x2.
This can be corrected by checking the support of factor variables when constructing the initial grid, and adjusting the MTR formulas as necessary.
This is actually done in mst.R:
The following specification generates an error.
Here is the output.
This is because of the following: The initial grid is a design matrix constructed using a random sample from the support of the covariates. In this example, you sampled only one value of
x2
. However, the MTR formulas involve the termfactor(x2)
. So R throws an error since it is expecting at least 2 values ofx2
.This can be corrected by checking the support of factor variables when constructing the initial grid, and adjusting the MTR formulas as necessary. This is actually done in
mst.R
:https://github.com/jkcshea/ivmte/blob/7c67a265deb70e735f2b521ebc1733c8af822cf3/R/mst.R#L2090-L2106