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
Code:
sample
documentation.

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
I tried to combine
Code:
sample
with
Code:
bysort
like
Code:
bysort pid (year): sample 1
but it always drops all observations for me. Thank you very much.