At a country level, railways help economies to prosper and diversify and build democratic institutions. The movement of people, goods and services helps industry and trade to grow which raises the demand for skilled labour and, in turn, the middle classes who tend to focus on Government and support greater democracy.
Many big rail projects in third world / developing countries are vital due to an inability to trade because they cannot move people, goods and services easily. In addition, they are often focused on a single commodity, for example, garments account for 80% of all Bangladesh exports. Making trade easier increases the flow of money that can then be used to diversify into other industries which, in turn, aids greater economic stability, i.e. the country does not fall into decline if one industry is in recession.
The commercial diversification being driven in the Middle East comes from the same concern – a single commodity, oil, is a short-term strength and long term (as it declines) weakness. These countries need more infrastructure than just pipes to maintain their prosperity. In troubled areas (famine, drought, war and so on) investment in railways brings hope through real jobs that reduce unemployment and create greater social cohesion.