How long can you stay outside of the US without it affecting your citizenship?

You can stay abroad as long as you want to, as far as US laws are concerned.