I don’t think any one answer is optimal. I got a nice new car and kept it 12+ years. The advantage to this is minimizing transaction costs while getting exactly the car I wanted. I also drive far less than most people keeping the car in great shape.
If I put a lot more miles in it then I would be more concerned with break downs as it aged.
The beater is often just as poor an investment due to the money you'll have to throw into it like a black hole whenever it fails. There's also the stress and instability it creates knowing it may not start the next morning.