The simple gold cost of upgrading vs. buying anew should be readily analyzable, but the wild-cards in the analysis are usually "squishier" questions, like (1) do the obsolete units have promotions that you want to preserve?, (2) does the intermediate unit on the upgrade path require a resource you don't have (or that is in short supply) but the final upgraded unit does not (or requires a different resource that you have in abundance) (e.g., warrior to swordsman to musketman to infantry)?, and (3) if the alternatives are upgrade immediately for gold vs. train new units with production over many turns (assuming you have the best policy cards available for each alternative), can you afford the time to train new units, or do you need the upgraded units now? I've probably omitted other factors to consider (e.g., faith-buying alternatives), but I don't think there is an easy rule of thumb, like "1 upgrade is always worth it, but 2 or more are not".