Hi,
I am using Stata 13.1 for Windows and have a dataset with the following fields: ID, nlab, ntesttype, testdate where the fields nlab and ntesttype are numeric variables (recoded from string variables) and contain the values 1 to 9 and 1 to 4 respectively. A person can have multiple records for repeated tests at the same or multiple labs occurring on different dates.
How can I loop through all records for each person (using their ID) and produce a file of a single summary record (for each person) which contains the following information: Id, lab, testtype where both lab and testtype contain a summary of all combinations occurring e.g. if a person had a test done at lab 1 only, then compute lab=1; if tests done at labs 1 and 2 then lab=12; if tests done at labs 1 to lab 3 then lab=123. Similarly for test type. If test type 1 only done, compute testtype=1; if test types 1 & 2 done, then testtype=12; if test types 1 to 3, then testtype=123 etc. There could be duplicates by lab or test type which can be included e.g. if a person had the same test 1 done on different dates at lab 1, then compute lab=11 & testtype=11; if 2 different tests 2 & 3 done at lab 2 on different dates then compute lab=22 & testtype=23.
What would be the best way of doing this to collapse the file to produce one single summary record per person? I have looked at a few different commands in Stata, however, there appears to be no command capable of directly doing this. Any help or suggestions would be much appreciated.
Thanks
Kevin
I am using Stata 13.1 for Windows and have a dataset with the following fields: ID, nlab, ntesttype, testdate where the fields nlab and ntesttype are numeric variables (recoded from string variables) and contain the values 1 to 9 and 1 to 4 respectively. A person can have multiple records for repeated tests at the same or multiple labs occurring on different dates.
How can I loop through all records for each person (using their ID) and produce a file of a single summary record (for each person) which contains the following information: Id, lab, testtype where both lab and testtype contain a summary of all combinations occurring e.g. if a person had a test done at lab 1 only, then compute lab=1; if tests done at labs 1 and 2 then lab=12; if tests done at labs 1 to lab 3 then lab=123. Similarly for test type. If test type 1 only done, compute testtype=1; if test types 1 & 2 done, then testtype=12; if test types 1 to 3, then testtype=123 etc. There could be duplicates by lab or test type which can be included e.g. if a person had the same test 1 done on different dates at lab 1, then compute lab=11 & testtype=11; if 2 different tests 2 & 3 done at lab 2 on different dates then compute lab=22 & testtype=23.
What would be the best way of doing this to collapse the file to produce one single summary record per person? I have looked at a few different commands in Stata, however, there appears to be no command capable of directly doing this. Any help or suggestions would be much appreciated.
Thanks
Kevin
Comment