# Help with weighting sample according to population

I am a beginner with basic knowledge of statistics - just learning. I have a doubt regarding weighting survey sample distribution to population distribution. I have to create a weighting variable that will allow me to adjust the data to match the expected age and gender population breakdown.

In the attached image, there is the sample distribution by age and gender and also the population distribution is given for the same category. I have currently calculated weights for each category by dividing each cell category in the population by the respective sample category.

In this scenario, some weights are too high and one of them is zero. I believe that this is not the right approach and I am doing something wrong here. Kindly guide me on how to do this. I want to keep the age and gender categorizations the same and not group anything.

• Your results look (at least qualitatively) correct. Why the division by zero error? Because your sample has no young males in it. It is hopeless to try to reweight the results in that group, because you have no information at all about it! – whuber Mar 2 '20 at 14:50
• Would it be ok for you to adjust your grouping? For example by merging adjacent rows that don't have enough participants or by leaving them out completely? As whuber mentioned: Trying to infinitely weight the missing data-points is not the way to go. – KaPy3141 Mar 2 '20 at 15:52