Title: How to calculate average in different interval ?
---------------------------------------------
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
Thanks
Gary
Gary Tian, PhD
Senior Lecturer
School of Economics and Finance
Parramatta Campus, EDG89
Locked Bag, 1797 Penrith South DC
NSW 1797 Australia
Tel: 61 2 9685 9093
Fax: 61 2 9685 9105
Email: [email protected]
________________________________
From: [email protected] on behalf of Badri
Sent: Thu 4/05/2006 7:07 PM
To: [email protected]
Subject: st:Re.how to create yearly lag in monthly data?
Dear all,
Thanks a lot for your suggestions. In fact, I had already done what
Nick had suggested and I was skeptical whether it was right. I now
realise the power and potential of stata. It's smart indeed..
Thanks again
Badri Narayanan G.,
*
* 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/
<<winmail.dat>>