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]

st: calculating cumulative values of other observations


From   KOTa <kota.alba@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: calculating cumulative values of other observations
Date   Fri, 6 Apr 2012 19:09:18 -0400

Hi all,

i have a data looking like this:

ID	date	            activity	hours prior	     result should be:	
1	20071230  	A	10	   ?	<--	11
1	20071122	        A	11	   ?		0
2	20071120	        A	5	   ?		0
3	20071210	        B	6	   ?		73
3	20071111	        B	24	   ?		49
3	20071130	        F	20	   ?		0
3	20070511	        B	49	   ?		0
4	20070611	        A	50	   ?		0

(better picture here http://gyazo.com/5dc1218534d8b185ab22989069034b8a.png )

i need to fill "prior" column with following:
- amount of hours spent on same activity by same user(ID) prior to
date of current activity.

example:
in case of observation 4(line 4) activity is B, so prior = sum of
hours spent on activity B before it took place (i.e. before 20071210)
there are 2 such observations, one with 49 hour, another with 24.
Therefore, prior = 24+49=73.


any suggestions how to make this simple?

i was thinking to use "sort" and "by:", but i can't figure out how to
conditionally("if")  sum up values from different observations into
"prior" var
its not a first time i encounter similar problem and always took some
way around, but this time i decided to ask, maybe there is proper,
simple way to do this

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