I'm currently working on the stock market. I have thousands of stocks and their daily returns. I'm trying to drop stocks (only that month) whose returns are zero more than 10 days a month. For example, stock A's returns are zero 11 days on Jan, and its returns are zero 5days on Feb. I drop stock A's Jan whole observation.
Firstly, I cannot count the number of days when stock returns are zero.
My code is
bys permno mdate : egen zero_days = count(ret==0)
It gives me always the number of month.
permno is stock code, mdate is month identifier, ret is daily return.
How can I fix this? I upload dataex below. Thank you for help.
. dataex
----------------------- copy starting from the next line -----------------------
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input double permno long date double(prc ret) int mdate 10001 20485 8.420000076293945 .01201927661895752 673 10001 20486 8.489899635314941 .008301610127091408 673 10001 20487 8.260000228881836 -.02707916684448719 673 10001 20488 8 -.03147702291607857 673 10001 20489 8.34000015258789 .04250001907348633 673 10001 20492 8.630000114440918 .034772176295518875 673 10001 20493 8.210000038146973 -.04866744577884674 673 10001 20494 8.300000190734863 .010962259955704212 673 10001 20495 8.050000190734863 -.030120480805635452 673 10001 20496 8.300000190734863 .03105589933693409 673 10001 20500 8.25 -.006024119444191456 673 10001 20501 8.199999809265137 -.006060629151761532 673 10001 20502 8.100000381469727 -.012195052579045296 673 10001 20503 7.900000095367432 -.024691391736268997 673 10001 20506 7.860000133514404 -.005063286051154137 673 10001 20507 7.940000057220459 .01017810683697462 673 10001 20508 7.880000114440918 -.007556668017059565 673 10001 20509 7.940000057220459 .0076142060570418835 673 10001 20510 7.840000152587891 -.012594446539878845 673 10001 20513 7.860000133514404 .002551018027588725 673 10001 20514 8.300000190734863 .0559796504676342 674 10001 20515 8.15999984741211 -.016867510974407196 674 10001 20516 8.199999809265137 .0049019563011825085 674 10001 20517 8.199999809265137 0 674 10001 20520 8.1899995803833 -.001219540135934949 674 10001 20521 8.079999923706055 -.013430972583591938 674 10001 20522 8.029999732971191 -.006188142579048872 674 10001 20523 8.119999885559082 .011207989417016506 674 10001 20524 8 -.014778311364352703 674 10001 20527 7.980000019073486 -.002499997615814209 674 10001 20528 7.900000095367432 -.010025053285062313 674 10001 20529 8.069999694824219 .02151893638074398 674 10001 20530 8.119999885559082 .0061958106234669685 674 10001 20531 8.199999809265137 .009852207265794277 674 10001 20534 8.199999809265137 0 674 10001 20535 8.199999809265137 0 674 10001 20536 8.239999771118164 .004878044128417969 674 10001 20537 8.079999923706055 -.019417457282543182 674 10001 20541 7.900000095367432 -.02227720618247986 674 10001 20542 7.889999866485596 -.0012658517807722092 674 10001 20543 7.889999866485596 0 674 10001 20544 7.809999942779541 -.010139407590031624 674 10001 20545 7.800000190734863 -.0012803779682144523 675 10001 20548 7.769999980926514 -.0038461806252598763 675 10001 20549 7.230000019073486 -.06949806213378906 675 10001 20550 7.079999923706055 -.020746901631355286 675 10001 20551 7.369999885559082 .04096044600009918 675 10001 20552 7.579999923706055 .02849389985203743 675 10001 20555 7.769999980926514 .025065971538424492 675 10001 20556 7.869999885559082 .012870000675320625 675 10001 20557 7.800000190734863 .0006353631615638733 675 10001 20558 7.599999904632568 -.0256410613656044 675 10001 20559 7.449999809265137 -.01973685435950756 675 10001 20562 7.21999979019165 -.030872486531734467 675 10001 20563 7.309999942779541 .012465395033359528 675 10001 20564 7.179999828338623 -.01778387278318405 675 10001 20565 7 -.025069614872336388 675 10001 20566 7.179999828338623 .025714261457324028 675 10001 20569 7.199999809265137 .002785512711852789 675 10001 20570 7.349999904632568 .020833346992731094 675 10001 20571 7.28000020980835 -.009523767977952957 675 10001 20572 7.329999923706055 .006868092343211174 675 10001 20573 7.300000190734863 -.004092732910066843 675 10001 20576 6.909999847412109 -.05342470481991768 676 10001 20577 7.039999961853027 .018813330680131912 676 10001 20578 7.039999961853027 0 676 10001 20579 7.014999866485596 -.0035511499736458063 676 10001 20580 6.880000114440918 -.019244441762566566 676 10001 20583 6.889999866485596 .0014534522779285908 676 10001 20584 6.96999979019165 .011611019261181355 676 10001 20585 7.050000190734863 .0114778196439147 676 10001 20586 7.099999904632568 .00709215784445405 676 10001 20587 7.150000095367432 .007042280398309231 676 10001 20590 7.119999885559082 -.004195833578705788 676 10001 20591 7.139999866485596 .0028089862316846848 676 10001 20592 7.059999942779541 -.011204470880329609 676 10001 20593 6.900000095367432 -.022662868723273277 676 10001 20594 6.880000114440918 -.0028985480312258005 676 10001 20597 6.900000095367432 .0029069739393889904 676 10001 20598 6.900000095367432 0 676 10001 20599 6.949999809265137 .007246335037052631 676 10001 20600 6.960000038146973 .0014388818526640534 676 10001 20601 7.059999942779541 .014367802068591118 676 10001 20605 7.139999866485596 .011331434361636639 676 10001 20606 7.110000133514404 -.004201643168926239 677 10001 20607 7.010000228881836 -.014064683578908443 677 10001 20608 7.059999942779541 .0071326266042888165 677 10001 20611 7.079999923706055 .0028328585904091597 677 10001 20612 6.939799785614014 -.019802279770374298 677 10001 20613 7 .008674632757902145 677 10001 20614 7 0 677 10001 20615 7.010000228881836 .0014286041259765625 677 10001 20618 6.96999979019165 -.005706196650862694 677 10001 20619 6.920000076293945 -.007173560094088316 677 10001 20620 7.03000020980835 .015895972028374672 677 10001 20621 7.099999904632568 .00995728187263012 677 10001 20622 6.989999771118164 -.015492976643145084 677 10001 20625 6.980000019073486 -.0014305796939879656 677 10001 20626 7.010000228881836 .004298024345189333 677 10001 20627 7.03000020980835 .0028530643321573734 677 end format %d date format %tm mdate
Listed 100 out of 4641809 observations
Use the count() option to list more
0 Response to Count function with bysort
Post a Comment