Endogenous Switching Regression Models for the Causes and Effects of Discrete Variables