Hi,
I have a string variable of varyimg number of characters, for which each sequential 4 characters contains two pieces of information:
01T121T431L4
In this example, the the first two characters correspond to a subject("01") a grade ("T1"), the second ("21" "T4") and so on. There are 90 levels of subject and 10 levels of grade. I want to create 90 variables subjects, with 10 levels for each possible grade.
The first step I've taken is to separate out the string variable to 10 string variables:
gen subject1 =substr(subjectgrade, 1,4)
gen subject2 =substr(subjectgrade, 5,4)
gen subject3 =substr(subjectgrade, 9,4)
gen subject4 =substr(subjectgrade, 13,4)
gen subject5=substr(subjectgrade, 17,4)
gen subject6 =substr(subjectgrade, 21,4)
gen subject7 =substr(subjectgrade, 25,4)
gen subject8 =substr(subjectgrade, 29,4)
gen subject9 =substr(subjectgrade, 33,4)
gen subject10 =substr(subjectgrade, 37,4)
I'm unsure as to the best next step, but think I need to create 90 variables based on all possible subjects 1-90 and then recode these strings for the level of the variable. e.g the string characters "01T1" are in new variable Subject01 and a value "T1". I've tried using strpos to capture the subject, but without success.
Any advice or recommendations would be most welcome. I hope it's reasonably clear what I'm trying to do, but let me know if not.
Thanks.
I have a string variable of varyimg number of characters, for which each sequential 4 characters contains two pieces of information:
01T121T431L4
In this example, the the first two characters correspond to a subject("01") a grade ("T1"), the second ("21" "T4") and so on. There are 90 levels of subject and 10 levels of grade. I want to create 90 variables subjects, with 10 levels for each possible grade.
The first step I've taken is to separate out the string variable to 10 string variables:
gen subject1 =substr(subjectgrade, 1,4)
gen subject2 =substr(subjectgrade, 5,4)
gen subject3 =substr(subjectgrade, 9,4)
gen subject4 =substr(subjectgrade, 13,4)
gen subject5=substr(subjectgrade, 17,4)
gen subject6 =substr(subjectgrade, 21,4)
gen subject7 =substr(subjectgrade, 25,4)
gen subject8 =substr(subjectgrade, 29,4)
gen subject9 =substr(subjectgrade, 33,4)
gen subject10 =substr(subjectgrade, 37,4)
I'm unsure as to the best next step, but think I need to create 90 variables based on all possible subjects 1-90 and then recode these strings for the level of the variable. e.g the string characters "01T1" are in new variable Subject01 and a value "T1". I've tried using strpos to capture the subject, but without success.
Any advice or recommendations would be most welcome. I hope it's reasonably clear what I'm trying to do, but let me know if not.
Thanks.
Comment