WordPress has a built-in display categories widget that can show as a list or a dropdown. However, it only shows categories with posts attached to them. If you want to show all categories in a dropdown use this code.