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

Re: st: cumulative average moving through time


From   [email protected]
To   [email protected]
Subject   Re: st: cumulative average moving through time
Date   Wed, 06 Oct 2004 14:18:05 -0500

Dan,

Try 

bysort pid (ob):gen cave = sum(calc)/ob

Hope this helps,
Scott

----- Original Message -----
From: Daniel Egan <[email protected]>
Date: Wednesday, October 6, 2004 1:38 pm
Subject: st: cumulative average moving through time

> 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