Earth has a molten core of a conductive metal i.e. The iron ore still in circulation in the earth. The earth has two pole the South and the North and functions like an ordinary compass. The magnetic field is created by the flow of these iron ore in the center of the Earth or the Earth's core.
The earths magnetic field comes from the earths moving iron core... Or at least thats what scientists think so far. There is evidence because scientists have tested their hypothesis using a model of earth with what we think is in the inner core. The model had the cores moving around and a small magnetic field was created by this model. This hypothesis turned into a theory and gives evidence of why we have a magnetic field. JOIN BROAD SCIENCE GROUP IN THE SCIENCE CATEGORY IF YOU HAVE MORE QUESTIONS