I have simplified an original question I had so that it is much more approachable. I have long data set with the following structure:
- Person ID
- Age
- Current Education Enrollment
This education variable only states what education someone is CURRENTLY obtaining. So if a person was not in school, it is 0 (labeled "Not in School"). However, I would like to replace the 0's with the highest education level that the person has obtained by that year.
So in the example below, I would like to replace the "Not in School" values after age 23 with "Has Bachelor degree". My difficulty is that some persons were not in college <4 years, and for those persons, I would like to replace the "Not in School" with "Obtained some college" instead.
Therefore, this would be similar to a replace command, but I am not sure how to do this in the long format. Also, the exact value that the "0" value is being replaced with depends on the specific times an education state previously appeared.
Can you advise what command can help achieve this in the long-format?
With much gratitude,
S
PS: Just for reference, the following is entire data for just one person with the ID "1234". There are ~11,000 persons in my data:
Code:
ID age CurrentEnrollemntState 1234 1234 1234 1234 1234 1234 0 Not in school 1234 1 Not in school 1234 2 Not in school 1234 3 Not in school 1234 4 Not in school 1234 5 Not in school 1234 6 In a Kthru12 1234 7 In a Kthru12 1234 8 In a Kthru12 1234 9 In a Kthru12 1234 10 In a Kthru12 1234 11 In a Kthru12 1234 12 In a Kthru12 1234 13 In a Kthru12 1234 14 In a Kthru12 1234 15 In a Kthru12 1234 16 In a Kthru12 1234 17 Full-time, enrolled in Bachelor’s degrees 1234 18 Full-time, enrolled in Bachelor’s degrees 1234 19 Full-time, enrolled in Bachelor’s degrees 1234 20 Full-time, enrolled in Bachelor’s degrees 1234 21 Full-time, enrolled in Bachelor’s degrees 1234 22 Full-time, enrolled in Bachelor’s degrees 1234 23 Not in school 1234 24 Not in school 1234 25 Not in school 1234 26 Not in school 1234 27 Not in school 1234 28 Not in school 1234 29 Not in school 1234 30 Not in school 1234 31 Not in school 1234 32 Not in school 1234 33 Not in school 1234 34 Not in school 1234 35 Not in school 1234 36 Not in school 1234 37 Not in school 1234 38 Not in school 1234 39 Not in school 1234 40 Not in school 1234 41 Not in school 1234 42 Not in school 1234 43 Not in school 1234 44 Not in school 1234 45 Not in school 1234 46 Not in school 1234 47 Not in school 1234 48 Not in school 1234 49 Not in school 1234 50 Not in school 1234 51 Not in school 1234 52 Not in school 1234 53 Not in school 1234 54 Not in school 1234 55 Not in school 1234 56 Not in school 1234 57 Not in school 1234 58 Not in school 1234 59 Not in school 1234 60 Not in school 1234 61 Not in school 1234 62 Not in school 1234 63 Not in school 1234 64 Not in school 1234 65 Not in school 1234 66 Not in school 1234 67 Not in school 1234 68 Not in school 1234 69 Not in school 1234 70 Not in school 1234 71 Not in school 1234 72 Not in school 1234 73 Not in school 1234 74 Not in school 1234 75 Not in school 1234 76 Not in school 1234 77 Not in school 1234 78 Not in school 1234 79 Not in school 1234 80 Not in school 1234 1234
0 Response to Conditionally Replacing Values in Long-Data Format Dataset?
Post a Comment