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: sum up values in last occurrences of subgroups


From   KOTa <[email protected]>
To   [email protected]
Subject   st: sum up values in last occurrences of subgroups
Date   Sat, 12 May 2012 23:16:29 -0400

HI statalist,

need your help with data management problem again.

here is the sample of data:

obs   user     date     activity    hours_same 	total   index
1        1    20071127    A  	 74 	 	          76
2        1    20071128    A 	         76	 	          78
3        1    20071129    B 	           0		          81
4        1    20071129    A 	         78 		          81
5        1    20071130    A 	         82 		          86
6        1    20071130    C 	         83 		          86
7        1    20071203    C 	         87 		          90
8        1    20071204    A 	         85 		          96
9        1    20071204    C 	         90 		          96


column "hours_same" contains number of hours spent previously (by
date) on same activity. ("total" is overall hours spent on all
activities)

i need to sum up in column "index" hours spent on each activity
separately, up to date and by user.
or in other words sum up values of "hours_same" variable from last
occurrences of each activity except current (because current is
actually the last for this type)

i.e. in the sample above "index" in line number:

- 3 - would be 0 (B) + 76 (A) = 76 (current plus last occurrence of B)
- 6 - would be 83 (C) + 82 (A) + 0 (B) = 165  (current plus last of A and B)
- 9 - would be 90 (C) + 85 (A) + 0 (B) = 175 (current plus last of A and B)

i tried to mark them in some way, but it does not help, because which
occurrence is last changes as i advance along the list of observations
and i could not connect the mark with type of activity also.

thank you in advance

K.

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