How so subset observations in a matrix?
조회 수: 1(최근 30일)
I have a matrix that has the follwing columns:
[GVKEY FYEAR SALE ASSET]
FYEAR ranges from 2005-2019 and there are many GVKEYs which are basically identifiers. I want to keep only those GVKEYS(observations) for which I have the entire 2005-2019 observations, as some may have only sub ranges like 2007-2009.
How do I do this?
Githin George 2022년 7월 25일
편집: Githin George 2022년 7월 25일
My understanding is that you want to filter out the rows of a matrix for those GVKEYs having observations from 2005-2019. I would like to make the assumption that the year range is continuous. You could try out the following piece of code.
keys = unique(data(:,1))
keyData = data(data==keys(i),:)
% from here you can compare with keyData length or compare the year
% array to the 2nd column and based on that modify values in the actual
% data array.
col2 = sort(keyData(:,2))
flag = isequal(col2,2005:2019)
if(flag == 0)
data(data==keys(i),:) = 
I Hope this helps.