They do, when they can. But often they can't. A patent covers not just the molecule, but the treatment. Often, they would need to license the original patent even if they have the more advanced molecule, and they can't get the license.
So the cost of educating consumers (marketing) is not offset by the difference in cost of selling the generic and the cost of selling the new patented version?
Patients aren't really equipped to make this decision. It's made by doctors and by insurance companies. They are often reluctant to prescribe/pay for the "almost as good and a lot cheaper" drug, for fear of exposing themselves to risk. Generics manufacturers don't usually have the influence to convince them otherwise.
There's also the regulators. If the drug manufacturer can convince the regulator that the old drug is dangerous, they can simply forbid it.