Public railroad stocks can be especially attractive in a growth economy. Few industries are as closely tied to economic growth as those involved in moving goods and commodities. Railroad stocks took a beating in the past few years, due in part to the falling fortunes of coal, which accounts for nearly 40% of America's railroad tonnage. Declining oil and gas production, as well as the increasing use of pipelines over railways, also hurt the industry. (See also: A Primer on the Railroad Industry.)

However, depressed prices may provide an opportunity for value investors to enter this space, taking their cues from Warren Buffett and even Bill Gates, both of whom are heavily invested in railroads. Buffett's Berkshire Hathaway acquired Burlington Northern Santa Fe in 2009, and Gates holds a significant stake in Canadian National Railway Company (CNI).

According to a report by the Association of American Railroads, U.S. railroads generated about $33 billion in revenue in 2014, and $28 billion was invested into the industry. Railroads transport the vast majority of all major industrial and consumer goods, so railroad companies are very sensitive to movements in the economy. A growing economy could point to growth in public railroad stocks. If you're looking for exposure to this sector, here are three of the top railroad stocks for 2017.

Note: All figures are as of Jan. 14, 2017.

CSX Corporation (CSX)

CSX has a market cap of $34 billion and gross revenue in 2015 of $11.81 billion. The Florida-based company operates mainly on the east coast and is the third largest Class I railroad. The company operates in three main areas – merchandise, intermodal and coal – and it handles domestic coal shipments to power plants as well as exports to deep-water port facilities. Its merchandise line transports food, agricultural, automotive and forest products, among other goods.

CSX currently trades at $38.80, which marks a 52-week high and is above its 12-month price target of $38. The stock is up nearly 74% over the past 12 months. The consensus sentiment is currently Outperform, upgraded from Hold in September 2016. (See also: CSX Earnings Could Wake Up Sleepy Transports.)

Union Pacific Corporation (UNP)

This is the granddaddy of American railways, established in 1862, with a market cap approaching $87 billion. It is the supply chain link for much of the western United States, connecting approximately two-thirds of the country – and some 20 states – by rail. It operates roughly 9,000 locomotives and connects the Canadian rail lines with the Gulf of Mexico. Its rail network covers around 32,000 miles.

Union Pacific reported revenue of nearly $22 billion in 2015 and earnings per share of $5.49, an increase of 13.63%. It currently trades at $105.25, up 42.52% over the past year. The stock is just 4% off its 12-month price target of $109 and has a 52-week range of $67 to $106.52. The analyst consensus is currently Outperform, which has been stable since 2007. (See also: Norfolk Southern a Better Buy Than Union Pacific.)

Canadian National Railway Company (CNI)

Canadian National has a market cap of $54.5 billion, making it one of the larger railroad companies. Although it's technically a Canadian railway, it operates 20,000 miles of track across the U.S. and Canada, connecting the Atlantic and Pacific oceans and the Gulf of Mexico. It moves freight for several major commodities groups – including oil, liquid natural gas and chemicals – and it has access to all the NAFTA countries.

The company had revenue of CA$12.61 billion ($9.6 billion) and a net profit margin of 29.73% in 2015. It currently trades at $71.50, which is a new 52-week high and exceeds its one-year price target of $68.30. The stock is up 27.83% over the past 12 months. (See also: This Is What Bill Gates' Portfolio Looks Like.)

Want to learn how to invest?

Get a free 10 week email series that will teach you how to start investing.

Delivered twice a week, straight to your inbox.