I have an unbalanced panel with individuals dropping out and re-appearing. The form below gives an example
ID YEAR
1 2011
1 2013
1 2014
2 2013
2 2014
3 2011
3 2012
......
I am trying to create four variables at id level in2011 in2012 in2013 and in2014 that take the value 1 if an individual participated in that year's survey and 0 otherwise. I am using code similar to
bysort id (year): replace in2011=in2011[1] if year !=2011
but it seems (to me) it will take a lot of code to correctly deal with all the patterns correctly
However all the information seems to be generated by the xtdes command
for this sample
. xtdes
id: 1, 2, ..., 3249 n = 3249
year: 2011, 2012, ..., 2014 T = 4
Delta(year) = 1 unit
Span(year) = 4 periods
(pid*year uniquely identifies each observation)
Distribution of T_i: min 5% 25% 50% 75% 95% max
1 1 1 2 4 4 4
Freq. Percent Cum. | Pattern
---------------------------+---------
1242 38.23 38.23 | 1111
810 24.93 63.16 | 1...
582 17.91 81.07 | ..11
175 5.39 86.46 | 11..
158 4.86 91.32 | 111.
98 3.02 94.34 | 1..1
91 2.80 97.14 | 11.1
90 2.77 99.91 | ..1.
2 0.06 99.97 | 1.1.
1 0.03 100.00 | (other patterns)
---------------------------+---------
3249 100.00 | XXXX
1. Is there anyway the xtdes output can be used to generate in2011...in2014 as discussed above.
2. If not is there any more elegant code than I can come up with that might generate the in2011..in2013 variables coping with all the possible patterns
Thanks
Martin
ID YEAR
1 2011
1 2013
1 2014
2 2013
2 2014
3 2011
3 2012
......
I am trying to create four variables at id level in2011 in2012 in2013 and in2014 that take the value 1 if an individual participated in that year's survey and 0 otherwise. I am using code similar to
bysort id (year): replace in2011=in2011[1] if year !=2011
but it seems (to me) it will take a lot of code to correctly deal with all the patterns correctly
However all the information seems to be generated by the xtdes command
for this sample
. xtdes
id: 1, 2, ..., 3249 n = 3249
year: 2011, 2012, ..., 2014 T = 4
Delta(year) = 1 unit
Span(year) = 4 periods
(pid*year uniquely identifies each observation)
Distribution of T_i: min 5% 25% 50% 75% 95% max
1 1 1 2 4 4 4
Freq. Percent Cum. | Pattern
---------------------------+---------
1242 38.23 38.23 | 1111
810 24.93 63.16 | 1...
582 17.91 81.07 | ..11
175 5.39 86.46 | 11..
158 4.86 91.32 | 111.
98 3.02 94.34 | 1..1
91 2.80 97.14 | 11.1
90 2.77 99.91 | ..1.
2 0.06 99.97 | 1.1.
1 0.03 100.00 | (other patterns)
---------------------------+---------
3249 100.00 | XXXX
1. Is there anyway the xtdes output can be used to generate in2011...in2014 as discussed above.
2. If not is there any more elegant code than I can come up with that might generate the in2011..in2013 variables coping with all the possible patterns
Thanks
Martin
Comment