| |
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: RE: How to calculate average in different interval
This has already been answered. Another answer is
bysort date time : egen volavg = mean(vol)
bysort date time : replace volavg = . if _n < _N
Nick
[email protected]
gary tian
> >Can anyone help me ?
> >
> >I have stock transaction data. I need to calculate each
> second average
> >trading volume. How can I to produce a new variable such as
> volavg and
> >put average volume in the last one of the same second ?
> >
> >order date time price vol
> >1 1-Jul-05 10:02:19 5.8 5000
> >2 1-Jul-05 10:02:19 5.8 651
> >3 1-Jul-05 10:02:19 5.8 3349
> >4 1-Jul-05 10:02:19 5.8 349
> >5 1-Jul-05 10:02:19 5.8 1500
> >6 1-Jul-05 10:02:19 5.8 5651
> >7 1-Jul-05 10:02:24 5.8 2000
> >8 1-Jul-05 10:02:26 5.8 1000
> >9 1-Jul-05 10:02:26 5.8 37711
> >10 1-Jul-05 10:02:26 5.8 500
> >11 1-Jul-05 10:02:26 5.8 8789
> >12 1-Jul-05 10:02:26 5.8 2000
> >13 1-Jul-05 10:02:35 5.8 2583
> >14 1-Jul-05 10:02:36 5.8 5000
> >
> >
> >The result that I want:
> >
> >order date time price vol volavg
> >1 1-Jul-05 10:02:19 5.8 5000 .
> >2 1-Jul-05 10:02:19 5.8 651 .
> >3 1-Jul-05 10:02:19 5.8 3349 .
> >4 1-Jul-05 10:02:19 5.8 349 .
> >5 1-Jul-05 10:02:19 5.8 1500 .
> >6 1-Jul-05 10:02:19 5.8 5651 =
> >(5000+651+3349+349+1500+5651)/6
> >7 1-Jul-05 10:02:24 5.8 2000 2000
> >8 1-Jul-05 10:02:26 5.8 1000 .
> >9 1-Jul-05 10:02:26 5.8 37711 .
> >10 1-Jul-05 10:02:26 5.8 500 .
> >11 1-Jul-05 10:02:26 5.8 8789 .
> >12 1-Jul-05 10:02:26 5.8 2000 =
> >(1000+37711+500+8789+2000)/5
> >13 1-Jul-05 10:02:35 5.8 2583 .
> >14 1-Jul-05 10:02:35 5.8 5000
> =(2583+5000)/2
*
* 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/