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: How to reshape or collapse multiple observation per id as one observation per id


From   "Shittu, Aminu" <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: How to reshape or collapse multiple observation per id as one observation per id
Date   Sun, 12 Aug 2012 11:30:54 -0700 (PDT)

Hi Caliph

Try

collapse (sum) duration cost, by(id gender age)

for a data that look like this one

    +---------------------------------------+
     | id   duration   cost   gender     age |
     |---------------------------------------|
  1. |  1          8     50     MALE   ADULT |
  2. |  1         10     40     MALE   ADULT |
  3. |  1          3     30     MALE   ADULT |
  4. |  2          7     20   FEMALE   YOUNG |
  5. |  2          9     60   FEMALE   YOUNG |
     |---------------------------------------|
  6. |  2          6    100   FEMALE   YOUNG |
  7. |  2          8     20   FEMALE   YOUNG |
     +---------------------------------------+



Aminu





________________________________
From: Caliph Omar Moumin <[email protected]>
To: "[email protected]" <[email protected]> 
Sent: Sunday, August 12, 2012 7:17:25 PM
Subject: Re: st: How to reshape or collapse multiple observation per id as one observation per id

Dear Aminu

How do i keep other variables like gender, agegroup, and other string variables?


Kind Regards,
Caliph Omar Moumin

Email:  [email protected] 



----- Original Message -----
From: "Shittu, Aminu" <[email protected]>
To: "[email protected]" <[email protected]>
Cc: 
Sent: Sunday, August 12, 2012 6:03 PM
Subject: Re: st: How to reshape or collapse multiple observation per id as one observation per id

 Dear Caliph

Try this one:

collapse (sum) duration cost, by(id)

Aminu




________________________________
From: Caliph Omar Moumin <[email protected]>
To: "[email protected]" <[email protected]> 
Sent: Sunday, August 12, 2012 4:42:42 PM
Subject: st: How to reshape or collapse multiple observation per id as one observation per id

Dear statalist helper

I want to ask your help about a command which many of you answered many times, but i couldn´t i understand well.
it is ´reshape´or ´collapse´ command. I have a dataset which is in long format with multiple observation per id, and no time period. The dataset is also unbalanced


id duration cost gender agegroup plus other string variables (up to 5 variables)

I want to create a dataset with one observation per id by adding each ones multiple observation in both variables duration and cost


id duration cost (other variables)
1      8         50         string(or constant)
1      10       40         >>>>>>>>>>>>>
1       3        30         >>>>>>>>>>>>>
2       7        20        >>>>>>>>>>>>>
2       9        60        >>>>>>>>>>>>>
2       6       100     >>>>>>>>>>>>>>
2       8         20



and so on up to 20,000 observation which i have one up to 10 observation per id. 


I wanted to reshape my dataset as

Id    duration     cost     (other variables)
1        21            120          unchanged
2        30             200        >>>>>>>>>

I tried the reshape command. And it is creating many variables of duration and cost instead of adding as one variable


id  duration1 duration2 duration3   duration4...........
1     8                10          3                   .


I tried the collapse command and it is giving me only the mean value. But i wanted the total value. 


I would appreciate you if you could help?


Kind Regards,
Caliph

Email:  [email protected] 


*
*   For searches and help try:
*  http://www.stata.com/help.cgi?searchhttp://www.stata.com/support/statalist/faqhttp://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*  http://www.stata.com/help.cgi?searchhttp://www.stata.com/support/statalist/faqhttp://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*  http://www.stata.com/help.cgi?searchhttp://www.stata.com/support/statalist/faqhttp://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