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]

st: How to reshape or collapse multiple observation per id as one observation per id


From   Caliph Omar Moumin <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: How to reshape or collapse multiple observation per id as one observation per id
Date   Sun, 12 Aug 2012 08:42:42 -0700 (PDT)

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