Hi there, I am STRUGGLING to write some script to help process my dataset for an analysis. Here's the story:
- This dataset contains rehabilitation outcomes, some of which are goals e.g. "brush my teeth independently".
- Instead of that whole string, the goals are stored as letters e.g. "A", "B", "C", in string variables: copm_goal1_category copm_goal2_category copm_goal3_category etc. (there are 8 in my full dataset).
- The dataset is structured in long format, with each participant id having two timepoints (timepoint_label==0 and timepoint_label==1).
- Within each timepoint, there is a relationship between the variables that have the same prefix (e.g. copm_goal1 vs. copm_goal2 vs. copm_goal3). So copm_goal1_category stores the goal, and copm_goal1_p stores a rating about that same goal.
- Between the timepoints, there is a relationship between the goal letters. Goals that have the same letter between timepoints are the same. They may not be stored in the same variable, however.
- For example, for id==73952, in timepoint_label==0, goal "B" is in the variable copm_goal2_category and this goal is the same as goal "B" in timepoint_label==1 which unfortunately happens to be stored in a different variable copm_goal1_category.
- For my anaysis of the goal ratings, I need to ensure that only goals represented within BOTH timepoints are included.
- For example, for participant id==73952, I need to ensure only ratings corresponding to goal letters "B", and "C" are included.
- To do this for my planned analysis, I need to keep the rating values in the variables corresponding to goal "B" i.e. copm_goal2_p for timepoint_label==0;copm_goal1_p for timepoint_label==1 and goal "C" copm_goal3_p for timepoint_label==0;copm_goal2_p for timepoint_label==1; ANDreplace the rating values in the variables corresponding to the other goals that do not appear in both timepoints ("A" copm_goal1_p for timepoint_label==0, and "E" copm_goal3_p for timepoint_label==1) with missing data.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input long id str1 copm_goal1_category byte copm_goal1_p str1 copm_goal2_category byte copm_goal2_p str1 copm_goal3_category byte copm_goal3_p float timepoint_label 73951 "A" 1 "B" 5 "C" 2 0 73951 "A" 4 "B" 10 "C" 9 1 73952 "A" 6 "B" 3 "C" 1 0 73952 "B" 7 "C" 10 "E" 6 1 73954 "A" 2 "B" 5 "C" 4 0 73954 "A" 5 "B" 10 "C" 9 1 73955 "A" 6 "C" 3 "D" 4 0 73955 "A" 7 "C" 9 "D" 8 1 73956 "A" 4 "B" 2 "C" 3 0 73956 "A" 8 "B" 3 "C" 3 1 73957 "A" 5 "B" 2 "D" 3 0 73957 "C" 10 "B" 7 "D" 10 1 73958 "A" 1 "B" 3 "C" 1 0 73958 "A" 8 "B" 7 "C" 10 1 739510 "A" 2 "B" 4 "C" 4 0 739510 "F" 2 "B" 7 "C" 9 1 739512 "J" 5 "I" 4 "H" 5 0 739512 "J" 7 "I" 10 "H" 7 1 739513 "A" 2 "B" 1 "C" 1 0 739513 "A" 8 "B" 8 "C" 7 1 739514 "A" 1 "B" 1 "C" 3 0 739514 "A" 6 "B" 9 "C" 8 1 739515 "A" 1 "B" 1 "C" 1 0 739515 "A" 10 "B" 3 "C" 7 1 739516 "A" 5 "B" 5 "C" 3 0 739516 "A" 8 "B" 10 "C" 10 1 739517 "A" 6 "B" 4 "C" 1 0 739517 "A" 10 "B" 8 "C" 10 1 739519 "G" 2 "H" 1 "I" 1 0 739519 "G" 8 "H" 9 "I" 7 1 end label values copm_goal1_p copm_performance1_ label def copm_performance1_ 1 "1", modify label def copm_performance1_ 2 "2", modify label def copm_performance1_ 4 "4", modify label def copm_performance1_ 5 "5", modify label def copm_performance1_ 6 "6", modify label def copm_performance1_ 7 "7", modify label def copm_performance1_ 8 "8", modify label def copm_performance1_ 10 "10", modify label values copm_goal2_p copm_performance2_ label def copm_performance2_ 1 "1", modify label def copm_performance2_ 2 "2", modify label def copm_performance2_ 3 "3", modify label def copm_performance2_ 4 "4", modify label def copm_performance2_ 5 "5", modify label def copm_performance2_ 7 "7", modify label def copm_performance2_ 8 "8", modify label def copm_performance2_ 9 "9", modify label def copm_performance2_ 10 "10", modify label values copm_goal3_p copm_performance3_ label def copm_performance3_ 1 "1", modify label def copm_performance3_ 2 "2", modify label def copm_performance3_ 3 "3", modify label def copm_performance3_ 4 "4", modify label def copm_performance3_ 5 "5", modify label def copm_performance3_ 6 "6", modify label def copm_performance3_ 7 "7", modify label def copm_performance3_ 8 "8", modify label def copm_performance3_ 9 "9", modify label def copm_performance3_ 10 "10", modify
Comment