Dear Stata users,

I am new to stata and am working on a dataset with 20 mio. people for two years with zipcodes for each person to identify the municipality they live in.

I have the following question:
I want to create a variable that gives me the literacy rate for each municipality (zipcode).
I have a dummy variable that tells me if an individual is literate and I have the total number of people that live in each municipality; I also have a weight for sample expansion (since not the whole population is represented in my dataset).

I tried creating said variable with the following code, but if I summarize my literacy rate variable it does not give me a reasonable number (between 0 and 1).

egen literation = sum(literacy) if literacy == 1, by(zipcode)

gen literacy_rate = literation/popcount

My question is: how do I include the sample weights into the literacy_rate variable?

Thanks in advance for tips where I can read up on this.