The Electronic Structure of Lanthanide Impurities in TiO2, ZnO, SnO2, and Related Compounds