Quantcast
Channel: Statalist
Viewing all articles
Browse latest Browse all 72762

Calculating average of specific number of observations across industry and years

$
0
0
Dear statalists,
I’m using Stata 13.1 on Windows 7 and I’ve data from 2009-2012. I’ve calculated the market share of each company (i.e., comp_share). I would like to generate two variables, avrg1 and avrg2. Where avrge1 is the average market share of the largest four firms in the industry (i.e., sic) in a particular year (i.e., fyear) and avrg2 is the average market share of the next four firms in the same industry. I'm struggling how to write the code that can do the job.
I’ll be grateful for your help

My data is as follows;
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long gvkey double fyear int sic double comp_share
 7466 2009 1311   .34693896120538337
 7039 2009 1311   .24536914522636577
 1788 2009 1311   .19964407495505443
 2437 2009 1311    .0563285125987912
 8387 2009 1311   .03221220229948507
 7137 2009 1311   .01837176803150096
 1364 2009 1311  .012677270614497693
10743 2009 1311   .01092949211300734
10636 2009 1311  .009970299139304393
 4358 2009 1311 .0078100297463560165
 2845 2009 1531    .7568013650685039
 7170 2009 1531   .06257041139580258
 4546 2009 1531   .06125845115685833
 6667 2009 1531    .0456344576729991
 2772 2009 1531   .03559255797175098
 6300 2009 1531   .02357305535713519
 2937 2009 1531   .00417207650453138
10951 2009 1531  .004057557334738101
 3406 2009 1531   .00321011547826784
 8276 2009 1531  .002005516961004791
 5737 2009 1531  .001124435098407754
 8551 2010 2300    .2872246350348441
 8551 2010 2300    .2872246350348441
 6990 2010 2300    .2672462447145319
 8219 2010 2300   .20127862301672336
 7018 2010 2300   .11285172319086839
15471 2010 2300   .04255386574835588
 5006 2010 2300   .03263484168495139
 4014 2010 2300  .017462039700241145
 6446 2010 2300  .013040506076967884
 3043 2010 2300  .010500765091312968
 7264 2010 2300  .010225362399760964
 6348 2010 2300  .004981393341441993
 9458 2010 2834   .46818866134587217
 2950 2010 2834   .24732069816521957
 7637 2010 2834   .08380594911560697
 6315 2010 2834   .05364103198663614
 4843 2010 2834   .04687661119016684
 8026 2010 2834   .04219169983570156
 4570 2010 2834  .039971264960437757
 5364 2010 2834  .008538018932128936
 8665 2010 2834  .006204156269119456
 9227 2010 2834 .0018389050437556283
10902 2010 2834 .0014230031553548225
end

Viewing all articles
Browse latest Browse all 72762

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>