Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Characteristics of median observation


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: Characteristics of median observation
Date   Tue, 18 Aug 2009 06:25:58 +0000 (GMT)

--- On Tue, 18/8/09, John Hund wrote:
>  As an example, I have data (sales and ages) on firms by
> year in different industries. I would like to find the
> age of the firm with the median value on sales for each
> year and industry. 

*---------- begin example --------------
clear
input ///
age     sales   ind    year id
   2     1.04   3339    1991 1
   3     1.75   3339    1991 2
   3     3.08   3339    1991 3
  31     .496   3339    1991 4
  42     .546   3339    1991 5
  42      1.5   3339    1991 6
   5        .   3411    1991 7
   8     .584   3411    1991 8
  30     .491   3411    1991 9
  19     .944   3411    1991 10
  20     .692   3411    1991 11
  28     1.81   3411    1991 12
  29     .601   3411    1991 13
  32     .509   3411    1991 14
  42     .938   3411    1991 15
  42     .886   3411    1991 16
end

gen byte miss = missing(age, sales, ind, year)
bysort miss ind year (sales): gen long n =  ///
     _N - 1 if miss == 0
bysort miss ind year (sales): gen medage =  ///
     (age[`= floor(n/2)'] + age[`= ceil(n/2)'])/2 ///
      if miss == 0
drop miss n
list
*--------------- end example ----------------------

Hope this helps,
Maarten

-----------------------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany

http://home.fsw.vu.nl/m.buis/
-----------------------------------------


      

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index