Dear statalisters,
I have trouble calculating cumulative volumes. The data looks the following:
I want to calculate the cumulative volume for each secuity in account_number 1. The easiest way to do so is to use sum(), however, the cumulative volume should not drop below zero. The ideal cumvolume variable should look like this:
I tried to use the if/else command but I am not able to solve my problem.
Does anyone know how to calculate the cumvolume such that it does not drop below zero?
Thank you all in advance,
Sabine
I have trouble calculating cumulative volumes. The data looks the following:
account_number | security_number | Volume |
1 | 10 | 100 |
1 | 10 | 100 |
1 | 10 | -250 |
1 | 10 | 100 |
1 | 11 | 150 |
1 | 11 | -50 |
1 | 11 | 100 |
1 | 12 | 300 |
1 | 12 | -300 |
account_number | security_number | Volume | Cumvolume |
1 | 10 | 100 | 100 |
1 | 10 | 100 | 200 |
1 | 10 | -250 | 0 |
1 | 10 | 100 | 100 |
1 | 11 | 150 | 150 |
1 | 11 | -50 | 100 |
1 | 11 | 100 | 200 |
1 | 12 | 300 | 300 |
1 | 12 | -300 | 0 |
Does anyone know how to calculate the cumvolume such that it does not drop below zero?
Thank you all in advance,
Sabine
Comment