Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down at the end of May, and its replacement, **statalist.org** is already up and running.

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

From |
Billy Schwartz <wkschwartz@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: How to find the sum of a variable by a group id |

Date |
Tue, 2 Aug 2011 13:22:30 -0400 |

If you want to keep the individual observations but want a variable containing the sum of y1 as follows hhid childid y1 sumy1 1 1 1 2 1 2 1 2 1 3 0 2 2 1 0 0 2 2 0 0 Then you can write (and you may need to -sort hhid- first) . by hhid: egen sumy1 = total(y1) On Tue, Aug 2, 2011 at 12:09 PM, Christophe Kolodziejczyk <ck.statalist@gmail.com> wrote: > > write instead > collapse (sum) y1, by(hhid) > > Christophe > > > 2011/8/2 Urmi Bhattacharya <ub3@indiana.edu>: > > Dear Statalisters, > > > > I have the following data set. > > > > hhid childid y1 > > 1 1 1 > > 1 2 1 > > 1 3 0 > > 2 1 0 > > 2 2 0 > > > > > > I need to find the sum of y1 per hhid, i.e., i need to get the > > following data set > > > > hhid sumy1 > > 1 2 > > 2 0 > > > > How do I get that? > > > > I tried the following > > > > collapse (sum) y1, by hhid > > it gives me the following error: > > > > option by incorrectly specified > > r(198); > > I am using Stata 11.2. > > > > It is a simple enough thing I am sure, but I am just not able to work > > it out. It would be great if someone could tell me where am i going > > wrong? > > > > Best > > > > Urmi > > * > > * 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/ > > > > * > * 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/ * * 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/

**References**:**st: How to find the sum of a variable by a group id***From:*Urmi Bhattacharya <ub3@indiana.edu>

**Re: st: How to find the sum of a variable by a group id***From:*Christophe Kolodziejczyk <ck.statalist@gmail.com>

- Prev by Date:
**st: Re: Finding and graphing intersection of lines** - Next by Date:
**st: Superscript test in data editor** - Previous by thread:
**Re: st: How to find the sum of a variable by a group id** - Next by thread:
**st: How to return regression results from a complex column vector in mata back to stata** - Index(es):