Suppose that you have a survey where reported turnout is x% but you know from official sources that turnout is actually y% and the discrepancy is not due to differences in the sampling frame and it is statistically significant. You may decide that you wish to weight your data so that in your analysis the reported turnout matches the official turnout. To calculate the relevant weight variable, you can use the following formulae, where the variable turnout is a dummy variable to indicate whether someone did (1) or did not (0) vote.

Weight = y/x if turnout==1

Weight = (100-y)/(100-x) if turnout==0

If the main variable of interest is a categorical variable with more than two categories, the same principles apply to creating the weight. Respondents in each category need to be assigned a weight equal to the ratio of their frequency in reality to their frequency in the sample.