My daughter started doing this to sooth herself at around 20 months or so. She used to rub her hair while I was nursing her and I guess she just transferred the habit after the nursing ended. She was eating it for a while but that seems to have stopped. But she did begin to wear a bald spot on her head. I took her to the doc and she recommended taking her to the store to buy her (have her pick out) a special "sleeping cap" I just picked out a few of the cotton knit caps we already had and let her pick our her own sleepy cap. We also let her pick out a doll with "human like" hair. She now asks for her sleepy cap everynight and at naptime and it keeps her from pulling her hair and if she really needs soothing she uses the doll instead. Every once in a while she reverts back but it is MUCH better than it was.
Sounds like either anxiety/self soothing or some sort of sensory integration issue. I wonder if there's any evidence for craving hair due to a vitamin/nutrient deficiency...? Just a shot in the dark.
Whatever the case, it's pretty dangerous for her to be eating hair and other stringy things and you should see a doctor if you haven't already. Hair can not be digested, which is why you're seeing it in her stool. Unfortunately, you may or may not be seeing all of this material get passed through her system. I am not trying to scare you, but you should be aware that accumulation of hair (or any undigested material) in the digestive tract can pose a serious health risk.