When showing chemical formulas for compounds, how do i know how many electrons an element gives up in it's outer level, or how many electrons an element gains in it's outer level?

Elements in group I have 1 electron in their outside shell; they give up 1 e to become +1 valence.

Elements in group 2 have 2 electrons in their outside shell; they give up 2 e to become +2 valence. Group 13 (group IIIA)becomes +3 by the same reasoning.
On the other side of the table, group 17 elements (or VIIA depending upon the system you are using) have 7 electrons in the outside shell; they will ADD 1 e to complete the octet to have a valence of -1.
Elements in group 16 (VIA) have 6 electrons in their outside shell; they will ADD 2 e to become -2 valence. Do you see that Group 1 has 1 e, group 2 has 2 e, group 13 has 3 e, group 16 has 6 e, group 17 has 7. What could be easier? However, before we make it too easy, not all of the columns can be treated that way. All of the A groups (if you use that system) will have that number of electrons in the outside shell OR 1,2, and the second number of 13(that would be 3), 14 (that would be 4), 15 (that would be 5) etc through 16, 17, 18 if you use the other system.