Ferromagnetism and resisitive switching in magnesium oxide with nitrogen doping