Anecdote:
We're getting ready to sell our primary residence. In 1997 we bought the land for $90K cash. Over the last 18 years we've "invested" ~$320K to develop the land, i.e., build a house, a guest house, put up fences, outbuildings, build a 600' long driveway etc. If we're lucky, we're going to walk away with about $600K from the sale of our place. Great investment, huh?
The problem is, if we had invested the same amount of money in an S&P 500 index fund, we'd be sitting on around $830K, which means it's cost us ~$230K to own our home for 18 years. We're totally fine with this outcome. If we had rented for those 18 years, we would have had to pay around $1K/month rent for a place which wouldn't have been near as nice as our own home.
Our place has also brought in some income over the years from farming and rentals, but I'm pretty sure that extra income was less than the extra stuff (not included in estimate of how much we "invested in the property) we bought over the years that we probably wouldn't have bought if we had been renting: ladders, shovels, picks, rakes, wrenches, wheelbarrows, saws, drills, paint, nails, etc. Also, our home is in the country, far from work, stores, and many activities we would like to be involved in. If we had rented for an average of ~$1000K/month for the past 18 years, we would've lived in town, closer to work, shopping and entertainment. Had we lived in town, we could've not owned cars for all these years, which has been our single biggest expense besides housing.
So, in the end we're hoping to sell our house/land for more money than we paid for it, but I wouldn't say that it's been a great investment. Only looking at the financials, we could've made more money renting and investing the difference in the stock market. Overall, though, we're happy with our choice to buy land and build our own house. We've learned many life skills that we would've never learned living in an apartment: how to build a house, painting, fencing, gardening, raising livestock, etc., but money-wise I'd say we've probably lost a little bit.