I have a long dataset wherein each observation represents either a hospitalization or ED visit. I am attempting to create two variables that will represent how many total hospitalizations or ED visits a person had. I have included a dataex example below. The variable pid is the patient ID and the type is coded 1 for ED visits and 2 for hospitalizations. For example, the first PID 100006 has one hospitalization (so the new hospital variable would be "1" for each row of that ID) and one ED visit (so the new ED variable would be "1" for each row of that ID).
Can anyone suggest an easy way to do this?
Thank you!
Sarah
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input long pid float type 1000008 1 1000008 2 1000048 2 1000048 2 1000048 2 1000048 1 1000063 2 1000063 2 1000081 2 1000081 2 1000089 1 1000089 2 1000098 2 1000111 1 1000115 1 1000130 2 1000130 2 1000157 2 1000157 2 1000157 2 1000157 2 1000160 1 1000160 2 1000180 2 1000181 2 1000181 2 1000181 2 1000181 1 1000181 1 1000213 2 1000213 2 1000213 1 1000213 2 1000250 2 1000271 1 1000271 1 1000271 2 1000271 1 1000271 2 1000296 2 1000312 2 1000312 2 1000318 2 1000319 1 1000319 2 1000319 2 1000319 1 1000334 2 1000334 1 1000334 1 1000334 2 1000334 1 1000346 1 1000354 2 1000354 2 1000385 2 1000385 2 1000385 2 1000390 2 1000391 2 1000391 2 1000399 1 1000399 1 1000434 2 1000434 2 1000434 1 1000434 2 1000441 2 1000441 2 1000488 2 1000488 2 1000512 2 1000512 2 1000512 2 1000512 1 1000525 1 1000549 2 1000549 2 1000598 2 1000598 2 1000598 1 1000598 2 1000598 2 1000598 1 1000598 2 1000598 2 1000598 1 1000598 2 1000627 1 1000627 2 1000627 2 1000627 1 1000627 2 1000627 1 1000627 1 1000627 1 1000627 2 1000653 2 1000679 2 1000694 1 end
0 Response to Counting values in long dataset
Post a Comment