Hi guys - Need some help with comparing a value in a cell with previous values in a panel data. The is an inventor-year panel with a variable subclass that describes the subclasses in which each inventor was granted patent each year. The data looks something like this:
inventor year patent subclass
10069 1982 4346109 859
10069 1983 4382151 875
10069 1983 4386227 219
10069 1984 4481217 894
10069 1984 4468458 134
10069 1984 4435423 927
10069 1984 4454126 41
10069 1984 4454330 497
10069 1984 4454330 219
10069 1984 4455316 419
10069 1984 4482734 960
10069 1985 4522759 821
10069 1985 4491592 560
10069 1986 4571408 134
10069 1986 4599328 134
10069 1986 4603126 739
10069 1986 4613593 106
10069 1986 4576963 532
10069 1987 4655973 35
10069 1987 4639450 176
I want to compare values in the subclass and identify if the inventor has used the subclass in the previous 4 years and if yes, generate a new variable that will return 1 and 0 otherwise. For example, the new variable, i,e., old subclass should return value of 1 if the inventor has used the subclasses in the last 4 years and 0 otherwise. To take an example from the table above, the old subclass variable should generate 1 for the green entry as the inventor has used the subclass 134 within last 4 years (1984) and 0 for red entry has the inventor has not used subclass 106 within previous 4 years. Hope you will be able to help.
Best
Rajat
inventor year patent subclass
10069 1982 4346109 859
10069 1983 4382151 875
10069 1983 4386227 219
10069 1984 4481217 894
10069 1984 4468458 134
10069 1984 4435423 927
10069 1984 4454126 41
10069 1984 4454330 497
10069 1984 4454330 219
10069 1984 4455316 419
10069 1984 4482734 960
10069 1985 4522759 821
10069 1985 4491592 560
10069 1986 4571408 134
10069 1986 4599328 134
10069 1986 4603126 739
10069 1986 4613593 106
10069 1986 4576963 532
10069 1987 4655973 35
10069 1987 4639450 176
I want to compare values in the subclass and identify if the inventor has used the subclass in the previous 4 years and if yes, generate a new variable that will return 1 and 0 otherwise. For example, the new variable, i,e., old subclass should return value of 1 if the inventor has used the subclasses in the last 4 years and 0 otherwise. To take an example from the table above, the old subclass variable should generate 1 for the green entry as the inventor has used the subclass 134 within last 4 years (1984) and 0 for red entry has the inventor has not used subclass 106 within previous 4 years. Hope you will be able to help.
Best
Rajat
Comment