I have a small dataset shown below, which is structured in longitudinal format. The dataset has 4 variables in total, among them,
id---student id
grade-current student grade
state-if a student was retained in current grade (0-no grade retention;1-was retained in grades)
totalbyid---the number of complete data records on the variable "grade" within id
Now, I want to create a binary variable "COMPLETE" with the rule below, indicating if a student has completed record.
1-Like the student with id==1 or id==8 or id==9 or id==10, as long as the state variable didn't have missing values at all within id, whether they were retained in grades or not, they were treated as complete record. (COMPLETE==1)
2-Like the student with id==2 or id=3/4/5/6/7, as long as the state variable has one missing value within id, they were treated as incomplete record. (COMPLETE==0)
How can I use Stata code to realize the function? Thank you.
clear
input str10 id byte (grade state totalbyid)
1 1 0 12
1 2 0 12
1 3 0 12
1 4 0 12
1 5 0 12
1 6 0 12
1 7 0 12
1 8 0 12
1 9 0 12
1 10 0 12
1 11 0 12
1 12 0 12
2 1 0 9
2 2 0 9
2 . . 9
2 4 0 9
2 . . 9
2 6 0 9
2 7 0 9
2 8 0 9
2 . . 9
2 10 0 9
2 11 0 9
2 12 0 9
3 1 0 11
3 2 0 11
3 3 0 11
3 4 0 11
3 5 0 11
3 6 0 11
3 7 0 11
3 8 0 11
3 9 0 11
3 10 0 11
3 . . 11
3 11 0 11
4 1 0 6
4 . . 6
4 3 0 6
4 4 0 6
4 5 0 6
4 6 0 6
4 . . 6
4 . . 6
4 . . 6
4 . . 6
4 . . 6
4 12 0 6
5 1 0 3
5 2 0 3
5 . . 3
5 . . 3
5 . . 3
5 . . 3
5 . . 3
5 . . 3
5 . . 3
5 . . 3
5 . . 3
5 9 0 3
6 1 0 2
6 1 1 2
7 1 0 6
7 . . 6
7 . . 6
7 . . 6
7 . . 6
7 4 0 6
7 5 0 6
7 6 0 6
7 7 0 6
7 7 1 6
8 1 0 1
9 1 0 2
9 2 0 2
10 1 0 2
10 1 1 2
end
id---student id
grade-current student grade
state-if a student was retained in current grade (0-no grade retention;1-was retained in grades)
totalbyid---the number of complete data records on the variable "grade" within id
Now, I want to create a binary variable "COMPLETE" with the rule below, indicating if a student has completed record.
1-Like the student with id==1 or id==8 or id==9 or id==10, as long as the state variable didn't have missing values at all within id, whether they were retained in grades or not, they were treated as complete record. (COMPLETE==1)
2-Like the student with id==2 or id=3/4/5/6/7, as long as the state variable has one missing value within id, they were treated as incomplete record. (COMPLETE==0)
How can I use Stata code to realize the function? Thank you.
clear
input str10 id byte (grade state totalbyid)
1 1 0 12
1 2 0 12
1 3 0 12
1 4 0 12
1 5 0 12
1 6 0 12
1 7 0 12
1 8 0 12
1 9 0 12
1 10 0 12
1 11 0 12
1 12 0 12
2 1 0 9
2 2 0 9
2 . . 9
2 4 0 9
2 . . 9
2 6 0 9
2 7 0 9
2 8 0 9
2 . . 9
2 10 0 9
2 11 0 9
2 12 0 9
3 1 0 11
3 2 0 11
3 3 0 11
3 4 0 11
3 5 0 11
3 6 0 11
3 7 0 11
3 8 0 11
3 9 0 11
3 10 0 11
3 . . 11
3 11 0 11
4 1 0 6
4 . . 6
4 3 0 6
4 4 0 6
4 5 0 6
4 6 0 6
4 . . 6
4 . . 6
4 . . 6
4 . . 6
4 . . 6
4 12 0 6
5 1 0 3
5 2 0 3
5 . . 3
5 . . 3
5 . . 3
5 . . 3
5 . . 3
5 . . 3
5 . . 3
5 . . 3
5 . . 3
5 9 0 3
6 1 0 2
6 1 1 2
7 1 0 6
7 . . 6
7 . . 6
7 . . 6
7 . . 6
7 4 0 6
7 5 0 6
7 6 0 6
7 7 0 6
7 7 1 6
8 1 0 1
9 1 0 2
9 2 0 2
10 1 0 2
10 1 1 2
end

Comment