Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: Summing up values specific for each individual.


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: Summing up values specific for each individual.
Date   Wed, 4 Sep 2002 11:33:25 +0100

Kompal Sinha asked 
 
> > I am working with household data and my problem is 
> something like this.
> > 
> > For each household I have 'j' items where 'j' varies for 
> each household. I
> > want to find the sum of these items for each household.
> > 
> > For example:
> > 
> > HHid    item code  amount consumed
> > 
[ ... ] 
> > 
> > In the above example I want to find the sum of the third 
> column(amount
> > consumed) for each household and place this sum in the 
> fourth column such
> > that the sum is repeated '
> > j' times for one household. As I have 69000 households, I 
> wonder if there is
> > a command or a program is STATA that can do this for me. 
> Also the number of
> > items consumed by each household varies.

and [email protected] rightly wrote 

> assuming Stata 7
> 
> bysort HHid: egen totalcons=sum(amount_consumed)
 
More generally, the tool you want and need 
is -by <varlist>:-. Typing 

. findit by 

in an up-to-date Stata points to sources
of information in the manual and elsewhere. 

Nick 
[email protected] 
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index