This post ended up being a bit long, but hopefully it'll be helpful.
I bought a home for a three year residency. I thought the odds were that I'd stay for a fellowship and possibly as an attending. The cost of living is low here and I bought a house in a nice and safe neighborhood a 15 minute walk from one hospital I'm at about 60% of the time and a 10 minute drive from the other hospital I work at. The home cost around $110k, and at 3.25% or so, mortgage/taxes/insurance total $775, compared to the $1100/month it would've cost to rent a similar home. At the time we moved, we couldn't find any rentals under $1300 (they were all bigger homes than the small one we purchased), and none were close to the hospitals.
I figured it made more sense to by--the NYTimes rent vs buy was in favor of buying (even if we only stayed 3 years), it was a great neighborhood and my wife felt safe there, one of my favorite hobbies is landscaping/working on a home, and as a PM&R resident I actually have time to do those things.
I also figured that if I got an attending job right away (rather than being a fellow) and had to move, that we could absorb any loss on the home fairly easy--you can only lose so much on such a cheap home. What I didn't take into account was doing a fellowship somewhere else and not having the income to offset that. We also did have to do some major work--renovated the bathroom (I did about 1/3 the work, so it was fairly cheap by bathroom remodel standards), completely redid the landscaping (that was just fun--we did all the work and only paid for the plants, wood, but they did add up), and we replaced the heater and AC last summer (not fun). We met with a realtor and she recommended listing a fair amount higher than what we purchased the home for, and if we sell it at/near that amount, we'd recoup most of what we put into the home, not taking into account closing costs. But that also doesn't take into account how much we saved on a monthly basis. We'll see-we've had a lot of interest in the home, but no offers yet (we just listed this week), so it could still be on the market for some time for all I know.
If I can't sell it I have a co-resident who'd be willing to rent it, but I'd rather not be a landlord. At best we'd only make about $350-400/month if we rent it out, not taking into account taxes on the profit, maintenance costs, depreciation from a renter not taking as good of care of the home/property (an the landscaping is a big selling point for our home), other crap that can go wrong (at least the Heater/AC are warrantied though). Still--all that work and stress for at best $4800/year? That's without a property manager too--it's not like I can fly across the country just to fix a sink. For that profit, it's just not worth it, and it certainly wouldn't be worth it as an attending--maybe if I was staying local it would be, but even then--who wants the headache of finding renters/home maintenance/etc., all for only $5k at best, when you're making around $200k? Unless that seems worth it to you, or you're in an area where you're home will really go up in value, I would not consider being able to rent out the home to other residents/medical students after you graduate as a benefit to buying. In my mind, renting is a backup if you can't sell, or a way to make profit on the home going up in value if you bought in say, SF.
We did decide to list early as I don't want to sell from across the country (or pay rent at our new place + our mortgage, and for a landscaping maintenance team), and would rather move into a subleted unit for a few months. The odds of a prospective buyer willing to wait until the end of June to close or willing to rent back to us are slim, though certainly a possibility.
We'll have to see how I feel when we close, but I am personally really glad we bought the home, though I would NOT recommend it for most residents. For starters, I actually had time to work on the home--most residents will not. Who's going to handle the simple things that go wrong? Shoveling snow? Lawn care? What about fixing a leaky faucet, or if the heater goes out? If you own the home, are you going to be ok with the contractor coming in while you're not there? If I didn't have more time than the average resident, I don't think I'd want to be using up what little free time I had to work on a home, as much as I enjoy it. I'd want that time for family, studying, and sleep.
For anyone that is interested in buying, I would recommend going into home buying with the assumption that you will at best break even. You just don't know what will go wrong with the home--things like roofing, sewers, plumbing, HVAC, etc., get very expensive. And like I said, most residents may not want to deal with the time and stress of the repairs (or scheduling them).
For my wife and I, renting an apartment wasn't an option. We'd lived in duplexes and apartments for something like 8-10 years prior. Some were good, but the latter 4 years while in medical school we had miserable adjacent neighbors--kids running around, mom screaming, dog barking. All right upstairs. The next place we moved was a young couple who always had the loudest screaming matches. We're more sensitive to noise and we realized paying an extra $300-400/month would've been worth the peace of mind, ability to sleep, study, etc. We got lucky that we were able to then move into a coach house--no immediate neighbors! Unfortunately, they don't have those where I live now. That's why we only looked at renting homes, as we could've gotten an apartment pretty cheap.
Of course, one thing to consider is when you buy, you're stuck there. If you don't like your neighbors you can't exactly get up and move. But at least they don't live right on top of/below/to the side of you. You've got some space.
All-in-all, I'm glad we bought the house. Who knows if we break even, come out ahead (we might, when factoring in rent saved vs comparable place) or behind. It was a great starter home--we learned a ton about what we should've thought about when buying, what things to have inspected more closely (and how to make sure we have a good inspector--use a referral if available!), fixing up a home, landscaping, etc. etc. You think you learn a lot from the research you do prior to buying a home, but it's nothing compared to actually learning from living in one. Unfortunately a lot of that learning is done the hard way. So when we're ready to buy our next home (we'll likely rent the first 6 months of attendinghood so we can get to know the area, make sure I like the job, etc.), we'll be in a much stronger place on picking a home, knowing what fixer-upper stuff I can tackle on my own, what repairs are actually affordable, etc. Considering my next home will likely be our permanent home, and will likely cost $500k or whole a lot more (we're from CA, and would like to move back west, though I can't afford SF...), it'll be helpful to be a stronger/more knowledgeable buyer.
Long story short, I would still recommend against buying for the vast majority of residents. It's been great for us, but unless you have the time or are willing to spend a lot of what little free time you have working on a home, it'll just be a whole new source of stress. If you're a psych/derm/PM&R/path/etc resident with good hours, and the numbers look ok and you can find a good value home, then it may be worth considering.