Under which conditions does religion affect educational outcomes