I have a long format sample and it is layout as follows,
I want to use assert command to verify if the dataset is setup correctly,
Within id, as long as there is a "1" and no missing value on the "state" variable, then the value of "retain" should be equal to 1 within id.
Within id, if all values of "state" variable are equal to 0 and there is no missing value on this variable, then the value of "retain" should be equal to 0 within id.
Within id, as long as there is a missing value on the state variable, then the value of "retain" should be equal to missing value within id.
Can someone help me to do this with Stata code?
Thank you!
clear
input str10 id byte (grade state retain)
1 1 0 0
1 2 0 0
1 3 0 0
2 1 0 1
2 1 1 1
2 2 0 1
3 1 0 .
3 2 0 .
3 . . .
3 4 0 .
4 1 0 1
4 2 0 1
4 2 1 1
end
I want to use assert command to verify if the dataset is setup correctly,
Within id, as long as there is a "1" and no missing value on the "state" variable, then the value of "retain" should be equal to 1 within id.
Within id, if all values of "state" variable are equal to 0 and there is no missing value on this variable, then the value of "retain" should be equal to 0 within id.
Within id, as long as there is a missing value on the state variable, then the value of "retain" should be equal to missing value within id.
Can someone help me to do this with Stata code?
Thank you!
clear
input str10 id byte (grade state retain)
1 1 0 0
1 2 0 0
1 3 0 0
2 1 0 1
2 1 1 1
2 2 0 1
3 1 0 .
3 2 0 .
3 . . .
3 4 0 .
4 1 0 1
4 2 0 1
4 2 1 1
end
Comment