God isn't something rational, he is the cause himself. The creation is the beginning of everything, nothing existed before the creation, therefore there couldn't be any reason for the creation. The bible itself starts with the sentence- " In the beginning God created the heaven and the earth". If the creation is the beginning, no event could have occurred before that including any rational process of cause-consequence. The question of "Why god created earh" has no answer from it's very own essence.