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   [email protected]
To   [email protected]
Subject   Re: st: summing across observations for given id and date
Date   Sat, 4 Dec 2010 17:34:01 -0500

I don't think that will work...in this case it will replace the example dataset with a single observation, summing over all time periods.
 
The following should work fine:
 
sort id date
collapse (sum) x1 x2, by(id date)


[email protected] wrote: -----


To: [email protected]
From: Christian Hunkler <[email protected]>
Sent by: [email protected]
Date: 12/04/2010 12:06PM
Subject: Re: st: summing across observations for given id and date


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/



This e-mail message, including attachments, is for the sole use of the intended recipient(s) and may contain confidential or proprietary information.  If you are not the intended recipient, immediately contact the sender by reply e-mail and destroy all copies of the original message.

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