The relation between nuclear activity and stellar mass in galaxies