company_id | year | grant | donor_id |
co_001 | 2003 | 1 | do_100 |
co_001 | 2004 | 0 | |
co_001 | 2005 | 1 | do_200 |
co_001 | 2005 | 1 | do_100 |
co_002 | 2005 | 0 | |
co_002 | 2006 | 1 | do_300 |
co_002 | 2006 | 1 | do_300 |
co_002 | 2006 | 1 | do_500 |
co_003 | 2007 | 1 | do_300 |
co_003 | 2007 | 1 | do_600 |
co_003 | 2007 | 1 | do_600 |
co_003 | 2007 | 1 | do_400 |
co_004 | 2008 | 0 | |
co_004 | 2011 | 1 | do_100 |
Create a variable unique_donors that counts the number of distinct donors for each company each year. E.g. for co_001 in year 2005, there are 2 different donors- do_200 and do_100. Similarly, for co_003 in year 2007, there are a total of 4 grants but 3 unique donors- do_300, do_600 and do_400
Code: egen id= group( company_id)
xtset id
if i do xtset id year then result box is showing repeated years. Then I did
bysort id year donor_id : gen unique_id :_n== 1
But I am unable to get my result. I ask my seniors here where am I going wrong ?
Comment