One sided formula & ModelMatrix



I’m trying to write some 2SLS code, and ran into the following scenarios:

I have a one-sided formula and a DataFrame. Is there a simple way to get the model matrix given that formula? The @formula macro throws an error without a LHS.

Similarly, if the formula is two sided, can I get a vector for the dependent variable? The ModelMatrix(ModelFrame(@formula(…), df)).m strategy doesn’t supply the dependent variable. Getting this vector is non-trivial since the validity of dependent variable data points is affected by the presence of NAs on both sides of the formula.