Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | "Rossen, Lauren M. (CDC/OSELS/NCHS)" <vyz5@cdc.gov> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
Subject | RE: st: create new variable from weighted counts? |
Date | Wed, 17 Apr 2013 13:12:46 +0000 |
Thank you so much, Nick, for pointing me in the right direction. There will be plenty of jumping up and down in appreciation. Lauren ------------------------------ Date: Tue, 16 Apr 2013 19:09:30 +0100 From: Nick Cox <njcoxstata@gmail.com> Subject: Re: st: create new variable from weighted counts? 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. Nick njcoxstata@gmail.com On 16 April 2013 18:57, Rossen, Lauren M. (CDC/OSELS/NCHS) <vyz5@cdc.gov> 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: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/ ------------------------------ * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/