So frequently, I find myself raiding the enemy base with some fast harasser unit (example: Mutalisks) and I find that the enemy mineral line is defended in some way (example: marines/photon cannons). Now I know that each Mutalisk costs me 100 crystal and 100 gas, but I also know that each Collector costs my opponent 50 crystal + all the resources it will ever collect for the rest of the game. So the question is, how can you determine how many Collectors you should kill for some value of raiding force for the loss of the raiding force to be 'worth it'?
The mechanics and mathematics behind certain strategies can be discusses for days upon end in Starcraft. I like to take a different route when giving advice to friends.
How many times have you ragequit from a match because you felt defeated and then went back to view the replay...and found out that if you had retained a cool head, built up your economy/units and counterattacked, you would have won easily? Forcing your opponent to feel like they are losing the game (whether they are actually losing or not) can turn the tide more than crazy APM or micro.
For example: With an MMM build, Terrans are afforded huge map control and harassment potential. The ability to drop your Marines and Marauders in a key location (such as the enemy mineral line), keep them healed up, and get away unscathed will wear at your opponent greatly over time, giving you openings to take advantage of your opponent's mistakes. They might overproduce military units, allowing you to take the economic advantage. Your foe might overcompensate with drop defense and take too many units back to defend the line, giving you a clear avenue to attack straight-up.
My answer is this: Forcing your opponent to feel disorganized, frustrated, and off-balance is worth a hell of a lot more than several times the cost of a few units thrown out to die.
This is a relatively open question, because there is a big variety of raids. Doing the math is far beyond my ability/motivation level as well, so my answer is mostly subjective. Let's divide this into several cases:
An early game raid. This contains mostly mineral units and is done when the enemy has a single base (or two, if they're playing early expand). Minerals for drones are still relatively limited, making them highly valuable. I'd argue that killing even a third of the drones' cost compared to the force you lose is an even trade. If you're using three upgraded hellions for example, their cost would be 3x100+1x150, plus 150 gas, which could be converted to about 500 minerals. Thus, for the raid to have been worth your trouble, you would want to have killed at least 7 drones. The same calculation applies if you're using a dropship, as you are unlikely to use it, and it can be integrated into your army composition. The raid itself is a risk - it's harder to survive while teching for hellions and it costs more APM than a more orthodox approach, and you also want to win, not to make even trades. Thus, while 7 drones is "sufficient", it's far from enough. Additionally, you don't really want to lose the hellions - while it's tempting to suicide them and never worry about the fragile speedsters again, pulling them out at the right time will put your opponent on edge, force him to watch his back, and let you reuse them on some unguarded expansion later in the game. This is doubly true for early-game raids with less gimmicky units which can immediately join your standing army, provided they are fast enough to escape.
A late game raid. Mechanics here are completely different. Drones cost less, because they can be replaced much faster, leading to significant decrease in the long-term yield decrease, so much that it becomes a short-term yield decrease. You'd also likely be killing inefficient "third" drones, which have a reduced yield to start with (saturation). The rule from the previous situation applies doubly - try to save your raiders. Also heavily consider the gas and APM costs, as these resources are the main limiters at this stage of the game. A marine drop is cheap on gas, can assault any undefended expansion, and is easy to pull out - it is also heavy on micro.
tl;dr: Pull out early, losing raiders is a failure. You should only be killing drones when you're not being shot upon by a superior force, and if one approaches, retreating in time and coming back later/attacking another base is better than trying to get just one more drone (reminds me of the sunk cost fallacy, because you aren't sacrificing a drop for ten drones, you're sacrificing it for the last two that you wouldn't kill if you retreated early, a fact that makes any wiped out harass with sufficient unit mobility a failure). For land units in the early game that can't survive a raid (speedlings that end up in the mineral line because the enemy army was having a field trip somewhere), killing a third of their cost in drones should end up as a (subjectively) even trade. For a similar situation in the end game, drones become only as valuable as normal units, sometimes even cheaper, and the only way for harass to have a significant effect is for it to happen multiple times, killing off the drones in many enemy bases consequtively.
It depends a lot from the type and the number of units you use for harass. For instance, a pack of 7 mutalisks must kill a lot more that 10 zerglings to pay for itself.
I think a good rule of thumb is you have to kill for the same amount of resources your harass units cost you. For instance 10 zerglings => 5 collectors, 8 mutalisks => 32 collectors (and/or 1600 worth of resources of pylons/overlord/depots, tech, production, ...)
The value of a good harass is also that it allows you to force your opponent into defense mode, which allows you to expand, attack elsewhere while he backs to defend, etc. This cannot be evaluated in terms of kills.