Hello all:
1) I'm working with clinical data that is currently in long format and I wanted to reshape to wide. The data was collected using multiple forms and also has repeat instances for daily visits. I wanted to reshape from long to wide and than label the repeat instances for daily visit 1,2,3,etc. Please see an example of the data below.
2) I tried to reshape using the code below and got the output below. I could work with that and clean it up but wanted to know if there was a more efficient strategy.
drop form repeat_instance
sort sid
by sid: gen num = _n
reshape wide age-status, i(sid) j(num)
3) Ideally, I want an output like that below. Again, I wanted the temp variable (which is repeated daily while the patient is hospitalized) to be labeled 1,2,3, etc to indicate days of hospital say
Thanks for any insights.
DM
1) I'm working with clinical data that is currently in long format and I wanted to reshape to wide. The data was collected using multiple forms and also has repeat instances for daily visits. I wanted to reshape from long to wide and than label the repeat instances for daily visit 1,2,3,etc. Please see an example of the data below.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str5 sid str13 form byte(repeat_instance age) str6 sex double temp str5 status "bn_01" "clinical_data" . 23 "male" . "" "bn_01" "daily_visit" 1 . "" 38 "" "bn_01" "daily_visit" 2 . "" 37 "" "bn_01" "30_day_status" . . "" . "alive" "bn_02" "clinical_data" . 67 "female" . "" "bn_02" "daily_visit" 1 . "" 36.2 "" "bn_02" "daily_visit" 2 . "" 36.4 "" "bn_02" "daily_visit" 3 . "" 37 "" "bn_02" "30_day_status" . . "" . "dead" end
drop form repeat_instance
sort sid
by sid: gen num = _n
reshape wide age-status, i(sid) j(num)
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str5 sid byte age1 str6 sex1 double temp1 str5 status1 byte age2 str6 sex2 double temp2 str5 status2 byte age3 str6 sex3 double temp3 str5 status3 byte age4 str6 sex4 double temp4 str5 status4 byte age5 str6 sex5 double temp5 str5 status5 "bn_01" 23 "male" . "" . "" 38 "" . "" 37 "" . "" . "alive" . "" . "" "bn_02" 67 "female" . "" . "" 36.2 "" . "" 36.4 "" . "" 37 "" . "" . "dead" end
3) Ideally, I want an output like that below. Again, I wanted the temp variable (which is repeated daily while the patient is hospitalized) to be labeled 1,2,3, etc to indicate days of hospital say
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str5 sid byte age str6 sex str5 status double(temp1 temp2) byte temp3 "bn_01" 23 "male" "alive" 38 37 . "bn_02" 67 "female" "dead" 36.2 36.4 37 end
DM
Comment