Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: using egen, total() with weights

From   Sheera Joy Olasky <>
Subject   st: using egen, total() with weights
Date   Thu, 9 Feb 2012 17:53:02 -0500

Hi Statalist,

I have a set of individual level survey data, which includes
person-weights. I would like to create population totals by year and
state. I am using Stata 11.2.

Originally I had thought to use bysort id: egen pop=total(weight)
where id is the state-year.

However, it was then suggested to me that I should be using sum
[aweight=weight]. This seems more complicated to me, since I'm not
sure how/if I could make new variables with the sum output in the same
way that I get a new variable with egen total (weights). Use of
scalars was recommended, but I have no experience with them.

Initially, when I compared the values I got with egen total(weight)
and sum [aweight=weight], they were very close--maybe off by about 4
people out of over 80,000,000. This imprecision is okay in this
scenario, but it got me concerned. I thought that perhaps there was
too much rounding happening with egen, so I generated the
total(weight) as double. The increased precision seems to have helped,
and now egen total(weight) and sum [aweight=weight] appear to give me
the same results when I spot check.

I don't feel completely confident, though. Before I go ahead and use
egen, I'd like to know if this is okay or ill-advised. I'd be curious
to know others' preferred way of handling this.

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index