hello guys!

My data consist of unbalanced Panel data with the identifier gvkey_num fyear, fyear consists of the years 2010 till 2014. Further, the location of the company is given My question is if it is possible to take a random sample of 5 companies (gvkey_num) and to have all the fyear (all observations) of that company and not only of a single year. Example: If i wanted to have a random sample size of 2. I would like to have for example a sample of AVX CORP from 2010 to 2014 and Pfeiffer from 2010 to 2014. Another example is a random sample size of 2 which consist of ADC TELECOMMUNICATION year 2010 and ABOT LABORATORIES from fyear 2010 2011 2012 2013 2014.

My second question is it also possible to take a random sample panel data just as mentioned above but then for every loc(country) we take a random sample of 2 companies with their fyears. An example would be ADC TELECOMMUNICATION with fyear 2010 and ABOT LABORATORIES with fyear 2010 2011 2012 2013 2014. (Both from the USA) and 2 random samples from DEU which will result in PFEIFFER 2010 2011 2012 2013 2014 and NOVALED 2010 2011. (Both from DEU). If this isn't possible I would just make subsets of each country and make random samples just as in question 1 and later append them.
My database consists of 43 countries and 28,645 observations. I don't know how many firms there are in my data. I would also like to know how to count this.

ssc install dataex
Example database:
gvkey num fyear conm loc
1013 2010 ADC TELECOMMUNICATIONS INC USA
1072 2010 AVX CORP USA
1072 2011 AVX CORP USA
1072 2012 AVX CORP USA
1072 2013 AVX CORP USA
1072 2014 AVX CORP USA
1078 2010 ABBOTT LABORATORIES USA
1078 2011 ABBOTT LABORATORIES USA
1078 2012 ABBOTT LABORATORIES USA
1078 2013 ABBOTT LABORATORIES USA
1078 2014 ABBOTT LABORATORIES USA
63265 2010 PFEIFFER VACUUM TECHNOLOGY DEU
63265 2011 PFEIFFER VACUUM TECHNOLOGY DEU
63265 2012 PFEIFFER VACUUM TECHNOLOGY DEU
63265 2013 PFEIFFER VACUUM TECHNOLOGY DEU
63265 2014 PFEIFFER VACUUM TECHNOLOGY DEU
3440 2010 NOVALED AG -ADR -REDH DEU
3440 2011 NOVALED AG -ADR -REDH DEU
I would appreciate any help

Thanks!

Alexis da SilvaM