Walmart’s second-quarter results are showing that United States consumers across the spectrum are still flocking to the retailer’s stores despite economic headwinds, but its shares have dipped as the company’s margins ebbed and inventory costs rose.The world’s largest retailer has scooped up market share from rivals as wealthier consumers frequent the store more often, worried about the effects of tariffs on prices, the company’s results on Thursday showed.That has fueled an 85 percent surge in the stock over the last year-and-a-half that some analysts say has made its valuation too lofty.Shares were down 4 percent in midday trading in New York, as its second-quarter profit was lower than expected, registering Walmart’s first earnings miss in more than three years.Investors also focused on Walmart’s gross margins for the quarter, which fell short of their expectations, even though the company raised its fiscal year sales and profit forecasts.Overall gross margins were about flat at 24.5 percent versus 24.4 percent last quarter, missing consensus estimates of 24.9 percent, according to brokerage DA Davidson.“Expectations were high for a margin beat and we didn’t get that, so we’re getting a little bit of a pullback on the stock,” said Steven Shemesh, RBC Capital Markets analyst.Still, the Bentonville, Arkansas-based chain’s results sh …