Drop all entries of a category based on one condition
10 views (last 30 days)
Show older comments
Simon Jurgies
on 17 Mar 2021
Edited: Cris LaPierre
on 17 Mar 2021
I'm working with a 745820x4 table containing the PermNo., date, CUSIP and stock price of a multitude of shares. The data is sorted such that the full time series of a stock is listed below the full time series of the following stock and so forth. (Pls see photo below). I am trying to exclude companies from the sample once their share price drops below 1USD based on the unique identifier CUSIP in column 3. I have started to try with a combination of a for and an if loop but i cant figure out how it could even work. So for example in the picture below, the share price of the company with the CUSIP 89026070 has share price below USD 1 and i now want to drop all entries for the respective comany.
nRows = size(crsp,1)
for i = 1:nRows
if crsp{i,4}<1
...
end

0 Comments
Accepted Answer
Cris LaPierre
on 17 Mar 2021
Edited: Cris LaPierre
on 17 Mar 2021
nRows = height(crsp)
for i = 1:nRows
if crsp.PRC(i)<1
crsp(crsp.CUSIP==crsp.CUSIP(i),:)=[];
end
end
It might also be possible to use logical indexing and ismember to accomplish this without using a for loop.
More Answers (0)
See Also
Categories
Find more on Call Python from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!