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

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


From   Anton Granik <anton.granik@GMAIL.COM>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: summing across observations for given id and date
Date   Sun, 5 Dec 2010 18:45:34 +0100

thank you

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



2010/12/4  <Daniel.Green@ny.frb.org>:
> 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)
>
>
> -----owner-statalist@hsphsun2.harvard.edu wrote: -----
>
>
> To: statalist@hsphsun2.harvard.edu
> From: Christian Hunkler <Hunkler@mea.uni-mannheim.de>
> Sent by: owner-statalist@hsphsun2.harvard.edu
> 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/
>

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index