The answer depends a few factors, all of which need to be considered and weighed according to importance and skill:

Sentimental Value:
Sometimes a vehicle is more than just “a vehicle.” Perhaps it was your first, maybe it was given to you by a parent or friend or someone who’s no longer around. Whatever the reason, the vehicle’s value is thus much higher than any estimate will place it. Even though there are limits to what people might be willing to do, this is one of the biggest reasons folks will keep a vehicle around, but, also the least common reason.

Mechanical Skill:
One’s ability to do automotive work can really play into keeping on-going maintenance costs down. The more confident the person, the more money can be saved - to a point. This only saves on labour - not the overall cost. If the vehicle still needs a ton of pricey parts, there’s still a point at which the cost to keep it working could get too high. That said...

Operating Cost vs. Market Value:
So... whether you are doing your own work or getting it done professionally, there is a point at which the cost could get close to (or exceed) the value of the actual vehicle. This is a bit of a make/break moment to me; If you had to drop $7000 into a vehicle, and if you had to sell it the next day and knew you wouldn’t get anywhere near that for it... likely wiser to put that $7K into a newer/better vehicle. Sometimes just normal operating costs play into this as well. If your older vehicle is a big heavy V8-powered monster with a 3 or 4 speed transmission, chances are fuel tankers are following you around with big grins on their faces. 20 years ago, it wasn’t so bad, but with today’s insane fuel prices, you may find that the fuel savings alone could fund 50% or more of a new car payment.

Age vs. Part Availability:
As vehicles get older, the availability of parts begins to drop off. This is a particularly challenging issue with newer cars than, say classics from the 1980s and prior. Newer vehicles tend to have more parts and more complexity to their engines and internals due to higher levels of technology. Those parts are produced for only a short while by the manufacturer, and then later only if other companies see a market opportunity to produce after-market equivalents. For a vehicle that is popular, this might not be as hard as for one that was not. So... finding parts for a 1998 Mustang may not be so bad, but a 1998 Neon... good luck with that. (Also why would you have a 1998 Neon? Why?) 

One of the biggest ways to avoid operating costs is to have a reliable vehicle. Which brands, and more specifically, which vehicles from those brands, are reliable varies from year to year. If you have a very reliable vehicle, there may not be much in the way of maintenance costs until well into the vehicle’s service life.  My mother’s Toyota 4Runner, for example, has never had a mechanical issue or required any major service outside of general stuff for a decade now.  My neighbour’s Mercedes began having almost monthly issues by the time it was just 5 years old.

My Own Examples:
1975 Pontiac Laurentian (Catalina to Americans): Enjoyed for many years, and looked pristine even the day I sold it for scrap in 2006. The problem here was the cost to keep it safely on the road. Despite a life time of oil sprays and careful care/treatment nature finally got the better of it and caused damage on the chassis around the rear body mounts. The only way to properly repair it was a full body-off restoration, which would run about $12,000. That doesn’t even tough on interior, engine or anything else. It was many times more than it was worth, so it was time to say good-bye to the 18'10" monster.

2003 Dodge Dakota: This apart from some rust in the wheel wells (which I closed over with sheet metal and repainted) this truck looked brand new inside and out when I got rid of it in 2015. Why did I? Well, I knew within the next year, it needed both new summer and winter tires, new coil springs in the front, new shocks all around, and new brake pads and rotors in the front. Within the next 2 years, it’d probably also need a new exhaust manifold on the driver side, and a new bed as my repair was already showing signs of dying. The cost was enormous, and the 4.7L H.O. V8 got the gas mileage equivalent of a Falcon 9 rocket (with considerably less power). It just didn’t make sense to keep it anymore.

So in the end, all these factors have to be considered. Some vehicles may outlive their useful value in a decade, some may last more than two.  A little bit of logic and reason will often reveal the best path.