I'm doing an analysis of the Current Population Survey. I have a wage variable (wage), a time-series variable (qtr), and an observational weight (pworwgt). Each quarter has thousands of observations.
I can easily make a table showing the weighted average wage in each quarter:
table qtr [iw=pworwgt], contents(mean wage)
What I want to do, however, is graph this easily within Stata. I tried to use egen to make a variable containing the mean by qtr, but egen mean() does not allow for weights.
egen'stotal()function to get the numerator and denominator of a weighted average, and then divide. There is a user-writtenegenfunction for this purpose, but doing it from first principles should be easy and instructive. Or even easier is to usecollapseto get a reduced dataset of averages. - Nick Cox