Thanks a lot for your help! But this is not exactly what I look for. I try to explain it again: The goal is to look what the share of stock sales with a loss in each month is, e.g. in January 20% of overall stocks sold are sold with a loss. And I want to do the same with stock sales with a profit (profti sale). For example, 55% of all stocks sold in March are sold with profit. My data set only shows sales and purchases for each investor and I wanted to create two variable which show me the purchase price of a stock and the sale price of a stock. And these two variables match, so the first line in variable buy price represents a purchase of investor X of stock Y and the equivalent holds for the variable sellprice, that means in the first line of this variable I find the sell price of investor X of stock Y. In a second step, I then would have created an other loop including an if condition to count for every month how many stocks were sold with gain and how many with loss. for example my condition would be "if sell price > buy price" then add to a counter variable +1 with this I would have a new variable with 12 lines (for each month) which represents the amount of profit sales (because the condition is sell price > buy price meaning that the stock was sold with a profit. I hope this explanation helps and you understand what I want to do.
To show an example of what output I want to generate: If you look in my data from #14, the first investor who bought and sold the same stock is investor 3206. In line 5 he bought 1000 stocks of X to a price of 2.25 in 1991 and in line 6 he sold the 1000 stocks of X in December 1993 for 1.0312, as the sale price is lower than the buy price, he sold with a loss. Therefore my variable for loss sales would increase by 1 in line 12 (as the loss was realized in December).
To show an example of what output I want to generate: If you look in my data from #14, the first investor who bought and sold the same stock is investor 3206. In line 5 he bought 1000 stocks of X to a price of 2.25 in 1991 and in line 6 he sold the 1000 stocks of X in December 1993 for 1.0312, as the sale price is lower than the buy price, he sold with a loss. Therefore my variable for loss sales would increase by 1 in line 12 (as the loss was realized in December).
Comment