Dear Kieran,
Thank you very much for your help. I think I can get the basic idea
about how to solve my problem.
If someone else has any other idea please feel free to jump in.
-JHS
On Thu, Jul 30, 2009 at 7:25 PM, Kieran McCaul<[email protected]> wrote:
> ...
>
>
> OK, I'll have a go at this. On a more complete dataset the flag
> variable should pick the spread with the smallest time difference.
> Also, I'm not all that familiar with using -tsset-, so someone else may
> come up with something more elegant than this.
>
> Until they do, try something like this:
>
>
> clear
>
> input str3 BondID str8 Date str6 Time Bid_Price Ask_Price
> AAA 20090729 090540 100.00 .
> AAA 20090729 092307 100.05 .
> AAA 20090729 093051 . 101.10
> AAA 20090729 093523 . 101.20
> end
>
> gen double DateTime = clock(Date+Time,"YMDhms")
>
> format DateTime %tc
>
> sort BondID DateTime
>
> by BondID: gen spread = round(Ask_Price[_n] - Bid_Price[_n-1],0.01)
>
> by BondID: gen TimeDiff = round(minutes(DateTime[_n] -
> DateTime[_n-1]),0.01) if spread ~= .
>
> sort BondID spread
> by BondID: gen flag=1 if _n==1 & spread ~=.
>
> sort BondID DateTime
> list
>
>
>
> ______________________________________________
> Kieran McCaul MPH PhD
> WA Centre for Health & Ageing (M573)
> University of Western Australia
> Level 6, Ainslie House
> 48 Murray St
> Perth 6000
> Phone: (08) 9224-2701
> Fax: (08) 9224 8009
> email: [email protected]
> http://myprofile.cos.com/mccaul
> http://www.researcherid.com/rid/B-8751-2008
> ______________________________________________
> If you live to be one hundred, you've got it made.
> Very few people die past that age - George Burns
>
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of stata help
> Sent: Friday, 31 July 2009 4:20 AM
> To: [email protected]
> Subject: st: How to calculate the bid-ask spread in this case?
>
> Dear Statalisters,
>
> I have data of foreign bonds with their trading date and time, and the
> bid and ask prices.
>
> The data structure is as follows:
>
>
> Bond ID Date Time(HHMMSS) Bid_Price Ask_Price
> AAA 20090729 090540 100.00
> AAA 20090729 092307 100.05
> AAA 20090729 093051 101.10
> AAA 20090729 093523 101.20
> .
> .
> .
>
> I want to calculate the "closest-in-time" bid-ask spread of the
> bonds(in this case, 101.10-100.05 = 1.05). Since it is my first time
> to deal with this type of data I don't know how to do that. Could any
> of you let me know what command I should use or how to program to get
> the bid-ask spread?
>
> Thank you very much.
>
> JHS
> *
> * 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/
>
>
>
> *
> * 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/
>
*
* 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/