I am attempting to create a group ID which identifies each unique combination of the variables "investorid", "AnnounceDate2", and "uniqueinvestmentid" in the example data below.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(investorid AnnounceDate2) str11 uniqueinvestmentid 1 17995 "16x3307" 1 17995 "16x3307" 1 17995 "16x3307" 1 17995 "16x3307" 1 18443 "16x13109" 1 18567 "16x3990" 1 18604 "16x12503" 1 18736 "16x6502" 1 19153 "16x7257" 1 19450 "16x2982" 1 19801 "16x11283" 1 19844 "16x11559" 1 19927 "16x11810" 1 19996 "16x4271" 1 20032 "16x6827" 1 20187 "16x6907" 1 20206 "16x5897" 1 20502 "16x6593" 1 20545 "16x6809" 1 20683 "16x4722" 1 20698 "16x4745" 1 20759 "16x9229" 1 20836 "16x6372" 1 20957 "16x12705" 1 20978 "16x2978" 1 21154 "16x103" 1 21172 "16x2978" 1 21202 "16x4231" 1 21535 "16x5931" 2 20226 "17x4326" end format %td AnnounceDate2
Code:
egen investmentid = group(investorid AnnounceDate2 uniqueinvestmentid)
Code:
bysort investorid: egen investmentid = group(AnnounceDate2 uniqueinvestmentid)
I tried to do the following as well:
Code:
bysort investorid: gen investmentid=_n replace investmentid[_n]=investmentid [_n-1] if AnnounceDate2[_n]==AnnounceDate2[_n-1] & uniqueinvestmentid[_n]==uniqueinvestmentid[_n-1]
Given all of the above - does anyone have any suggestions as to how I might achieve what I'd like to do here? It seems like a fairly easy issue in terms of logic but I cannot get there. Thanks in advance for any help you can provide!
0 Response to Creating a group ID based on multiple variables: no bysort & no weights allowed
Post a Comment