I have come across research papers where they compute the weighted covariance between two variables. For example covariance between X and Y in year t is weighted by the population size. When I look at the Stata code, the authors would use:
The stata correlate manual has a example with real data as well:
I wanted to know what the formula for the weighted covariance is in Stata. I think the weighted covariance formula is:
sum(w_t(x_it - xbar)(y_it = ybar)) where w_t = w/sum(w),
and xbar, ybar are also weighted using w [so for example xbar = sum(w_t x_it)/sum(w_t)]. I have tested out some examples and this formula closely matches what is obtained from Stata. I wanted to ask whether this is what Stata implements or is it some variant?
Code:
correlate X Y [aweight=w], covariance
Code:
webuse census13 correlate mrgrate dvcrate [aweight=pop], covariance
sum(w_t(x_it - xbar)(y_it = ybar)) where w_t = w/sum(w),
and xbar, ybar are also weighted using w [so for example xbar = sum(w_t x_it)/sum(w_t)]. I have tested out some examples and this formula closely matches what is obtained from Stata. I wanted to ask whether this is what Stata implements or is it some variant?
Comment