Ginger is correct. Even if a
dog has been neutered they still get the swelling
on the penis. Dogs, like people, masturbate because it feels good to them. Neutering them will not prevent them from doing this, it merely prevents them from being able to impregnate a female, so if they are in the mood, they can still bet an erection.