The value of a stock ultimately is related to the valuation of a corporation. As part of the valuation, you can estimate the cash flows (discounted to present time) of the expected cash flows from owning a share. This stock value is the so-called "fundamental" value of a stock. What you are really asking is, how is the stock's market price and the fundamental value related? And by asking this, you have implicitly assumed they are not the same.
The reason that the fundamental value and market price can diverge is that simply, most shareholders will not continue holding the stock for the lifespan of a company (indeed some companies have been around for centuries). This means that without dividends or buybacks or liquidations or mergers/acquisitions, a typical shareholder cannot reasonably expect to recoup their share of the company's equity. In this case, the chief price driver is the aggregate expectation of buyers and sellers in the marketplace, not fundamental evaluation of the company's balance sheet.
Now obviously some expectations are based on fundamentals and expert opinions can differ, but even when all the experts agree roughly on the numbers, it may be that the market price is quite a ways away from their estimates. An interesting example is given in this survey of behavioral finance. It concerns Palm, a wholly-owned subsidiary of 3Com. When Palm went public, its shares went for such a high price, they were significantly higher than 3Com's shares. This mispricing persisted for several weeks.
Note that this facet of pricing is often given short shrift in standard explanations of the stock market. It seems despite decades of academic research (and Nobel prizes being handed out to behavioral economists), the knowledge has been slow to trickle down to laymen, although any observant person will realize something is amiss with the standard explanations. For example, before 2012, the last time Apple paid out dividends was 1995. Are we really to believe that people were pumping up Apple's stock price from 1995 to 2012 because they were waiting for dividends, or hoping for a merger or liquidation? It doesn't seem plausible to me, especially since after Apple announced dividends that year, Apple stock ended up taking a deep dive, despite Wall Street analysts stating the company was doing better than ever. That the stock price reflects expectations of the future cash flows from the stock is a thinly-disguised form of the Efficient Market Hypothesis (EMH), and there's a lot of evidence contrary to the EMH (see references in the previously-linked survey). If you believe what happened in Apple's case was just a rational re-evaluation of Apple stock, then I think you must be a hard-core EMH advocate.
Basically (and this is elaborated at length in the survey above), fundamentals and market pricing can become decoupled. This is because there are frictions in the marketplace making it difficult for people to take advantage of the mispricing. In some cases, this can go on for extended periods of time, possibly even years. Part of the friction is caused by strong beliefs by market participants which can often shift pressure to supply or demand. Two popular sayings on Wall Street are, "It doesn't matter if you're right. You have to be right at the right time." and "It doesn't matter if you're right, if the market disagrees with you." They suggest that you can make the right decision with where to put your money, but being "right" isn't what drives prices. The market does what it does, and it's subject to the whims of its participants.