Hello,
My data is currently in a wide format, at the id/month/yr level. Each individual, in a month-yr, can use as many programs as they need and these are shaped wide like program1 program2 program3 (imagine programs like Medicaid, health services, etc). However, instead of saying medicaid, they are coded with numbers (i.e. 27=medicaid.) There is a data example below. So, for instance, for the person with ID 721 below, I want to create a variable that counts how many times a certain number shows up across his observations. So, you can see for instance, that the number 78 (a program key) shows up in his first observation, and in his third observation (but it is the second program he uses and thus under program_key2 in that month-yr). So, for 721 I would have some variable that says count_78=2. This means 2 times in his history, he has used program 78. Thanks in advance for help on this and let me know if anything is confusing.
* Example generated by -dataex-. For more info, type help dataex
clear
input long id int(program_key1 program_key2)
721 78 84
721 66 70
721 299 78
809 84 216
809 78 211
809 66 84
end
[/CODE]
My data is currently in a wide format, at the id/month/yr level. Each individual, in a month-yr, can use as many programs as they need and these are shaped wide like program1 program2 program3 (imagine programs like Medicaid, health services, etc). However, instead of saying medicaid, they are coded with numbers (i.e. 27=medicaid.) There is a data example below. So, for instance, for the person with ID 721 below, I want to create a variable that counts how many times a certain number shows up across his observations. So, you can see for instance, that the number 78 (a program key) shows up in his first observation, and in his third observation (but it is the second program he uses and thus under program_key2 in that month-yr). So, for 721 I would have some variable that says count_78=2. This means 2 times in his history, he has used program 78. Thanks in advance for help on this and let me know if anything is confusing.
* Example generated by -dataex-. For more info, type help dataex
clear
input long id int(program_key1 program_key2)
721 78 84
721 66 70
721 299 78
809 84 216
809 78 211
809 66 84
end
[/CODE]
Comment