[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
"Kieran McCaul" <Kieran.McCaul@uwa.edu.au> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: How to calculate the bid-ask spread in this case? |

Date |
Fri, 31 Jul 2009 07:25:50 +0800 |

... 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: Kieran.McCaul@uwa.edu.au 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: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of stata help Sent: Friday, 31 July 2009 4:20 AM To: statalist@hsphsun2.harvard.edu 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/

**Follow-Ups**:**Re: st: RE: How to calculate the bid-ask spread in this case?***From:*help me <carrot2rabbit@gmail.com>

**References**:**st: How to calculate the bid-ask spread in this case?***From:*stata help <carrot2rabbit@gmail.com>

- Prev by Date:
**Re: st: AW: How to calculate the bid-ask spread in this case?** - Next by Date:
**Re: st: RE: How to calculate the bid-ask spread in this case?** - Previous by thread:
**Re: st: AW: How to calculate the bid-ask spread in this case?** - Next by thread:
**Re: st: RE: How to calculate the bid-ask spread in this case?** - Index(es):

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