I think egen (extensions to generate) would work perfectly as below:
. l
+--------+
| id a |
|--------|
1. | 1 1 |
2. | 1 0 |
3. | 2 1 |
4. | 2 2 |
+--------+
. egen sumA = sum(a), by (id)
. l
+---------------+
| id a sumA |
|---------------|
1. | 1 1 1 |
2. | 1 0 1 |
3. | 2 1 3 |
4. | 2 2 3 |
+---------------+
Eric
>Hi,
>
>I'm looking for a function that will sum a variable across all
>observations by identifier.
>
>For example, if I have
>
>ID A
>1 1
>1 0
>2 1
>2 2
>
>I would like a function that would give me:
>SumByID=function(A,ID)
>
>SumbyID would be equal to 1 for all observations with ID=1 and 3 for
>all observations with ID=2 .
>
>Thanks very much,
>Rachel
>
>*
>* 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/
--
===================================================
Eric G. Wruck
Econalytics
2535 Sherwood Road
Columbus, OH 43209
ph: 614.231.5034
cell: 614.330.8846
eFax: 614.573.6639
eMail: [email protected]
website: http://www.econalytics.com
====================================================
*
* 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/