Hi all, I am trying to wrangle some survey data (which I've reproduced below with entirely fabricated made up data that mirrors the structure of my actual data). My goal is to figure out two things.
The first is to create a variable with 3 mutually exclusive levels: (1) in their final survey entry, the respondent is still in the same program as Wave 1; (2) in their final survey entry, the person is in a different program from Wave 1; (3) in their final survey entry, the person is not in any program (indicated by their program entry being missing). My first pass at this used strmatch() but I struggled to figure out how to specify comparing a respondent's first survey entry to their final survey entry.
The second is to flag the wave and date that they last appear in the survey. You'll notice that when someone doesn't take a survey at all, they have no row for that date, and that the final wave is wave 5. There are also some waves (wave 3 in this example data) where there were multiple surveys within that wave. Put simply, I just want to know when their final survey response took place.
Example data:
The first is to create a variable with 3 mutually exclusive levels: (1) in their final survey entry, the respondent is still in the same program as Wave 1; (2) in their final survey entry, the person is in a different program from Wave 1; (3) in their final survey entry, the person is not in any program (indicated by their program entry being missing). My first pass at this used strmatch() but I struggled to figure out how to specify comparing a respondent's first survey entry to their final survey entry.
The second is to flag the wave and date that they last appear in the survey. You'll notice that when someone doesn't take a survey at all, they have no row for that date, and that the final wave is wave 5. There are also some waves (wave 3 in this example data) where there were multiple surveys within that wave. Put simply, I just want to know when their final survey response took place.
Example data:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input int person_id byte survey_wave str9 survey_date str11 program 100 1 "3/3/2010" "Springfield" 100 2 "4/1/2010" "Springfield" 100 3 "6/1/2010" "Springfield" 100 3 "6/5/2010" "Springfield" 100 3 "6/20/2010" "Springfield" 100 4 "7/5/2010" "Springfield" 100 5 "1/1/2011" "Springfield" 101 1 "3/3/2010" "Springfield" 101 3 "6/1/2010" "Springfield" 101 3 "6/4/2010" "" 101 4 "7/5/2010" "Springfield" 101 5 "1/1/2011" "Springfield" 102 1 "3/3/2010" "Joyce" 102 2 "4/1/2010" "Joyce" 102 3 "6/1/2010" "Joyce" 102 3 "6/5/2010" "Joyce" 102 3 "6/20/2010" "Joyce" 103 1 "3/3/2010" "Capitol" 103 2 "4/1/2010" "Capitol" 103 3 "6/1/2010" "Capitol" 103 3 "6/4/2010" "Capitol" 103 4 "7/5/2010" "Green" 103 5 "1/1/2011" "Green" 104 1 "3/3/2010" "Target" 104 2 "4/1/2010" "Breakers" 104 3 "6/1/2010" "Breakers" 104 3 "6/4/2010" "Breakers" 104 3 "6/20/2010" "Breakers" 104 3 "6/25/2010" "Breakers" 104 4 "7/5/2010" "Breakers" 104 5 "1/1/2011" "" 105 1 "3/3/2010" "Capitol" 105 2 "4/1/2010" "Capitol" 105 4 "7/5/2010" "Springfield" 106 1 "3/4/2010" "Mill Park" 106 2 "4/1/2010" "Mill Park" 106 3 "6/1/2010" "" 106 3 "6/4/2010" "" end
Comment