Holding in your cough is not good because when you're coughing it's your bodies way of getting rid of irritants and other bad things in your lungs.
So by suppressing your cough you prevent those irritants and bad things from leaving your lungs which can be bad.
When you need to cough you should cough but cover your mouth if you're around other people and wash your hands after coughing to get rid of germs.
Coughing helps get rid of bacteria and germs in your lungs to make it easier to breathe better so avoid holding in your cough because it's not a good idea.