Hello,
I have a dataset of individual trading data representing investors buying and selling behavior. My dataset consists of investor identifier, stock identifier (cusip), date of purchase or sale of stocks, amount of stocks purchased or sold (negative sign indicates sale of stock) and the price of the stock. Each time a stock is sold in the investor stock portfolio, I additionally evaluate the other stocks in his portfolio using closing prices from CRSP. These "unrealized stocks" are the stocks where the variable "stock" == . . An unrealized stock is a stock the investor has in his portfolio but does not sell on the particular date.
Now, I want to calculate the number of days an investor has been holding the stock. So, I want to take the purchase date and calculate the difference between the sale date and I want to take the inital purchase date if the investor bought multiple times the same stock the purchase price used to calculate holding period should be the date were the stock was first bought. But I do not know how to do this properly maybe someone could help me here.
Thanks in advance!
I have a dataset of individual trading data representing investors buying and selling behavior. My dataset consists of investor identifier, stock identifier (cusip), date of purchase or sale of stocks, amount of stocks purchased or sold (negative sign indicates sale of stock) and the price of the stock. Each time a stock is sold in the investor stock portfolio, I additionally evaluate the other stocks in his portfolio using closing prices from CRSP. These "unrealized stocks" are the stocks where the variable "stock" == . . An unrealized stock is a stock the investor has in his portfolio but does not sell on the particular date.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float(investor cusip) str9 dates float(stock price date) 1 1234 "19910108" 100 10 11330 1 4321 "19910203" 50 25 11356 1 1234 "19910505" -100 12 11447 1 4321 "19910505" . 30 11447 2 5678 "19920407" 200 75 11785 2 5678 "19920409" 50 72 11787 2 5678 "19920802" -250 50 11902 3 1234 "19921105" 100 100 11997 3 1234 "19921111" 100 85 12003 3 1234 "19921212" -150 110 12034 3 1234 "19921220" -50 150 12042 4 8910 "19930218" 100 500 12102 4 7891 "19930509" 25 10 12182 4 7891 "19930606" 50 8 12210 4 8910 "19931006" -75 510 12332 4 7891 "19931006" . 15 12332 4 7891 "19931020" 30 11 12346 4 8910 "19931020" . 525 12346 4 8910 "19931130" -25 530 12387 4 7891 "19931130" . 16 12387 5 4657 "19940506" 40 260 12544 5 8585 "19940512" 50 25 12550 5 4657 "19940513" 20 250 12551 5 8585 "19940601" -20 15 12570 5 4657 "19940601" . 251 12570 5 8585 "19940605" 30 20 12574 5 4657 "19940707" -50 300 12606 5 8585 "19940707" . 26 12606 5 8585 "19940725" 50 30 12624 5 4567 "19940725" . 330 12624 6 1234 "19950506" 500 100 12909 6 1234 "19950606" 250 110 12940 6 1234 "19950607" -750 150 12941 6 1234 "19950707" 100 110 12971 6 1234 "19950709" -100 115 12973 7 4567 "19950111" 5 10 12794 7 4567 "19950115" 10 8 12798 7 4567 "19950120" -7 9 12803 7 4567 "19950201" 8 15 12815 7 4567 "19950209" -16 16 12823 end format %td date
Thanks in advance!
Comment