Hi,
My data has the following variables:
date - date test was done
time - time test was done
test - type of test done
sampleid - blood sample id
cutoff - positive or negative
The blood sample is tested first for phad, and if positive, other tests are done as follow up.
If phad is negative, none or other tests may be performed.
I would like to know for those phad positives, what other tests / how many tests were done on a sample as follow-up
and for those phad negatives, what other tests /how many tests were done as follow-up?
I tried the egen, bysort, tag, gen nvals, etc but was unsuccessful. In my mind, I need to be able to cluster the tests under a sampleID first.
I am new to STATA so any help will be appreciated. Thank you very much.
[CODE]
* Example generated by -dataex-. For more info, type help dataex
clear
input int date double time str5 testname str89 sampleid str8 cutoff
22648 -1893416595000 "phad" "PeyKLtCODRVO7BENTtPwCQ==" "Positive"
22648 -1893416580000 "phad" "irvi/SNYocsQoHRSsg1m8g==" "Positive"
22648 -1893416565000 "ex1" "irvi/SNYocsQoHRSsg1m8g==" "Positive"
22648 -1893416550000 "phad" "jfSmQZ2R7B6DrOU9lJTEGg==" "Positive"
22648 -1893416519999.9998 "phad" "7oSu4OID0/6Usc45pe1HKg==" "Positive"
22648 -1893416324999.9998 "phad" "DQlh6TSrYG97g71xC+Mdpg==" "Negative"
22648 -1893416310000.0002 "phad" "H7FuvMSPbAjSAmNs89hH9Q==" "Positive"
22648 -1893416280000 "phad" "AmfTKYIHOxx7ddaVQASS1g==" "Positive"
22648 -1893416235000 "phad" "/PGBexncCsp1CnIz+9Oq0w==" "Negative"
22648 -1893416205000 "phad" "gjPXaCBDrJyATAtfeRHi+A==" "Negative"
22648 -1893416175000 "phad" "e70CjJ6LJccvLvp+aLFd+g==" "Negative"
22648 -1893416145000 "phad" "L20ehp0dOXp6xDO8ybkeUw==" "Negative"
22648 -1893416115000 "mx1" "9/ISGxHkGOUHYFKfOf8HIg==" "Negative"
22648 -1.8934161e+12 "phad" "9/ISGxHkGOUHYFKfOf8HIg==" "Negative"
22648 -1893416055000 "phad" "txfSH0m1cj98LP0uACRgyg==" "Negative"
22648 -1893415905000 "phad" "OH5il0g7viGQJEtAeJ5Mag==" "Negative"
22648 -1893415725000 "phad" "3Oxs+ClVgKaUtgPDcNI3oA==" "Positive"
22648 -1893415710000 "phad" "8ZuoqOzlzC8SXGnvE6YCGQ==" "Negative"
22648 -1893415380000 "phad" "I6JdP24sqn3K1UExuAruug==" "Negative"
22648 -1893415094000 "phad" "TapPt8PZKC5LZhhu/S9H1A==" "Positive"
22648 -1893414989000 "phad" "LU/uVvgI2pX6WUhnOGg0Mw==" "Positive"
22648 -1893412918999.9998 "f17" "XkM7PLLj+eb8y4n9mVkb1A==" "Positive"
22648 -1893412904000 "phad" "XkM7PLLj+eb8y4n9mVkb1A==" "Positive"
22648 -1893412889000 "f13" "XkM7PLLj+eb8y4n9mVkb1A==" "Negative"
22648 -1893412874000 "phad" "MTf5nOID61vXnRuHInFlGA==" "Negative"
22648 -1893412814000.0002 "phad" "V6Oq9mwb6cGMzwpIXNqJLQ==" "Negative"
22648 -1893412727000 "phad" "vYbgwRdsXcH4y8dIPIXcKA==" "Negative"
22648 -1893412667000 "f1" "Zv6ID4o/QAfr3X3Dza5ExA==" "Negative"
22648 -1893412607000.0002 "f13" "Zv6ID4o/QAfr3X3Dza5ExA==" "Negative"
22648 -1893412574000 "phad" "M9dZjeFCQxDzqVuVQdg4sw==" "Negative"
22648 -1893412547999.9998 "f17" "Zv6ID4o/QAfr3X3Dza5ExA==" "Negative"
22648 -1893412529000.0002 "phad" "hK7FsVzGh+UOPcghu79mEA==" "Negative"
22648 -1893412514000 "fx5" "hK7FsVzGh+UOPcghu79mEA==" "Negative"
22648 -1893412499000 "f26" "hK7FsVzGh+UOPcghu79mEA==" "Negative"
22648 -1893412488000 "f2" "Zv6ID4o/QAfr3X3Dza5ExA==" "Negative"
22648 -1893412484000 "f27" "hK7FsVzGh+UOPcghu79mEA==" "Negative"
22648 -1893412454000 "phad" "vcaNk03gUieE+ERtx39qcA==" "Negative"
22648 -1893412428000 "f5" "Zv6ID4o/QAfr3X3Dza5ExA==" "Negative"
22648 -1893412368000 "phad" "Zv6ID4o/QAfr3X3Dza5ExA==" "Negative"
22648 -1893410448000 "f4" "8+zRH6ekRBZD/xXhzTKd0A==" "Negative"
22648 -1893410388000 "phad" "8+zRH6ekRBZD/xXhzTKd0A==" "Negative"
22648 -1893410327999.9998 "phad" "cWbcjj1ZSDK3rB8S1BF4Mw==" "Negative"
22648 -1893409328000 "f1" "GqHR32x68LKsSsv5XzJa1g==" "Negative"
22648 -1893409314000.0002 "f3" "GqHR32x68LKsSsv5XzJa1g==" "Negative"
22648 -1893409297000 "fx1" "GqHR32x68LKsSsv5XzJa1g==" "Negative"
22648 -1893409282000 "fx22" "GqHR32x68LKsSsv5XzJa1g==" "Negative"
22648 -1893409267000.0002 "phad" "GqHR32x68LKsSsv5XzJa1g==" "Negative"
22648 -1893409189000.0002 "phad" "QlLZvojufzIMTV/upBjEMw==" "Negative"
22648 -1.8934091e+12 "phad" "fSSr1zZK/VSIfyuNfF3sTQ==" "Negative"
22648 -1893408769000 "phad" "EiAh6rvdENtxMjf7VO4j4A==" "Negative"
22648 -1893408254000 "phad" "nrVgJ6ty3KpOhPHghtW9pg==" "Negative"
22648 -1893408239000 "phad" "99vfmUfLIfoHjm70eoWogg==" "Negative"
22648 -1893408027000 "f1" "wOGkTeVj7gazr7r5FOLVew==" "Positive"
22648 -1893408012000 "f75" "wOGkTeVj7gazr7r5FOLVew==" "Positive"
22648 -1893407997000 "phad" "wOGkTeVj7gazr7r5FOLVew==" "Positive"
22648 -1893407982000 "f13" "hV3pBnqJwMkid3ho6I/yeA==" "Negative"
22648 -1893407967000 "phad" "hV3pBnqJwMkid3ho6I/yeA==" "Positive"
22648 -1893407951999.9998 "phad" "yQ9PZZYyNr8wzm6W1JsFBQ==" "Negative"
22648 -1893407937000 "d1" "Gd38/MQm9SIQEMFONBYNpA==" "Negative"
22648 -1893407922000 "ex1" "Gd38/MQm9SIQEMFONBYNpA==" "Negative"
22648 -1893407906000 "fx5" "Gd38/MQm9SIQEMFONBYNpA==" "Positive"
22648 -1893407891000 "g6" "Gd38/MQm9SIQEMFONBYNpA==" "Negative"
22648 -1893407876000 "gx3" "Gd38/MQm9SIQEMFONBYNpA==" "Negative"
22648 -1893407861000 "mx1" "Gd38/MQm9SIQEMFONBYNpA==" "Negative"
22648 -1893407846000 "phad" "Gd38/MQm9SIQEMFONBYNpA==" "Negative"
22648 -1893407830999.9998 "t3" "Gd38/MQm9SIQEMFONBYNpA==" "Negative"
22648 -1893407816000.0002 "tx9" "Gd38/MQm9SIQEMFONBYNpA==" "Negative"
22648 -1893407786000 "w6" "Gd38/MQm9SIQEMFONBYNpA==" "Negative"
22648 -1893407756000 "fx5" "WHWZS19j4bmY+M2h7RoxZA==" "Negative"
22648 -1893407725000 "m227" "WHWZS19j4bmY+M2h7RoxZA==" "Positive"
22648 -1893407709999.9998 "phad" "WHWZS19j4bmY+M2h7RoxZA==" "Positive"
22648 -1893407650000 "phad" "fmMJSJa0AhHkm2DtmV2Esg==" "Negative"
22648 -1893407541999.9998 "d1" "nTHEsh2/ugDdl3MRZF+XMQ==" "Positive"
22648 -1893407483000 "d2" "nTHEsh2/ugDdl3MRZF+XMQ==" "Positive"
22648 -1893407423000 "d71" "nTHEsh2/ugDdl3MRZF+XMQ==" "Negative"
22648 -1893407391000 "phad" "D+7AqfHkECBND3NGT9qRfQ==" "Negative"
My data has the following variables:
date - date test was done
time - time test was done
test - type of test done
sampleid - blood sample id
cutoff - positive or negative
The blood sample is tested first for phad, and if positive, other tests are done as follow up.
If phad is negative, none or other tests may be performed.
I would like to know for those phad positives, what other tests / how many tests were done on a sample as follow-up
and for those phad negatives, what other tests /how many tests were done as follow-up?
I tried the egen, bysort, tag, gen nvals, etc but was unsuccessful. In my mind, I need to be able to cluster the tests under a sampleID first.
I am new to STATA so any help will be appreciated. Thank you very much.
[CODE]
* Example generated by -dataex-. For more info, type help dataex
clear
input int date double time str5 testname str89 sampleid str8 cutoff
22648 -1893416595000 "phad" "PeyKLtCODRVO7BENTtPwCQ==" "Positive"
22648 -1893416580000 "phad" "irvi/SNYocsQoHRSsg1m8g==" "Positive"
22648 -1893416565000 "ex1" "irvi/SNYocsQoHRSsg1m8g==" "Positive"
22648 -1893416550000 "phad" "jfSmQZ2R7B6DrOU9lJTEGg==" "Positive"
22648 -1893416519999.9998 "phad" "7oSu4OID0/6Usc45pe1HKg==" "Positive"
22648 -1893416324999.9998 "phad" "DQlh6TSrYG97g71xC+Mdpg==" "Negative"
22648 -1893416310000.0002 "phad" "H7FuvMSPbAjSAmNs89hH9Q==" "Positive"
22648 -1893416280000 "phad" "AmfTKYIHOxx7ddaVQASS1g==" "Positive"
22648 -1893416235000 "phad" "/PGBexncCsp1CnIz+9Oq0w==" "Negative"
22648 -1893416205000 "phad" "gjPXaCBDrJyATAtfeRHi+A==" "Negative"
22648 -1893416175000 "phad" "e70CjJ6LJccvLvp+aLFd+g==" "Negative"
22648 -1893416145000 "phad" "L20ehp0dOXp6xDO8ybkeUw==" "Negative"
22648 -1893416115000 "mx1" "9/ISGxHkGOUHYFKfOf8HIg==" "Negative"
22648 -1.8934161e+12 "phad" "9/ISGxHkGOUHYFKfOf8HIg==" "Negative"
22648 -1893416055000 "phad" "txfSH0m1cj98LP0uACRgyg==" "Negative"
22648 -1893415905000 "phad" "OH5il0g7viGQJEtAeJ5Mag==" "Negative"
22648 -1893415725000 "phad" "3Oxs+ClVgKaUtgPDcNI3oA==" "Positive"
22648 -1893415710000 "phad" "8ZuoqOzlzC8SXGnvE6YCGQ==" "Negative"
22648 -1893415380000 "phad" "I6JdP24sqn3K1UExuAruug==" "Negative"
22648 -1893415094000 "phad" "TapPt8PZKC5LZhhu/S9H1A==" "Positive"
22648 -1893414989000 "phad" "LU/uVvgI2pX6WUhnOGg0Mw==" "Positive"
22648 -1893412918999.9998 "f17" "XkM7PLLj+eb8y4n9mVkb1A==" "Positive"
22648 -1893412904000 "phad" "XkM7PLLj+eb8y4n9mVkb1A==" "Positive"
22648 -1893412889000 "f13" "XkM7PLLj+eb8y4n9mVkb1A==" "Negative"
22648 -1893412874000 "phad" "MTf5nOID61vXnRuHInFlGA==" "Negative"
22648 -1893412814000.0002 "phad" "V6Oq9mwb6cGMzwpIXNqJLQ==" "Negative"
22648 -1893412727000 "phad" "vYbgwRdsXcH4y8dIPIXcKA==" "Negative"
22648 -1893412667000 "f1" "Zv6ID4o/QAfr3X3Dza5ExA==" "Negative"
22648 -1893412607000.0002 "f13" "Zv6ID4o/QAfr3X3Dza5ExA==" "Negative"
22648 -1893412574000 "phad" "M9dZjeFCQxDzqVuVQdg4sw==" "Negative"
22648 -1893412547999.9998 "f17" "Zv6ID4o/QAfr3X3Dza5ExA==" "Negative"
22648 -1893412529000.0002 "phad" "hK7FsVzGh+UOPcghu79mEA==" "Negative"
22648 -1893412514000 "fx5" "hK7FsVzGh+UOPcghu79mEA==" "Negative"
22648 -1893412499000 "f26" "hK7FsVzGh+UOPcghu79mEA==" "Negative"
22648 -1893412488000 "f2" "Zv6ID4o/QAfr3X3Dza5ExA==" "Negative"
22648 -1893412484000 "f27" "hK7FsVzGh+UOPcghu79mEA==" "Negative"
22648 -1893412454000 "phad" "vcaNk03gUieE+ERtx39qcA==" "Negative"
22648 -1893412428000 "f5" "Zv6ID4o/QAfr3X3Dza5ExA==" "Negative"
22648 -1893412368000 "phad" "Zv6ID4o/QAfr3X3Dza5ExA==" "Negative"
22648 -1893410448000 "f4" "8+zRH6ekRBZD/xXhzTKd0A==" "Negative"
22648 -1893410388000 "phad" "8+zRH6ekRBZD/xXhzTKd0A==" "Negative"
22648 -1893410327999.9998 "phad" "cWbcjj1ZSDK3rB8S1BF4Mw==" "Negative"
22648 -1893409328000 "f1" "GqHR32x68LKsSsv5XzJa1g==" "Negative"
22648 -1893409314000.0002 "f3" "GqHR32x68LKsSsv5XzJa1g==" "Negative"
22648 -1893409297000 "fx1" "GqHR32x68LKsSsv5XzJa1g==" "Negative"
22648 -1893409282000 "fx22" "GqHR32x68LKsSsv5XzJa1g==" "Negative"
22648 -1893409267000.0002 "phad" "GqHR32x68LKsSsv5XzJa1g==" "Negative"
22648 -1893409189000.0002 "phad" "QlLZvojufzIMTV/upBjEMw==" "Negative"
22648 -1.8934091e+12 "phad" "fSSr1zZK/VSIfyuNfF3sTQ==" "Negative"
22648 -1893408769000 "phad" "EiAh6rvdENtxMjf7VO4j4A==" "Negative"
22648 -1893408254000 "phad" "nrVgJ6ty3KpOhPHghtW9pg==" "Negative"
22648 -1893408239000 "phad" "99vfmUfLIfoHjm70eoWogg==" "Negative"
22648 -1893408027000 "f1" "wOGkTeVj7gazr7r5FOLVew==" "Positive"
22648 -1893408012000 "f75" "wOGkTeVj7gazr7r5FOLVew==" "Positive"
22648 -1893407997000 "phad" "wOGkTeVj7gazr7r5FOLVew==" "Positive"
22648 -1893407982000 "f13" "hV3pBnqJwMkid3ho6I/yeA==" "Negative"
22648 -1893407967000 "phad" "hV3pBnqJwMkid3ho6I/yeA==" "Positive"
22648 -1893407951999.9998 "phad" "yQ9PZZYyNr8wzm6W1JsFBQ==" "Negative"
22648 -1893407937000 "d1" "Gd38/MQm9SIQEMFONBYNpA==" "Negative"
22648 -1893407922000 "ex1" "Gd38/MQm9SIQEMFONBYNpA==" "Negative"
22648 -1893407906000 "fx5" "Gd38/MQm9SIQEMFONBYNpA==" "Positive"
22648 -1893407891000 "g6" "Gd38/MQm9SIQEMFONBYNpA==" "Negative"
22648 -1893407876000 "gx3" "Gd38/MQm9SIQEMFONBYNpA==" "Negative"
22648 -1893407861000 "mx1" "Gd38/MQm9SIQEMFONBYNpA==" "Negative"
22648 -1893407846000 "phad" "Gd38/MQm9SIQEMFONBYNpA==" "Negative"
22648 -1893407830999.9998 "t3" "Gd38/MQm9SIQEMFONBYNpA==" "Negative"
22648 -1893407816000.0002 "tx9" "Gd38/MQm9SIQEMFONBYNpA==" "Negative"
22648 -1893407786000 "w6" "Gd38/MQm9SIQEMFONBYNpA==" "Negative"
22648 -1893407756000 "fx5" "WHWZS19j4bmY+M2h7RoxZA==" "Negative"
22648 -1893407725000 "m227" "WHWZS19j4bmY+M2h7RoxZA==" "Positive"
22648 -1893407709999.9998 "phad" "WHWZS19j4bmY+M2h7RoxZA==" "Positive"
22648 -1893407650000 "phad" "fmMJSJa0AhHkm2DtmV2Esg==" "Negative"
22648 -1893407541999.9998 "d1" "nTHEsh2/ugDdl3MRZF+XMQ==" "Positive"
22648 -1893407483000 "d2" "nTHEsh2/ugDdl3MRZF+XMQ==" "Positive"
22648 -1893407423000 "d71" "nTHEsh2/ugDdl3MRZF+XMQ==" "Negative"
22648 -1893407391000 "phad" "D+7AqfHkECBND3NGT9qRfQ==" "Negative"
Comment