DATA::
Unnamed: 0 gvkey date CUSIP conm tic cik PERMNO COMNAM
0
0 1001 1983 00016510 A & M FOOD SERVICES INC AMFD. 723576.0 10015 NaN
1
1 1001 1983 00016510 A & M FOOD SERVICES INC AMFD. 723576.0 10015 A & M FOOD SERVICES INC
2
5 1001 1984 00016510 A & M FOOD SERVICES INC AMFD. 723576.0 10015 A & M FOOD SERVICES INC
3
17 1001 1985 00016510 A & M FOOD SERVICES INC AMFD. 723576.0 10015 A & M FOOD SERVICES INC
4
29 1003 1983 00035410 A.A. IMPORTING CO INC ANTQ 730052.0 10031 NaN
Goal::
Take specific observation's PERMNO for the year(data)
Conditions::
- the observation has gvkey data
- the next year's observation for that gvkey has 'COMNAM' variable's data
for example; year = 1983, gvkey = 1001, next_year = 1984
What I've tried::
df = DATA
df[(df['date'] == year) & (df['date'] == gvkey) & (df[df['date'] == next_year]['COMNAM'].isna() != 1])]
however, it returns, NO OBSERVATIONS..
I think this is because the code contains two mutually exclusive conditions:: df['date'] == year and df['date'] == next_year
Can anyone give me advice? Thanks!