Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Nick Cox <njcoxstata@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: pweight for households |
Date | Sat, 14 May 2011 14:42:37 +0100 |
Daniel wrote > summarize weight if hhdrel==1 > > is closer - you get the number of records and and the mean weight so you > could multiply the two together to find your answer. The sum is also calculated by -summarize- and accessible in r(sum). So, you don't need to multiply. Just a small detail, Nick On Sat, May 14, 2011 at 1:15 PM, Daniel Feenberg <feenberg@nber.org> wrote: > > On Fri, 13 May 2011, Constance Kelly wrote: > >> I'm using the Current Population Survey (March Supplement) for a project, >> and I need to derive an estimate of the number of households in the >> population. There is a household population weight built into the data. The >> problem is that the data is structured by person, with individual household >> identifier numbers, i.e.: >> >> Person I.D. | Household I.D. >> 1 | 1 >> 2 | 1 >> 3 | 1 >> 4 | 2 >> 5 | 3 >> 6 | 3 >> etc. >> >> I know that if I reshape the data from long to wide, I can get the >> population household estimate, but I'm trying to figure out if there is a >> simper way to derive this value. >> Any insight would be appreciated. > > Althought Stata experts will believe this is a trivial problem, I want to > show that a beginner might take a while to find the solution. You > need to know that hhdrel==1 for the household head, so all you need > to do is get the sum of the weights of those records. > > First, she might try > > count if hhdrel==1 [pweight=weight] > > but -count- doesn't take weights. Then try: > > summarize if hhdrel==1 [pweight=weight] > > won't work because summarize doesn't take pweights > > summarize if hhdrel==1 [aweight=weight] > > won't work because -summarize- doesn't offer a weighted count. Everything > else is weighted, but not the count. > > summarize weight if hhdrel==1 > > is closer - you get the number of records and and the mean weight so you > could multiply the two together to find your answer. > > That isn't desirable. What about -tabulate-? > > tabulate hhdrel [pw=w] if hhdrel==1 > > won't work because tabulate doesn't take pweights. > > tabulate hhdrel [aw=w] if hhdrel==1 > > gives the wrong answer. > > tabulate hhdrel [iw=w] if hhdrel==1 > > gives the right answer, but the definition of iweights isn't documented. > Better to use: > > table hhdrel [pw=w] if hhdrel==1 > > which is documented or even > > egen sum=sum(weight) if hhdrel==1 > summarize sum > > or -table-, -collapse-, and possibly 7 other ways, but the lack > of pweights on many of the commands is a mystery to me - I never have > any other kind. * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/