Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Number of unique firms/ industries

    Hi I have a panel data. Gvkey is an identifier for firms and Fyear is an identifier for year. Sic is used to identify industry.

    How can I get the number of unique firms or the number of unique industries in my sample?

    Thank you in advance for your help!

  • #2
    Helen:
    you may want to try something along the following lines:
    Code:
    . use "https://www.stata-press.com/data/r16/nlswork.dta"
    (National Longitudinal Survey.  Young Women 14-26 years of age in 1968)
    
    . egen counter=tag(idcode)
    
    . count if counter==1
      4,711
    
    .
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      https://www.stata-journal.com/sjpdf....iclenum=dm0042 is a detailed discussion of such matters. Among other things, it discusses a distinct command which must be installed before you can use it.

      Code:
      search distinct, sj
      leads to download links, the latest at the time of writing being


      SJ-15-3 dm0042_2 . . . . . . . . . . . . . . . . Software update for distinct
      (help distinct if installed) . . . . . . N. J. Cox and G. M. Longton
      Q3/15 SJ 15(3):899
      improved table format and display of large numbers of
      observations

      Here is distinct in action:


      Code:
      . webuse grunfeld, clear
      
      . distinct company year
      
      --------------------------------
               |     total   distinct
      ---------+----------------------
       company |       200         10
          year |       200         20
      --------------------------------
      
      . distinct
      
      --------------------------------
               |     total   distinct
      ---------+----------------------
       company |       200         10
          year |       200         20
        invest |       200        195
        mvalue |       200        198
        kstock |       200        199
          time |       200         20
      --------------------------------

      Comment


      • #4
        Thank you!! It works perfectly!

        Comment

        Working...
        X