I'm not a frequent Stata user and got stuck on something that I think ought to be fairly simple. Perhaps someone here could help? I'm using Stata 16.0.
I'd like to calculate associations (using Spearman's rank correlation) between different biomarkers that are measured within 60 days from each other. I have panel data with 10 biomarkers, some measured only once and some up to four times, and some are measured the same date and some not (see data below(I only included two biomarkers to make it simpler)). How can I make this calculation across rows? I assume I need to get biomarker1 to populate the same row as biomarker2 if the id is the same and the biomarker_date is within 60 days, but I don't understand how. Does anyone know?
Many thanks!
Best
Gunnar
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float id double biomarker_date float(biomarker1 biomarker2) 185 21805 . 772.1053 117 21815 . 386.8421 248 21910 . 280 191 20135 . 303.1579 273 20381 . 320.5263 273 20167 . 283.6842 265 20275 . 174.73685 124 20290 . 652.6316 258 20891 . . 258 20891 . 35.789474 258 20891.57986111111 . . 258 21231 . 39.47368 258 20986 . . 258 21231.48611111111 . . 258 21231 . . 258 20986 . . 258 21231 . . 258 20986 6.481458 . 258 20891 . . 250 20954.5625 . . 250 20520 11.93801 . 250 20954 . . 250 20520 . . 250 20954 . . 250 20520 . . 250 20520 . 461.0526 250 20520 . . 250 20520.583333333336 . . 250 20954 . 362.6316 250 20520 . . 250 20954 . . 173 21223 . 111.05264 173 21223 . . 173 21223 . . 173 21223 . . 173 20849 . . 173 20544.479166666664 . . 173 20849 . 168.21053 173 20849 2.76059 . 173 21223 3.469453 . 173 20849 . . 173 20508 . . 173 20544 . . 173 21223.46527777778 . . 173 20557 . 83.1579 173 20849 . . 173 20544 . . 173 20849 . . 173 20508 . . 173 20508 3.8420894 . 173 21223 . . 173 21669 . 137.89473 190 20213 . 673.6842 206 20053 . 361.57895 214 20282 . 412.6316 169 20242 . 331.57895 197 20968 . . 197 21600 . 151.57895 197 20943 . . 197 21600 . . 197 21293 14.454144 . 197 20943 . 194.21053 197 21293 . . 197 20968 14.237902 . 197 21293 . 227.36842 197 20943 . . 197 21293.458333333336 . . 197 21293 . . 197 20943.59027777778 . . 197 21293 . . 197 21600 . . 197 21293 . . 197 20968 . . 158 20107 . 110.52631 225 20178 . 201.57895 261 19935 . 726.3158 133 20787 . . 133 21171.583333333336 . . 133 20787 . 431.57895 133 21171 . 673.6842 133 21076 . . 133 20559 18.342129 . 133 20559 . . 133 21171 . . 133 20787.583333333336 . . 133 20787 . . 133 21171 . . 133 20559 . . 133 21076 . . 133 21076 38.20453 . 133 20256 . 213.1579 123 20555 18.10814 . 123 20790 . . 123 21068 . . 123 20888 22.946787 . 123 20888 . . 123 20790 . . 123 20555 . . 123 20888 . . 123 21068 27.05924 . end format %td biomarker_date
0 Response to Comparing variables across rows
Post a Comment