Great question -- one that deep thinkers have been worrying about ever since they came up with the idea of God! As the great 4th century Catholic thinker Augustine said, when asked what God was doing all that time before creating the universe he was tempted to answer: preparing Hell for those who ask stupid questions! ... But then he recognized that it was an important question, and gave his own answer to it: since one of the things that God creates is time itself, there IS no time 'before' the creation of the universe -- so you don't have to say what God was doing! ... Now whether this answers your question or not -- i.e. WHY did God create anything -- is not clear, but it may take away a little incentive for raising that question: if God never 'changed' (from not creating to creating), then perhaps we don't need to look for a 'cause' to his changing in the way you framed the question ....
hope that's useful!
(If you're interested, I present some of the classic answers to this question in my book The God Question ...)