Suppose you have a survey where turnout is recorded in several different countries, such as the European Social Survey, and you want to make sure that in your analysis reported turnout matches the official turnout in each country separately. Let's say that the variable with official turnout is called offturnout and is measured as a proportion rather than as a percentage. You can use the following steps to create a suitable weight.
Create a variable which provides the reported level of turnout for each country (muturnout), perhaps with the following command in Stata.
bysort country: generate muturnout = mean(turnout)
Create the weight using the following Stata commands or similar.
gen weight = .
replace weight = offturnout/muturnout if turnout==1
replace weight = (1-offturnout)/(1-muturnout) if turnout==0