I think a lot of training should be done, not just to stay in the house but also what to do once they get outside. I think when gates are up all the time and a dog gets past the gate by accident or whatever that's when they run away because they'll always want past it and weren't taught what to do.
I taught Joel two different things, first thing, to not go out unless I say okay and the second thing is how to be outside without running away. I can take him outside loose to check the mail and he has NO want to run away even if he sees birds or a cat. When he was little I put a really long piece of yarn so he felt like he was "loose" but couldn't run away and took him in and out the door a lot so it wouldn't be a big deal to him, and of course a ton of treats and teaching him to come and when we were done I say "go inside" and he would get a lot of treats once we went inside.
Now the only time he goes out when he's not supposed to is when someone is right outside at the door and he's so excited to see them, which I'm working on now