Hi, Folks,
I have a dataset like this,
clear
input str10 id byte state byte year byte gr
001 0 1 0
001 0 2 1
001 0 3 3
001 1 4 2
002 0 1 0
002 0 2 1
002 0 3 2
002 0 4 4
002 1 5 3
002 0 6 6
002 1 7 5
002 1 8 6
003 0 1 0
003 0 2 1
003 0 3 2
003 0 4 3
003 0 5 4
003 . 6 .
003 0 7 7
003 1 8 6
003 0 9 8
003 . 10 .
003 0 11 10
003 0 12 11
004 0 1 0
004 . 2 .
004 0 3 2
end
As the title of the thread suggested, I want to create 3 binary variables to indicate at which stage where the students were retained in grades in K-12 system.
Here gr==grade_year, state==whether a student was retained in grades.
For the student with ID==1, he was demoted and still regarded as a student retained in grades.
The rule is listed below for reference,
1) Within each id, if state==1 and year<=5, then all variables of primaryschool==1, otherwise primary==0
2) Within each id, if state==1 and year ranged from 6 to 8, then all variables of middleschool==1, otherwise middle==0
3) Within each id, if state==1 and year ranged from 9 to 12, then all variables of highschool==1, otherwise high==0
4) Within each id, if state consists of missing values and zero, then the corresponding stage should be "missing value".
Thank you for your kindly code!
I have a dataset like this,
clear
input str10 id byte state byte year byte gr
001 0 1 0
001 0 2 1
001 0 3 3
001 1 4 2
002 0 1 0
002 0 2 1
002 0 3 2
002 0 4 4
002 1 5 3
002 0 6 6
002 1 7 5
002 1 8 6
003 0 1 0
003 0 2 1
003 0 3 2
003 0 4 3
003 0 5 4
003 . 6 .
003 0 7 7
003 1 8 6
003 0 9 8
003 . 10 .
003 0 11 10
003 0 12 11
004 0 1 0
004 . 2 .
004 0 3 2
end
As the title of the thread suggested, I want to create 3 binary variables to indicate at which stage where the students were retained in grades in K-12 system.
Here gr==grade_year, state==whether a student was retained in grades.
For the student with ID==1, he was demoted and still regarded as a student retained in grades.
The rule is listed below for reference,
1) Within each id, if state==1 and year<=5, then all variables of primaryschool==1, otherwise primary==0
2) Within each id, if state==1 and year ranged from 6 to 8, then all variables of middleschool==1, otherwise middle==0
3) Within each id, if state==1 and year ranged from 9 to 12, then all variables of highschool==1, otherwise high==0
4) Within each id, if state consists of missing values and zero, then the corresponding stage should be "missing value".
Thank you for your kindly code!

Comment