Both are great unis. I'd say edinburgh probably has a better night life just because there's more to do. St andrews is pretty much a campus uni but UoE is city based. Edinburgh is part of the Russel group so if you want to go on to do research you might want to pick Edinburgh over St Andrews. The other thing is that St andrews has a bit of a reputation for having just rich/posh students whilst Edi would be more diverse. Cost of living wise, both are pretty expensive but st andrews is probably slightly cheaper. For STEM I would say edinburgh just edges it, but St Andrews also has its benefits. Its basically down to if you want to live in a busier city or a slightly out of the way coastal town.