A Generalization of the Endogenous Grid Method