Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: summing across observations for given id and date


From   Christian Hunkler <[email protected]>
To   [email protected]
Subject   Re: st: summing across observations for given id and date
Date   Sat, 04 Dec 2010 18:06:12 +0100


Dear Anton,

the following should work:

egen x2temp = sum(x2), by(id)
bysort id: gen keep = _n
keep if keep==1
replace x2 = x2temp
drop x2temp

Best, Christian

Am 04.12.2010 18:03, schrieb Anton Granik:
I have the following panel data set where dates sometimes repeat:

id  date  x1  x2

1   t=1   1    12
1   t=2   1     9
1   t=2   2    11
1   t=5   1     7


I would like to do the following:
1. For every individual (id) I need to add all values of x2
corresponding to the same date, i.e. in the example above I would want
to get rid of lines 2 and 3 and replace them with

id   date   x1  x2
1    t=2     3   20

Any easy way to do that? Thanks in advance.

---------------------
Anton I. Granik

---------------------
Anton I. Granik

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


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index