Hello all,
I am using Stata 14.1 on Windows 7, and have a possibly strange question, which perhaps displays my ignorance or confusion as much as anything. So perhaps an illustration is in order first.
I have a dataset in which subjects (T) that are nested in different treatment groups are tested twice. Hopefully this image illustrates the setup:
Array
Each time the test outcome is pass or fail. But only those that pass the first test are tested the second time. The data that I have are in a single row for each ID and represent the counts of those T that pass or fail the first and second tests (P1, F1, P2, F2 respectively). The following table gives an ide of what I'm talking about:
I want to evaluate the success for each T, per ID, over the different treatment groups. So I think that what I need is a binomial regression. If I'm sadly deluded, and there's an easier way, I'd love to know because I cannot find a regression that takes two dichotomous dependent variables!
So, the approach that I've taken is to create two new variables, V1 and V2, which can then be used to hold the values of P=1 or F=0.
I have managed this far for a do file:
Which gives me this:
And now I'm stuck. I need to iterate through all ID, replacing V1 and V2 with as many 1's as there are P1 and P2, and as many 0's as there are F1 and F2. Please note that there will be missing values, which is why I defined V1 and V2 in that way.
I'm unsure whether it's better to use a foreach or while loop, or something completely different.
I am using Stata 14.1 on Windows 7, and have a possibly strange question, which perhaps displays my ignorance or confusion as much as anything. So perhaps an illustration is in order first.
I have a dataset in which subjects (T) that are nested in different treatment groups are tested twice. Hopefully this image illustrates the setup:
Array
Each time the test outcome is pass or fail. But only those that pass the first test are tested the second time. The data that I have are in a single row for each ID and represent the counts of those T that pass or fail the first and second tests (P1, F1, P2, F2 respectively). The following table gives an ide of what I'm talking about:
Code:
. list +-------------------------------------+ | GROUP ID T P1 F1 P2 F2 | |-------------------------------------| 1. | 0 1 8 6 2 5 1 | 2. | 0 2 6 4 2 4 0 | 3. | 1 3 0 . . . . | 4. | 1 4 10 8 2 5 3 | 5. | 2 6 9 8 1 7 1 | |-------------------------------------| 6. | 2 7 8 0 8 . . | +-------------------------------------+
So, the approach that I've taken is to create two new variables, V1 and V2, which can then be used to hold the values of P=1 or F=0.
I have managed this far for a do file:
Code:
generate byte V1=. generate byte V2=. expand T sort GROUP ID
Code:
. list +-----------------------------------------------+ | GROUP ID T P1 F1 P2 F2 V1 V2 | |-----------------------------------------------| 1. | 0 1 8 6 2 5 1 . . | 2. | 0 1 8 6 2 5 1 . . | 3. | 0 1 8 6 2 5 1 . . | 4. | 0 1 8 6 2 5 1 . . | 5. | 0 1 8 6 2 5 1 . . | |-----------------------------------------------| 6. | 0 1 8 6 2 5 1 . . | 7. | 0 1 8 6 2 5 1 . . | 8. | 0 1 8 6 2 5 1 . . | 9. | 0 2 6 4 2 4 0 . . | 10. | 0 2 6 4 2 4 0 . . | |-----------------------------------------------| 11. | 0 2 6 4 2 4 0 . . | 12. | 0 2 6 4 2 4 0 . . | 13. | 0 2 6 4 2 4 0 . . | 14. | 0 2 6 4 2 4 0 . . | 15. | 1 3 0 . . . . . . | |-----------------------------------------------| 16. | 1 4 10 8 2 5 3 . . | 17. | 1 4 10 8 2 5 3 . . | 18. | 1 4 10 8 2 5 3 . . | 19. | 1 4 10 8 2 5 3 . . | 20. | 1 4 10 8 2 5 3 . . | |-----------------------------------------------| 21. | 1 4 10 8 2 5 3 . . | 22. | 1 4 10 8 2 5 3 . . | 23. | 1 4 10 8 2 5 3 . . | 24. | 1 4 10 8 2 5 3 . . | 25. | 1 4 10 8 2 5 3 . . | |-----------------------------------------------| 26. | 2 6 9 8 1 7 1 . . | 27. | 2 6 9 8 1 7 1 . . | 28. | 2 6 9 8 1 7 1 . . | 29. | 2 6 9 8 1 7 1 . . | 30. | 2 6 9 8 1 7 1 . . | |-----------------------------------------------| 31. | 2 6 9 8 1 7 1 . . | 32. | 2 6 9 8 1 7 1 . . | 33. | 2 6 9 8 1 7 1 . . | 34. | 2 6 9 8 1 7 1 . . | 35. | 2 7 8 0 8 . . . . | |-----------------------------------------------| 36. | 2 7 8 0 8 . . . . | 37. | 2 7 8 0 8 . . . . | 38. | 2 7 8 0 8 . . . . | 39. | 2 7 8 0 8 . . . . | 40. | 2 7 8 0 8 . . . . | |-----------------------------------------------| 41. | 2 7 8 0 8 . . . . | 42. | 2 7 8 0 8 . . . . | +-----------------------------------------------+
I'm unsure whether it's better to use a foreach or while loop, or something completely different.