I am new to STATA and I am struggling to reorganise a large dataset using loops.
Each id represents a student that undergoes an exam each year throughout training. In this cohort students are at different stages of training and started at different dates.
This is a sample of the larger dataset
id | examyr1 | grade1 | spec1 | examyr2 | grade2 | spec2 | examyr3 | grade3 | spec3 |
1 | 2010 | ct | a | 2011 | ct | a | 2013 | st3 | b |
2 | 2011 | st5 | c | 2012 | st6 | c | . | . | . |
3 | 2017 | st4 | d | ||||||
4 | 2011 | ct | a | 2012 | st3 | d | 2013 | st4 | d |
5 | 2015 | st3 | b | 2016 | st4 | b | 2017 | st5 | b |
6 | 2013 | ct | a | 2014 | st3 | b | 2015 | st4 | b |
7 | 2014 | st8 | d | . | . | . | . | . | . |
8 | 2010 | ct | a | 2011 | ct | a | 2012 | st3 | c |
9 | 2015 | st6 | b | 2016 | st7 | b | 2015 | st8 | b |
I want to reorganise it so I can see the grade of the student per year. So that I can identify who I have a complete cohort for. Something like:
id | 2010 | 2011 | 2012 | 2013 | 2014 | 2015 | 2016 | 2017 |
1 | ct | ct | . | st3 | ||||
2 | st5 | st6 | ||||||
3 | st4 |
I'd be grateful for any advice. I have tried various combinations of 'foreach' but cannot get it to work.
Thanks,
Carla
0 Response to foreach- reorganising multiple variables
Post a Comment