I am stuck on how to create a new file based on a data in another.
The pseudo-algorithm for how I am trying to get this to work would be roughly:
- start a new file or frame
- for each row in the existing data/frame: look for a value 1 in variables pneumo - nausea
- for each value in that row which is 1 then copy the patid, when, arm, and variable name or label to the new dataset /frame (this could happen many times)
- when done, save file/frame
Given the sample data below... the final result should looke like:
patid | when | arm | issue |
2 | scr | 1 | pneumo |
2 | scr | 1 | colitis |
5 | scr | 1 | pneumo |
1 | wk1 | 1 | diarr |
1 | wk1 | 1 | colitis |
6 | wk1 | 2 | nausea |
While this would be a fairly easy task in standard programming language, I am stumped how to do it in stata.
I looked at trying to use frames... or replacing the 1's with the string of value label and then collapsing... but not sure this is the right approach.
Any hints on how to do this would be appreciated.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input long patid str7 when float arm byte(pneumo diarr colitis muco nausea) 1 "scr" 1 0 0 0 0 0 2 "scr" 1 1 0 1 0 0 3 "scr" 1 0 0 0 0 0 4 "scr" 1 0 0 0 0 0 5 "scr" 1 1 0 0 0 0 6 "scr" 1 0 0 0 0 0 1 "wk1" 1 0 1 1 0 0 2 "wk1" 1 0 0 0 0 0 3 "wk1" 1 0 0 0 0 0 4 "wk1" 2 0 0 0 0 0 5 "wk1" 2 0 0 0 0 0 6 "wk1" 2 0 0 0 0 1 end label values pneumo pneumo6_ label values diarr diarr6_ label values colitis colitis6_ label values muco muco6_ label values nausea nausea6_
Comment