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:
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.