You get shocked when you touch a metal doornob after rubbing your feet on a rug because all the negative energy from the rug goes to your body. But your body wants to have an even number of positive and negative energy so the extra negative energy that came from the rug goes out of your body by shocking you. Then the negative energy goes into the air so that the earth is equal.
You get shocked because all of the negative energy from the rug goes inside of your body. Just like Tara said your body wants to have an equal amount of positive and negative energy. By rubbing your feet on the carpet extra negative energy is coming in to your body and when you touch a door nob all of that negative energy comes out of your body and shocks you!
You get shocked after you touch a metal doorknob after rubbing your feet on the rug. That happens because the negative energy from the rug goes to your body. When you touch a metal doorknob the negative energy goes from your body to the metal doorknob. The doorknob will then have the negative energy that you used to have in your body. That's how that happens to a human, a metal doorknob, and a rug when you get shocked.