Hello, folks,
The dataset below is just for illustrative purpose, although I've ever posted my question here,
https://www.statalist.org/forums/for...rades-in-stata it didn't work for me, and my problem is not solved yet.
This is a pressing task and I really want to move forward with my project.
clear
input str10 id byte (state year grade)
001 0 1 0
001 0 2 1
001 0 3 2
001 0 4 3
001 0 5 4
001 0 6 5
001 0 7 6
001 1 8 7
001 0 9 8
001 0 10 9
001 0 11 10
001 0 12 11
001 0 13 12
002 0 1 0
002 0 2 1
002 . 3 .
002 0 4 3
002 1 5 2
002 1 6 3
002 0 7 4
002 0 8 5
002 . 9 .
002 0 10 7
002 0 11 8
002 0 12 9
002 0 13 10
003 0 1 0
003 0 2 1
003 1 3 1
003 . 4 .
003 0 5 3
003 0 6 4
003 . 7 .
003 0 8 6
003 0 9 7
003 1 10 7
003 0 11 8
003 0 12 9
003 0 13 10
004 0 1 0
004 0 2 1
004 0 3 2
004 0 4 3
004 0 5 4
004 0 6 5
004 0 7 6
004 0 8 7
004 0 9 8
004 0 10 9
004 0 11 .
004 1 12 8
004 1 13 9
005 0 1 0
005 0 2 1
005 1 3 1
005 0 4 3
005 0 5 4
005 . 6 .
005 0 7 6
005 . 8 .
005 1 9 6
005 0 10 8
005 0 11 10
005 0 12 11
005 1 13 11
end
The dataset has 5 students in total. The variable "state" indicates if a student was retained or demoted in a specific grade. (Here demoted students are regarded as student who was retained in grades. eg. student with id==004 is a demoted student when he/she demoted from 9th grade to 8th grade; also, he/she was retained in grades because she repeated 9th grade once).
What I want is to create 3 binary variables to indicator if a student was retained in elementary school, middle school, and high school.
The specific rule to create the variables above is listed below for reference,
1) Within each id, as long as state==1 and grade<=5, then all values of the variable "elementary"==1.
2) Within each id, as long as state==1 and grade ranged from 6 to 8, then all values of the variable "middle"==1.
3) Within each id, as long as state==1 and grade ranged from 9 to 12, then all values of the variable "high"==1.
4) Within each id, if state consists of missing values and zero only, then the corresponding stage indicator should be equal to "missing value".
I really appreciate your sustained supports and thank you for your Stata code!
The dataset below is just for illustrative purpose, although I've ever posted my question here,
https://www.statalist.org/forums/for...rades-in-stata it didn't work for me, and my problem is not solved yet.
This is a pressing task and I really want to move forward with my project.
clear
input str10 id byte (state year grade)
001 0 1 0
001 0 2 1
001 0 3 2
001 0 4 3
001 0 5 4
001 0 6 5
001 0 7 6
001 1 8 7
001 0 9 8
001 0 10 9
001 0 11 10
001 0 12 11
001 0 13 12
002 0 1 0
002 0 2 1
002 . 3 .
002 0 4 3
002 1 5 2
002 1 6 3
002 0 7 4
002 0 8 5
002 . 9 .
002 0 10 7
002 0 11 8
002 0 12 9
002 0 13 10
003 0 1 0
003 0 2 1
003 1 3 1
003 . 4 .
003 0 5 3
003 0 6 4
003 . 7 .
003 0 8 6
003 0 9 7
003 1 10 7
003 0 11 8
003 0 12 9
003 0 13 10
004 0 1 0
004 0 2 1
004 0 3 2
004 0 4 3
004 0 5 4
004 0 6 5
004 0 7 6
004 0 8 7
004 0 9 8
004 0 10 9
004 0 11 .
004 1 12 8
004 1 13 9
005 0 1 0
005 0 2 1
005 1 3 1
005 0 4 3
005 0 5 4
005 . 6 .
005 0 7 6
005 . 8 .
005 1 9 6
005 0 10 8
005 0 11 10
005 0 12 11
005 1 13 11
end
The dataset has 5 students in total. The variable "state" indicates if a student was retained or demoted in a specific grade. (Here demoted students are regarded as student who was retained in grades. eg. student with id==004 is a demoted student when he/she demoted from 9th grade to 8th grade; also, he/she was retained in grades because she repeated 9th grade once).
What I want is to create 3 binary variables to indicator if a student was retained in elementary school, middle school, and high school.
The specific rule to create the variables above is listed below for reference,
1) Within each id, as long as state==1 and grade<=5, then all values of the variable "elementary"==1.
2) Within each id, as long as state==1 and grade ranged from 6 to 8, then all values of the variable "middle"==1.
3) Within each id, as long as state==1 and grade ranged from 9 to 12, then all values of the variable "high"==1.
4) Within each id, if state consists of missing values and zero only, then the corresponding stage indicator should be equal to "missing value".
I really appreciate your sustained supports and thank you for your Stata code!

Comment