Below is appended an example data set in which pr represents daily closing price of a stock and st is for daily number shares traded in a stock.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input int stock_id str52 stock str10 month float pr long st 1 "3M India Ltd." "31-05-2002" 282.7 75 1 "3M India Ltd." "03-06-2002" 275.25 125 1 "3M India Ltd." "04-06-2002" 288.5 2020 1 "3M India Ltd." "05-06-2002" 282.6 270 1 "3M India Ltd." "06-06-2002" 284.9 20 1 "3M India Ltd." "07-06-2002" 276.05 52 1 "3M India Ltd." "10-06-2002" . . 1 "3M India Ltd." "11-06-2002" 287.9 715 1 "3M India Ltd." "12-06-2002" 285 420 1 "3M India Ltd." "13-06-2002" 278.7 350 1 "3M India Ltd." "14-06-2002" 283 50 1 "3M India Ltd." "17-06-2002" 287.9 165 1 "3M India Ltd." "18-06-2002" 294.95 911 1 "3M India Ltd." "19-06-2002" 294.5 190 1 "3M India Ltd." "20-06-2002" 294 372 1 "3M India Ltd." "21-06-2002" 284 137 1 "3M India Ltd." "24-06-2002" 290.05 650 1 "3M India Ltd." "25-06-2002" 289.1 200 1 "3M India Ltd." "26-06-2002" 282.5 50 1 "3M India Ltd." "27-06-2002" 290 110 1 "3M India Ltd." "28-06-2002" 285.15 440 1 "3M India Ltd." "01-07-2002" 287.2 500 1 "3M India Ltd." "02-07-2002" 285.05 3370 1 "3M India Ltd." "03-07-2002" 295 2595 1 "3M India Ltd." "04-07-2002" 324.5 9425 1 "3M India Ltd." "05-07-2002" 318.3 2368 1 "3M India Ltd." "08-07-2002" 318 1967 1 "3M India Ltd." "09-07-2002" 323.6 421 1 "3M India Ltd." "10-07-2002" 313.4 995 1 "3M India Ltd." "11-07-2002" 302 925 1 "3M India Ltd." "12-07-2002" 301.7 1790 1 "3M India Ltd." "15-07-2002" 295 180 1 "3M India Ltd." "16-07-2002" 300 685 1 "3M India Ltd." "17-07-2002" 292 320 1 "3M India Ltd." "18-07-2002" 295.85 200 1 "3M India Ltd." "19-07-2002" 303.5 1771 1 "3M India Ltd." "22-07-2002" 291 880 1 "3M India Ltd." "23-07-2002" 302.75 1859 1 "3M India Ltd." "24-07-2002" 299.45 980 1 "3M India Ltd." "25-07-2002" 301 535 1 "3M India Ltd." "26-07-2002" 300 2067 1 "3M India Ltd." "29-07-2002" 301.7 1167 1 "3M India Ltd." "30-07-2002" 300 1480 1 "3M India Ltd." "31-07-2002" 300 1943 1 "3M India Ltd." "01-08-2002" 300 351 1 "3M India Ltd." "02-08-2002" 302.9 276 1 "3M India Ltd." "05-08-2002" 303.75 121 1 "3M India Ltd." "06-08-2002" 304 310 1 "3M India Ltd." "07-08-2002" 306.8 276 1 "3M India Ltd." "08-08-2002" 300 140 1 "3M India Ltd." "09-08-2002" 300.75 350 1 "3M India Ltd." "12-08-2002" 300.4 30 1 "3M India Ltd." "13-08-2002" 300 312 1 "3M India Ltd." "14-08-2002" 300 650 1 "3M India Ltd." "16-08-2002" 304.1 100 1 "3M India Ltd." "19-08-2002" 300 248 1 "3M India Ltd." "20-08-2002" 303 115 1 "3M India Ltd." "21-08-2002" 301.95 499 1 "3M India Ltd." "22-08-2002" 302.1 50 1 "3M India Ltd." "23-08-2002" 303.4 375 1 "3M India Ltd." "26-08-2002" . . 1 "3M India Ltd." "27-08-2002" 305 590 1 "3M India Ltd." "28-08-2002" 305.25 175 1 "3M India Ltd." "29-08-2002" 305 100 1 "3M India Ltd." "30-08-2002" 316 595 1 "3M India Ltd." "02-09-2002" 315 1001 1 "3M India Ltd." "03-09-2002" 313.5 64 1 "3M India Ltd." "04-09-2002" 315 1165 1 "3M India Ltd." "05-09-2002" 315 347 1 "3M India Ltd." "06-09-2002" 310.4 239 1 "3M India Ltd." "09-09-2002" 306.5 115 1 "3M India Ltd." "11-09-2002" 310 632 1 "3M India Ltd." "12-09-2002" . . 1 "3M India Ltd." "13-09-2002" 310 1345 1 "3M India Ltd." "16-09-2002" 310 26000 1 "3M India Ltd." "17-09-2002" 328.35 26389 1 "3M India Ltd." "18-09-2002" 325 692 1 "3M India Ltd." "19-09-2002" 320.05 704 1 "3M India Ltd." "20-09-2002" 316.9 110 1 "3M India Ltd." "23-09-2002" 315.35 390 1 "3M India Ltd." "24-09-2002" 312.6 670 1 "3M India Ltd." "25-09-2002" 314.4 371 1 "3M India Ltd." "26-09-2002" 316.75 100 1 "3M India Ltd." "27-09-2002" 315.1 900 1 "3M India Ltd." "30-09-2002" 315 730 1 "3M India Ltd." "01-10-2002" 311 10 1 "3M India Ltd." "03-10-2002" 315 376 1 "3M India Ltd." "04-10-2002" 312 190 1 "3M India Ltd." "07-10-2002" . . 1 "3M India Ltd." "08-10-2002" 311.8 175 1 "3M India Ltd." "09-10-2002" 315.1 10 1 "3M India Ltd." "10-10-2002" 315 200 1 "3M India Ltd." "11-10-2002" 315 780 1 "3M India Ltd." "14-10-2002" 315 26 1 "3M India Ltd." "16-10-2002" 315 900 1 "3M India Ltd." "17-10-2002" 315 620 1 "3M India Ltd." "18-10-2002" 315 270 1 "3M India Ltd." "21-10-2002" 314 375 1 "3M India Ltd." "22-10-2002" 313 1260 1 "3M India Ltd." "23-10-2002" 313.2 205 end
Where Ri,d is the return of stock i on day d measured as a decimal; VOLDi,d is the dollar volume of stock i traded on day d, calculated as the closing price of the stock times the number of shares traded on the given date, measured in millions of dollars; and D is the number of the days in a month. Since, the distribution of illiq is highly skewed, for this reason; a log transformed version of illiq is generated.
The example dataset and explanation of the illiq measure follows the code for the given purpose. Before I may use it, I want to get it confirmed whether the given code is correctly specified as per above definitions.
Code:
* Change date to STATA format gen date1=date(month,"DMY") format date1 %td drop month rename date1 date gen mdate= mofd(date) format mdate %tm * Calculate Returns, Volume and filter data bysort stock_id (date) : gen rt =((pr[_n]-pr[_n-1])/pr[_n-1]) gen vol=st*pr replace vol=. if vol==0 * Calculate Amihud's measure of illiquidity egen validobs=count(rt), by(stock mdate) bysort stock_id mdate: egen ret_div_vol = sum(abs(rt/vol)) bysort stock_id mdate: gen illiq = ret_div_vol*(1/validobs)*1000000 collapse(mean) illiq validobs, by(stock_id stock mdate) replace illiq=. if validobs<15 drop validobs gen illiq_ln=ln(1+illiq)
Comment