Hi all,
I have a dataset with 12 observations per individual. Each individual however answers only eight of 12 randomly assigned questions, and therefore I need to delete four observations for each individual which are not relevant. My first variable of interest, jobsec, records missing values straightforwardly. However, the next variable, q_order, records the eight values one after the other in the first eight rows for each individual. What I need to do is to adjust the q_order variable values to follow the same pattern as the jobsec variable; i.e., for each individual id, to make q_order equal to missing whenever jobsec is missing, and then push back other recorded values of q_order accordingly to match the jobsec values.
Below is a sample of my data. For individual id 1, I want to make q_order=missing for the 3rd and 4th observations, and push back QID545 to the 5th observation, and QID 530 to the 7th observation, QID400 to the 8th observation, and so on. I would greatly appreciate any code that can do this for all observations.
Thank you very much.
I have a dataset with 12 observations per individual. Each individual however answers only eight of 12 randomly assigned questions, and therefore I need to delete four observations for each individual which are not relevant. My first variable of interest, jobsec, records missing values straightforwardly. However, the next variable, q_order, records the eight values one after the other in the first eight rows for each individual. What I need to do is to adjust the q_order variable values to follow the same pattern as the jobsec variable; i.e., for each individual id, to make q_order equal to missing whenever jobsec is missing, and then push back other recorded values of q_order accordingly to match the jobsec values.
Below is a sample of my data. For individual id 1, I want to make q_order=missing for the 3rd and 4th observations, and push back QID545 to the 5th observation, and QID 530 to the 7th observation, QID400 to the 8th observation, and so on. I would greatly appreciate any code that can do this for all observations.
Thank you very much.
individual id | jobsec | q_order |
1 | 7 | QID500 |
1 | 8 | QID300 |
1 | . | QID545 |
1 | . | QID530 |
1 | 6 | QID400 |
1 | . | QID350 |
1 | 5 | QID310 |
1 | 9 | QID560 |
1 | 6 | . |
1 | 7 | . |
1 | 8 | . |
1 | . | . |
2 | . | QID530 |
2 | 4 | QID500 |
2 | . | QID310 |
2 | 6 | QID 440 |
2 | 9 | QID350 |
2 | 7 | QID310 |
2 | 7 | QID400 |
2 | 3 | QID545 |
2 | . | . |
2 | . | . |
2 | 5 | . |
2 | 6 | . |
Comment