I have a longitudinal dataset shown below, which is about grade retention issues in K-12 education system in the US. (id-student id; grade-student grade; state-if a student was retained in grades)
What I want to do with Stata code is as follows,
1-Fill the missing values on the variable "grade" with the integer. For example, for the student with id==2, the values filled should be 3,5, and 9.
For another instance, for the student with id==5, the values filled should be 3,4,5,6,7,8,9,10, and 11.
2-After the imputation on the grade variable, I want to create a categorical variable called "type", which illustrates the type of the gap that I just filled within each id.
for the student with id==2 or id==4, then type==1(normal gap===because when the missing value on the grade variable is imputed, there is not any sign to indicate the student was retained in grades)
for the student with id==3 or id==5 or id==7, then type==2 (abnormal gap=after the variable "grade" was imputed, it was found that the student was demoted or retained in grades)
input str10 id byte (grade state)
2 1 0
2 2 0
2 . .
2 4 0
2 . .
2 6 0
2 7 0
2 8 0
2 . .
2 10 0
2 11 0
2 12 0
3 1 0
3 2 0
3 3 0
3 4 0
3 5 0
3 6 0
3 7 0
3 8 0
3 9 0
3 10 0
3 . .
3 11 0
4 1 0
4 . .
4 3 0
4 4 0
4 5 0
4 6 0
4 . .
4 . .
4 . .
4 . .
4 . .
4 12 0
5 1 0
5 2 0
5 . .
5 . .
5 . .
5 . .
5 . .
5 . .
5 . .
5 . .
5 . .
5 9 0
7 1 0
7 . .
7 . .
7 . .
7 . .
7 4 0
7 5 0
7 6 0
7 7 0
7 7 1
end
Can anybody help me with Stata code?
Thank you!
What I want to do with Stata code is as follows,
1-Fill the missing values on the variable "grade" with the integer. For example, for the student with id==2, the values filled should be 3,5, and 9.
For another instance, for the student with id==5, the values filled should be 3,4,5,6,7,8,9,10, and 11.
2-After the imputation on the grade variable, I want to create a categorical variable called "type", which illustrates the type of the gap that I just filled within each id.
for the student with id==2 or id==4, then type==1(normal gap===because when the missing value on the grade variable is imputed, there is not any sign to indicate the student was retained in grades)
for the student with id==3 or id==5 or id==7, then type==2 (abnormal gap=after the variable "grade" was imputed, it was found that the student was demoted or retained in grades)
input str10 id byte (grade state)
2 1 0
2 2 0
2 . .
2 4 0
2 . .
2 6 0
2 7 0
2 8 0
2 . .
2 10 0
2 11 0
2 12 0
3 1 0
3 2 0
3 3 0
3 4 0
3 5 0
3 6 0
3 7 0
3 8 0
3 9 0
3 10 0
3 . .
3 11 0
4 1 0
4 . .
4 3 0
4 4 0
4 5 0
4 6 0
4 . .
4 . .
4 . .
4 . .
4 . .
4 12 0
5 1 0
5 2 0
5 . .
5 . .
5 . .
5 . .
5 . .
5 . .
5 . .
5 . .
5 . .
5 9 0
7 1 0
7 . .
7 . .
7 . .
7 . .
7 4 0
7 5 0
7 6 0
7 7 0
7 7 1
end
Can anybody help me with Stata code?
Thank you!

Comment