I think it is natural for all beings to imitate. We generally copy what others do. To copy bad things is harmful, but to copy good things from others is useful.
Learned I think. Our parents and the media tell us that certain people behave in certain ways and we tend to get used to these models. I think animals survival instincts are purely based on sensory perception though, not stereotyping. For example they wouldn't be able to fear things that they couldn't sense, they wouldn't be able to pre-judge.