Stockinette ( St st also called Stocking stitch) and ribbing will always be different sizes worked on the same needle. The ribbing always is a little looser. Some patterns compensate for this by having you knit the ribbing on a smaller needle and some start with fewer stitches and then add some as they get ready to move into the St st.
Does your pattern by any chance have two needle sizes listed? If it doesn’t and your ribbing seems too large/loose and you got the gauge they called for doing St st, you might just decide on your own that you need to go down a needle or 2 smaller for the ribbing. For a hat you don’t want to end up with the ribbing too tight, but you don’t want it too loose either. I suggest that you try casting on with the needle you got gauge on (or even a needle 2 sizes larger than that in if you have lots of needles at hand) and then do the ribbing in 1 size smaller needle than you got gauge on. Then if it still seems too loose you could try the same thing with 2 sizes smaller for the ribbing. But cast on fairly snuggly (comfortably snug, don’t pull on it over much) on the larger needle each time so that the edge will still have plenty of stretch so the hat isn’t too tight right at the edge.
Be sure you paid attention to the gauge called for though or the whole hat will be the wrong size. You will want to use the needle you got gauge on for the St st portion of the hat.