Sorry to be controversial, but the replacement of steam locos _did_ make economic sense!
First, Diesel and electric require a _lot_ less daily maintenance, not even counting the coal and water filling (especially the coal filling requires a lot of machinery in the stations and both are time consuming).
Second, the starting torque of electric and diesel locos is much higher than of classic steam locos. Especially in countries with lots of mountains the first electric trains ran _much_ faster (I'm talking differences of two hours or more!) than steam trains! For example across the Semmering (Austria) steam trains reached an average speed of 15 km/h whereas the first electric trains reached an average speed of 60 km/h!
Besides: hydro electricity (or electricity generated from burning gas or biomass) is a _lot_ more environment friendly than burning coal in a loco. Plus a big power plant is always more effective than a small loco.

And there's alway the fire risk with steam locos too.