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]

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

From   Urmi Bhattacharya <>
Subject   st: How to find the sum of a variable by a group id
Date   Tue, 2 Aug 2011 12:05:01 -0400

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
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


*   For searches and help try:

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