I have the following dataset:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input double idfirm float id_molecule 1 434 1 434 1 1223 1 301 1 832 1 639 1 800 1 800 2 1439 2 1439 2 1392 2 1392 2 1865 2 395 2 1439 2 746 2 301 2 301 2 1439 2 746 3 399 3 474 3 153 3 1615 3 477 3 1792 3 23 3 1804 3 1146 3 961 3 1804 3 273 4 281 4 1383 4 1992 4 393 4 827 4 958 4 80 4 983 4 783 4 1626 4 210 4 104 5 961 6 1905 6 1905 6 1905 6 1905 6 1905 6 1905 7 963 7 963 7 963 7 963 7 963 7 963 7 963 7 963 7 963 8 1821 8 1402 8 1022 8 832 8 1162 8 1022 8 885 8 495 8 898 8 1821 8 1440 8 958 9 1372 9 441 9 1482 9 1482 9 228 9 38 9 1727 9 1787 9 425 9 959 9 661 9 1985 10 495 11 800 11 1511 11 1511 11 800 11 800 11 800 11 800 12 1792 12 1792 12 1792 12 1792 13 1665 13 1665 13 1665 13 1025 end
1) generate a counter taking on value 1 if an id_molecule is observed for the first time within a same firm (idfirm) and 0 otherwise so that for instance in case of firm with idfirm = 1 I will have:
Counter
1
0
1
1
1
1
1
0
2) Generate counter taking on value 1 if the id_molecule is observed for the first time in all the sample. So for instance, in the date I have displayed, 434 will have counter = 1 (just the first one) because it appears just for firm having idfirm =1, while for instance 800 will take on value 0 in that it appears also for other firms (e.g. firm with idfirm = 11).
Can someone please help me?
Thank you very much,
Federico
0 Response to Counter
Post a Comment