Do it. Just having Stanford on your resume is justification enough IMO. And yes, then you will have many opportunities. Plus the weather (when the wildfires aren't raging) is so much better.
I don't think a commute from SF is that bad. I took Caltrain to San Mateo from SF for a year and there were a few delayed or canceled trains but otherwise it was fine. Ok, full disclosure it's packed and loud for Giants games so that does kinda suck. The Palo Alto stop is 5 minutes from campus. As another commenter mentioned, you would want to live close to the train station in SF (Mission Bay, Potrero) otherwise your commute will suck - for example, getting from Sunset or Richmond to Caltrain is a pain.