1) The amount of money you lose by spending 5 years in grad school (instead of working) vastly exceeds any potential benefits of buying vs. renting.
2) If you were concerned about money, the smart thing to do would be to stay in subsidized student housing for the following 5 years.