Hi All,
We have data with repeated measures for the same individual. Each row includes an Id (static), admission date (static), glucose value (dynamic), BG date and time (dynamic). We would like to summarize these glucose data at the calendar day level by creating new variables for rolling BG mean and rolling SD. The data is rolling data. Each row considers the index for the next row (rolling summary data [mean and SD] up to and including the index value). Here is an example of the new variable that I am trying to crate.
I would appreciate if you can suggest a code to achieve this. Collapse command could not generate rolling mean and SD
STATA 18
We have data with repeated measures for the same individual. Each row includes an Id (static), admission date (static), glucose value (dynamic), BG date and time (dynamic). We would like to summarize these glucose data at the calendar day level by creating new variables for rolling BG mean and rolling SD. The data is rolling data. Each row considers the index for the next row (rolling summary data [mean and SD] up to and including the index value). Here is an example of the new variable that I am trying to crate.
id | Admission date | Hospital day | Rolling BG mean | Rolling BG SD |
1 | 14dec2015 | 1 | ||
1 | 14dec2015 | 2 | ||
1 | 14dec2015 | 3 | ||
1 | 14dec2015 | 4 |
I would appreciate if you can suggest a code to achieve this. Collapse command could not generate rolling mean and SD
STATA 18
Code:
* Example generated by -dataex-. For more info, type help dataex clear input long id float(admt_d bg_value bg_result_dt) 1 20436 85 1.7656978e+12 1 20436 150 1.7657088e+12 1 20436 90 1.765776e+12 1 20436 93 1.7657785e+12 1 20436 79 1.765817e+12 1 20436 66 1.765836e+12 1 20436 167 1.765839e+12 1 20436 94 1.765867e+12 1 20436 103 1.7658876e+12 1 20436 91 1.7659047e+12 1 20436 103 1.765921e+12 1 20436 102 1.7659353e+12 1 20436 99 1.766008e+12 1 20436 89 1.7660422e+12 1 20436 86 1.7660476e+12 1 20436 73 1.766077e+12 1 20436 77 1.766095e+12 1 20436 70 1.766134e+12 1 20436 70 1.7661367e+12 1 20436 74 1.7661508e+12 2 20439 76 1.7659607e+12 2 20439 102 1.7659817e+12 2 20439 109 1.7660048e+12 2 20439 84 1.7660304e+12 2 20439 87 1.7660356e+12 2 20439 101 1.7660365e+12 2 20439 88 1.766059e+12 2 20439 90 1.766069e+12 2 20439 80 1.766082e+12 2 20439 92 1.7661053e+12 2 20439 90 1.7661316e+12 2 20439 97 1.7661346e+12 2 20439 94 1.7661508e+12 2 20439 121 1.7661648e+12 2 20439 96 1.766179e+12 2 20439 98 1.76622e+12 2 20439 94 1.7662204e+12 2 20439 96 1.7662326e+12 2 20439 89 1.7662508e+12 2 20439 98 1.7662673e+12 2 20439 98 1.766295e+12 2 20439 91 1.766301e+12 2 20439 96 1.76632e+12 3 20592 117 1.779192e+12 3 20592 98 1.779254e+12 3 20592 84 1.7793442e+12 3 20592 95 1.7794323e+12 3 20592 86 1.7795222e+12 4 20425 158 1.764788e+12 4 20425 113 1.7648286e+12 4 20425 110 1.7649252e+12 4 20425 141 1.7650086e+12 4 20425 105 1.7650862e+12 4 20425 100 1.765173e+12 5 20450 201 1.7669354e+12 5 20450 214 1.7669356e+12 5 20450 196 1.7669595e+12 5 20450 212 1.7669867e+12 5 20450 183 1.7669936e+12 5 20450 185 1.7670084e+12 5 20450 281 1.7670293e+12 5 20450 166 1.767044e+12 5 20450 229 1.767081e+12 5 20450 219 1.7670827e+12 5 20450 177 1.7670928e+12 end format %td admt_d format %tc bg_result_dt
Comment