When I complete the PhD, if I go to industry in the USA, my income will probably be similar to that of my friends who will have been in industry the entire time (and gotten steady wage increases throughout).
It's important to note also cost of living. 40k/yr might sound like a lot, but in Boston, rent is >1k/month even with roommates, we don't have dental care, our health insurance is imperfect, groceries are expensive, etc. etc. Meanwhile in Tucson Arizona or Bloomington Indiana the stipend is something like 22-28K/yr, as cost of living is lower.
Generally speaking it's reasonable to say that completing a PhD in computer science is not a financial investment, but rather, something I am doing because I want to do it. I am very unlikely to literally "profit" (compared to, if I had gone straight to industry instead).
I hope this information is useful/interesting!