Elliptic flow in heavy ion collisions at varying energies: Partonic versus hadronic dynamics