It takes patience. Just keep a schedule. At first, keep the dog in a room that doesn't have carpet and take the dog out every hour, then every two hours, etc. Once you can go for a few days without accidents, you can see how the dog does on the carpeted areas. I really don't recommend it, but you could also crate your dog while you're gone as long as you don't leave him/her in there more than 8 hours at a time.Is your dog male or female? Females seem to have less trouble potty training than males. (I'm basing this from personal experience, not professional knowledge) If you have a male dog, you might want to look into buying a belly band. I have made some for my little male cockapoo and it has saved my carpets and my temper quite a few times. I used to foster rescue dogs and there were a few males who had to wear the belly bands because they tried to "mark" my sofa.I've added a link to a site that sells them. I don't have any affiliation with them. If you know how to sew, they're super easy to make. Good luck!
www.designerdoggie.net