Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: cumulative average moving through time


From   Daniel Egan <[email protected]>
To   [email protected]
Subject   st: cumulative average moving through time
Date   Wed, 6 Oct 2004 14:38:17 -0400

Hello all, 

I have iregularly spaced time/measurement data. I want to calculate an
average using all prior measurements. FYI, the variable to be
"averaged" is a dummy, so I would be looking at a percentage.

a hail mary was: 

sort PID OB
egen calc_sum=sum(calc[_n-_n]), by(PID)
gen cave=calc_sum/OB

which obviously does not work. 

My data looks like this. cave is the variable i wish I knew how to create. 

PID	OB	dm	dm_m	calc	cave
1	1	1-4-2000	0	1	1
1	2	1-10-2000	6	0	.5
1	3	1-28-2000	24	0	.333
1	4	2-1-2000	28	1	.5
2	1	10-5-1998	0	1	1
2	2	10-8-1998	3	0	.5
2	3	1-22-1998	17	1	.666
2	4	11-5-1998	31	1	.75



Thanks, 

Dan
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index