In the beginning God created the heavens and the earth.
Does the Bible state a reason anywhere?
God created the heavens and the earth as an expression of His glory.
The heavens are telling of the glory of God; And their expanse is declaring the work of His hands. (Psalms 19:1 NASB)
The heavens declare His righteousness, And all the peoples have seen His glory. (Psalms 97:6 NASB)
I think John Piper explains it nicely in Desiring God, which is available for free online. Basically, he argues that God's ultimate purpose and joy is in the display of His glory:
God would be unrighteous (just as we would) if He valued anything more than what is supremely valuable. But He Himself is supremely valuable. If He did not take infinite delight in the worth of His own glory, He would be unrighteous. For it is right to take delight in a person in proportion to the excellence of that person’s glory. (Desiring God, p42-43)
And to that purpose, creation is the expression of His glory:
In creation, God “went public” with the glory that reverberates joyfully between the Father and the Son. There is something about the fullness of God’s joy that inclines it to overflow. There is an expansive quality to His joy. It wants to share itself. The impulse to create the world was not from weakness, as though God were lacking in some perfection that creation could supply. “It is no argument of the emptiness or deficiency of a fountain, that it is inclined to overflow.”
God loves to behold His glory reflected in His works. So the eternal happiness of the triune God spilled over in the work of creation and redemption. And since this original happiness was God’s delight in His own glory, therefore the happiness that He has in all His works of creation and redemption is nothing other than a delight in His own glory. This is why God has done all things, from creation to consummation, for the preservation and display of His glory. All His works are simply the spillover of His infinite exuberance for His own excellence. (Desiring God, p44)
To some, this concept might seem to put God in a light in which he seems vain, or like he is "just showing off" (as @MasonWheeler mentioned). I don't believe it does.
Although "showing off" is essentially correct, that phrase carries a negative connotation. I think that connotation comes from the fact that "showing off" is usually used to describe humans that scramble to draw attention to, and highlight their own perceived glory. The difference between these people and God is that:
On the other hand:
Earth is the dwelling place of mankind. God's decision to create mankind necessitated the creation of a dwelling place for him.
The heavens possibly include the sky, the stars and planets, and even the throne of God. The sky, stars, and planets are, of course, part of man's dwelling place.
God's throne is where the angelic beings can be in His presence, but also mankind as well.
Two Scripture references, that basically say the same thing:
The LORD hath made all things for himself: yea, even the wicked for the day of evil. Proverbs 16.4
For by him were all things created, that are in heaven, and that are in earth, visible and invisible, whether they be thrones, or dominions, or principalities, or powers: all things were created by him, and for him. Col 1:15
As tautological as this sounds, it is true - God made everything for himself, because he wanted to.
God actually tells is specifically why He created the earth, in Isaiah 45:18
"For this is what the Lord says, he who created the heavens, he is God; he who fashioned and made the earth, he founded it; he did not create it to be empty, but formed it to be inhabited..."
His specific, stated purpose in creating the earth was so that it could be inhabited: he created it to be our home.
In summary God created the Earth to bask in his Glory as it is just for him to do so. And he created the people in love of Himself. People are to be active citizens in love for themselves, and ultimately Him. And Socrates's Allegory of the cave clearly exemplifies such. Bible versus to support my claims: "Proverbs 1:5, John 3:20-21, Matthew 5: 14&16."