Endogenous switching regression models