Hi there,

I'm working on a large dataset containing all stock trades from a large brokerage house. The variables are account number (hhnum), stock (cusip), date bought or sold (date), and quantity and price bought or sold. Below are the first couple of lines.

I have to omit some observations however for my analysis: Whenever an investor sells more of one stock over the period than he has bought over the period, all observations from that investor buying or selling that stock should be dropped (my analysis will include the average purchase price, and if more is sold than bought, I cannot calculate this).

Array

I'm fairly new to STATA and tried playing around with foreach, but so far haven't come up with anything that could do the job.

Could anyone point me in the right direction?

Philippe