Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

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

Re: st: create new variable from weighted counts?

From   Nick Cox <>
To   "" <>
Subject   Re: st: create new variable from weighted counts?
Date   Tue, 16 Apr 2013 19:09:30 +0100

You could always go something like

bysort county: egen dths_white=total(wtvar * (race==1))

In a strong sense this is documented, as the -egen- -total()- function
can take an arbitrary expression as argument. However, quite how
general this is may deserve more shouting and jumping up and down than
it gets.


On 16 April 2013 18:57, Rossen, Lauren M. (CDC/OSELS/NCHS) <> wrote:
> Hello Stata-listers,
> I have a data set on all infant deaths in the US, and I am
> trying to create county-level summaries of several variables.
> For example, counts of deaths by county for white infants,
> black infants, etc.  Normally, this would be straightforward
> to do with something like:
> bysort county: egen dths_white=total(race==1)
> bysort county: egen dths_black=total(race==2)
> However, the data are weighted because a small # of
> deaths are not included in the file, so there are something
> like importance weights to make sure that the totals sum
> up to the actual total # of reported deaths in the US.
> I say importance weights because there is no sampling,
> and the weights are not integers, they range from 1 to 1.2.
> My question is: is there a way to generate new variables
> representing county-level totals incorporating the
> weights? I apologize for the rudimentary question,
> but I have tried searching through the archives and
> documentation and had no luck finding a solution.
*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index