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 09:03:23 -0700 (PDT)
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?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/