Hi all,
I have unbalanced panel data and wish to calculate p50,p25 & p75 summary measures at each time the the panel.
The data thins out with increasing time and the last panels have only one or two subjects still remaining
Using egen & pctile to calculate summary measures at each time t produces quantile values even when only one or two subjects remain in the panel
I have replicated this below
I presume my code is incorrect and would appreciate any corrective input
many thanks in advance
Richard Hiscock
clear
input id t bob
1 0 6
1 1 7
1 2 10
1 3 7
2 0 10
2 1 6
2 2 8
2 3 9
2 4 4
2 5 4
2 6 3
2 7 4
3 0 16
3 1 6
3 2 10
3 3 8
3 4 7
3 5 6
4 0 6
4 1 7
5 0 6
5 1 10
5 2 4
end
xtset id t
xtline bob , overlay xlab(0(1)7)
sort id t
egen p50 =median(bob), by(t)
egen p25 = pctile(bob), by(t) p(25)
list id t bob p50 p25, sepby(id)
I have unbalanced panel data and wish to calculate p50,p25 & p75 summary measures at each time the the panel.
The data thins out with increasing time and the last panels have only one or two subjects still remaining
Using egen & pctile to calculate summary measures at each time t produces quantile values even when only one or two subjects remain in the panel
I have replicated this below
I presume my code is incorrect and would appreciate any corrective input
many thanks in advance
Richard Hiscock
clear
input id t bob
1 0 6
1 1 7
1 2 10
1 3 7
2 0 10
2 1 6
2 2 8
2 3 9
2 4 4
2 5 4
2 6 3
2 7 4
3 0 16
3 1 6
3 2 10
3 3 8
3 4 7
3 5 6
4 0 6
4 1 7
5 0 6
5 1 10
5 2 4
end
xtset id t
xtline bob , overlay xlab(0(1)7)
sort id t
egen p50 =median(bob), by(t)
egen p25 = pctile(bob), by(t) p(25)
list id t bob p50 p25, sepby(id)
Comment