In Starcraft 2, the biggest questions players usually have is “when can I attack?” or “when am I safe to move out on the map?” or “when can I get all my units together and end the game?” Notice how the focus in all these questions is on attacking.
A very important tip to remember is that sometimes you should be retreating – not constantly attacking. Being able to force engages when you have a winning army is definitely important, but being able to recognize when you are behind in army/tech or out of position on the map and retreat all the way back home can be equally important.
It is completely fine to sacrifice a small portion of your army in order to retreat with the rest of your main army and live to fight another fight. Just be sure that you either always have an escape path (either via Mothership Core recall, a Siege Tank line to fall back onto, Fungal Growth to hold your opponent back, etc) or a very mobile army that can just Blink/Stim/Run on creep away from a fight. Retreating and saving the majority of your army will buy you time to recover as well as not instantly lose the game.