Hello,
I have a rather complex problem. I have a unbalanced panel dataset with Insurancenumbers (meaning people) and ATC-Codes (as strings) for prescriptions and want to identify those who have a certain amount of same ATC-Codes to generate new variables. The structure is as follows:
Insurancenumber - ATC
1 - R03
1 - N07
1 - R03
1 - A07
1 - X01
1 - R03
2 - B00
2 - B00
2 - F09
3 - G03
4 - B00
4 - R03
.
I have certain definitions in the form of: If someone had 3 or more times "R03" he gets X1=1 and otherwise X1=0 (one new variable I want to create). If someone has for example 2 or more times "B00" he gets X2=1 and otherwise X2=0. Resulting in:
Insurancenumber - ATC - X1 - X2
1 - R03 - 1 - 0
1 - N07 - 1 - 0
1 - R03 - 1 - 0
1 - A07 - 1 - 0
1 - X01 - 1 - 0
1 - R03 - 1 - 0
2 - B00 - 0 - 1
2 - B00 - 0 - 1
2 - F09 - 0 - 1
3 - G03 - 0 - 0
4 - B00 - 0 - 0
4 - R03 - 0 - 0
.
.
.
If another person had for example both "R03" > 3 and "B00">2, both X1 and X2 would be 1.
I am desperately looking for the command-structure to do this and hope someone has a solution
!
Best regards
Karl Emmert-Fees
I have a rather complex problem. I have a unbalanced panel dataset with Insurancenumbers (meaning people) and ATC-Codes (as strings) for prescriptions and want to identify those who have a certain amount of same ATC-Codes to generate new variables. The structure is as follows:
Insurancenumber - ATC
1 - R03
1 - N07
1 - R03
1 - A07
1 - X01
1 - R03
2 - B00
2 - B00
2 - F09
3 - G03
4 - B00
4 - R03
.
I have certain definitions in the form of: If someone had 3 or more times "R03" he gets X1=1 and otherwise X1=0 (one new variable I want to create). If someone has for example 2 or more times "B00" he gets X2=1 and otherwise X2=0. Resulting in:
Insurancenumber - ATC - X1 - X2
1 - R03 - 1 - 0
1 - N07 - 1 - 0
1 - R03 - 1 - 0
1 - A07 - 1 - 0
1 - X01 - 1 - 0
1 - R03 - 1 - 0
2 - B00 - 0 - 1
2 - B00 - 0 - 1
2 - F09 - 0 - 1
3 - G03 - 0 - 0
4 - B00 - 0 - 0
4 - R03 - 0 - 0
.
.
.
If another person had for example both "R03" > 3 and "B00">2, both X1 and X2 would be 1.
I am desperately looking for the command-structure to do this and hope someone has a solution

Best regards
Karl Emmert-Fees
Comment