I try to take a random sample from a huge unbalanced panel dataset. For the MWE data, I would like to randomnly choose either 513 or 514. But whatever ID is picked at random it should keep all year-data from that person. I call it a 'random panel sample'. I havn't found anything in the
documentation.
I tried to combine
with
like
but it always drops all observations for me. Thank you very much.
Code:
sample
Code:
clear
input year pid var
2003 513 1500
2004 513 1550
2005 513 1500
2006 513 1600
2003 514 1600
2004 514 1600
2005 514 1700
2006 514 1800
end
Code:
sample
Code:
bysort
Code:
bysort pid (year): sample 1

Comment