Medieval Demographics (PDF File) is one of my goto documents on generating material.
Medieval Demographics discusses two areas of interest. One how to calculate the population of a realm. Two how to calculate the number of shops in a settlement.
Both area use straight forward math to calculate the figures. Both area are based on the author's research using medieval sources and medieval data.
There are several sites that do the calculations for you such this one on Donjon
The principle for villages is straight forward. Figure out how many people it would take to support a viable business then divide that factor into the populate. The whole number is the number of establishments that exist. The remainder is the percentage chance that one additional establishment of that type exists.
S John Ross has been criticized for using unrepresentative data that was found in Life in a Medieval City which is based on a tax census called the Paris Tax Roll.
I created an alternative take more suited for Fantasy setting at this link. It is meant to work with this price list. This is a spreadsheet showing I used the paris tax roll to derive my take.