Hi,
I have repeated measures data on sleep times in long format. I need to generate a baseline mean of the variable tib_2 and tst_2 if they were registered in week 0, and have that mean be on a single row, followed by the remaining observations.
My data look like this:
So far I have done it by generating new variables, computing means for the days before day 0, and then generating yet another variable in which the mean repeats for the days in the first week and is then followed by the consecute observations.
However, I need to drop repeating rows and have only one row for week 0, and this is not so straightforward because respondents have af different number of days in the first week - so I can't just drop if days < 0 for example, because for some their baseline observation is on day -2... I hope this makes sense.
Anyway I am going for something like this:
input str10 id float(days week tib_2 tst_2) str7 pt_responded
"QyJPARcsAx" 0 0 468.333 344.166 "Ja"
"QyJPARcsAx" 1 1 550 375 "Ja"
"QyJPARcsAx" 2 1 415 360 "Ja"
"QyJPARcsAx" 3 1 475 385 "Ja"
"QyJPARcsAx" 4 1 645 505 "Ja"
"QyJPARcsAx" 5 1 565 385 "Ja"
"QyJPARcsAx" 6 1 485 430 "Ja"
I am familiar with the collapse command, is it perhaps possible to use that within only week 0?
Thank you in advance!
I have repeated measures data on sleep times in long format. I need to generate a baseline mean of the variable tib_2 and tst_2 if they were registered in week 0, and have that mean be on a single row, followed by the remaining observations.
My data look like this:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str10 id float(days week tib_2 tst_2) str7 pt_responded "QyJPARcsAx" -5 0 540 450 "Ja" "QyJPARcsAx" -4 0 540 300 "Ja" "QyJPARcsAx" -3 0 540 390 "Ja" "QyJPARcsAx" -2 0 375 280 "Ja" "QyJPARcsAx" -1 0 385 255 "Ja" "QyJPARcsAx" 0 0 430 390 "Ja" "QyJPARcsAx" 1 1 550 375 "Ja" "QyJPARcsAx" 2 1 415 360 "Ja" "QyJPARcsAx" 3 1 475 385 "Ja" "QyJPARcsAx" 4 1 645 505 "Ja" "QyJPARcsAx" 6 1 485 430 "Ja" "QyJPARcsAx" 7 1 550 490 "Ja" "QyJPARcsAx" 8 2 550 490 "Ja" "TkcjjAJi72" -7 0 500 300 "Ja" "TkcjjAJi72" -6 0 505 230 "Ja" "TkcjjAJi72" -5 0 520 225 "Ja" "TkcjjAJi72" -4 0 470 350 "Ja" "TkcjjAJi72" -2 0 550 350 "Ja" "TkcjjAJi72" 0 0 525 230 "Ja" "TkcjjAJi72" 1 1 345 305 "Ja" "TkcjjAJi72" 2 1 290 155 "Ja" "TkcjjAJi72" 3 1 310 270 "Ja" "TkcjjAJi72" 4 1 340 210 "Ja" "TkcjjAJi72" 5 1 275 115 "Ja" "TkcjjAJi72" 7 1 300 275 "Ja" end
So far I have done it by generating new variables, computing means for the days before day 0, and then generating yet another variable in which the mean repeats for the days in the first week and is then followed by the consecute observations.
However, I need to drop repeating rows and have only one row for week 0, and this is not so straightforward because respondents have af different number of days in the first week - so I can't just drop if days < 0 for example, because for some their baseline observation is on day -2... I hope this makes sense.
Anyway I am going for something like this:
input str10 id float(days week tib_2 tst_2) str7 pt_responded
"QyJPARcsAx" 0 0 468.333 344.166 "Ja"
"QyJPARcsAx" 1 1 550 375 "Ja"
"QyJPARcsAx" 2 1 415 360 "Ja"
"QyJPARcsAx" 3 1 475 385 "Ja"
"QyJPARcsAx" 4 1 645 505 "Ja"
"QyJPARcsAx" 5 1 565 385 "Ja"
"QyJPARcsAx" 6 1 485 430 "Ja"
I am familiar with the collapse command, is it perhaps possible to use that within only week 0?
Thank you in advance!
Comment