Earth has a magnetic field primarily because it has Nickel (Ni) and Iron (Fe) in its outer core. The movement of these molten metals generates electric currents, which in turn produce magnetic fields. This phenomenon is known as the geodynamo. The combination of convection currents in the molten outer core and the rotation of the Earth contributes to the generation of the magnetic field.
The other options provided, such as the presence of rubber, plastic, or cotton in the core, are incorrect and do not contribute to the creation of Earth's magnetic field.