Hello Dear,
You are right. Eating mud, clay or soil could be an instinctive action to balance some mineral or
vitamin deficiency or to enhance the mineral absorption which eventually could have become a strong habit which stays even in the absence of deficiency. After all every plant gets most of it's nutrients from soil and even carnivorous animals eat herbivorous animals to get those nutrients. We humans usually tend to get those nutrients through specific secondary sources because of our limitations of digestion mechanism. You need to follow few steps to address this tendency. Firstly get tested in detail for the vitamin and mineral levels in your body and notice the deficiency if there is any. Second step is to understand the habit better and find ways to replace it with a healthier habit. After getting tests it would be of help to consult a psychologist to assist you through this strong instinctive habit. Take Care.