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

 From "Kieran McCaul" To 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 TimeDiff = round(minutes(DateTime[_n] -

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

Dear Statalisters,

I have data of foreign bonds with their trading date and time, and the

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
.
.
.

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

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/
```