Announcement

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

  • counting the nr of firms

    Hello,

    I am having some difficulties with the count command.. I have in a panel data with 359597 observations in a period 1998-2012. As you can see I have several firms, but I don't have all the values for all the variables. My questions are: how to find the total number of firms? The number of firms are not consecutive..

    How to find how many firms are exporting (not the zero value of exporting )? I can find the total number of exporting ( but some firm export for some years, some other firms they do not export at all, some export all the years)

    thanks a lot in advance...
    +-------------------------------------+
    firm year sales exportr~e
    |-------------------------------------|
    230. 38 2000 8381.7595 0
    231. 38 2001 7432.8313 0
    232. 38 2002 4730.7316 0
    233. 41 2008 1585615.5 989714.24
    234. 41 2009 2635737 0
    |-------------------------------------|
    235. 41 2010 3050670 0
    236. 41 2011 2464262.4 0
    237. 41 2012 1995193.7 0
    238. 42 1999 1557.2218 0
    239. 42 2001 3133903.7 0
    |-------------------------------------|
    240. 42 2003 1760325.9 0
    241. 42 2005 3855691.9 0
    242. 42 2006 3218257.6 0
    243. 42 2007 6165185.1 0
    244. 42 2008 4405523.8 0
    |-------------------------------------|
    245. 42 2009 4634218.5 0
    246. 42 2010 1595580 0
    247. 42 2011 1464526 0
    248. 42 2012 1593594.9 51491.243
    249. 43 1999 881.66236 824.41156
    |-------------------------------------|
    250. 43 2001 733307.2 695797.88
    +-------------------------------------+

  • #2
    "I am having some difficulties with the count command": you don't say what they are.

    The number of firms is

    Code:
     
    egen firmtag = tag(firm) 
    count if firmtag
    The number of firms ever exporting is

    Code:
     
    egen totalexports = total(export), by(firm) 
    count if firmtag & totalexports > 0
    See also http://www.stata-journal.com/sjpdf.h...iclenum=dm0042

    Comment


    • #3
      Thank you very very much.. You were very helpful.. I was stuck.. now I printed the stata journal that you suggested me.. Thanks again

      Comment


      • #4
        Hello... again I am having problems with the counting of the firms.. I used the suggestion of Nick and I generated firmtag=tag(firm) and now when I am counting the number of firms and I get strange results.. I don't understand why,..
        in the first years I have many firms.. then firms decrease dramatically (!!!)
        this is the result with years 2001 and 2002:

        | tag(firm)
        Year | 0 1 | Total
        -----------+----------------------+----------
        2001 | 0 23,585 | 23,585
        2002 | 17,819 8,071 | 25,890
        2003 | 23,847 5,661 | 29,508
        2004 | 26,628 4,071 | 30,699
        2005 | 28,592 3,947 | 32,539
        2006 | 29,850 4,562 | 34,412
        2007 | 30,501 4,162 | 34,663
        2008 | 29,382 4,273 | 33,655
        2009 | 31,228 4,492 | 35,720
        2010 | 31,715 3,671 | 35,386
        2011 | 30,819 2,766 | 33,585
        2012 | 28,772 1,552 | 30,324
        -----------+----------------------+----------
        Total | 309,153 70,813 | 379,966





        this is the result i get after dropping tear 2001 and 2002:
        | tag(firm)
        Year | 0 1 | Total
        -----------+----------------------+----------
        2003 | 0 27,548 | 27,548
        2004 | 19,919 9,463 | 29,382
        2005 | 26,187 5,241 | 31,428
        2006 | 28,542 5,043 | 33,585
        2007 | 29,616 4,509 | 34,125
        2008 | 28,919 4,311 | 33,230
        2009 | 30,667 4,663 | 35,330
        2010 | 31,115 3,754 | 34,869
        2011 | 30,446 2,732 | 33,178
        2012 | 28,404 1,567 | 29,971
        -----------+----------------------+----------
        Total | 253,815 68,831 | 322,646

        why the number of firms change after I drop 2 years? Where is my mistake?

        I really would appreciate your help..

        Thank you

        Comment


        • #5
          Nick's suggestion creates a variable that is 1 for the first instance of a distinct value for firm and 0 otherwise.

          Code:
          egen firmtag = tag(firm)
          If your data is sorted by firm and year, then the observation that is tagged is also the observation with lowest value for year. So for the sample data you showed (which would be easier to work with if you used dataex (from SSC))

          Code:
          clear
          input byte firm int year double(sales export)
          38 2000 8381.7595 0 
          38 2001 7432.8313 0 
          38 2002 4730.7316 0 
          41 2008 1585615.5 989714.24 
          41 2009 2635737 0 
          41 2010 3050670 0 
          41 2011 2464262.4 0 
          41 2012 1995193.7 0 
          42 1999 1557.2218 0 
          42 2001 3133903.7 0 
          42 2003 1760325.9 0 
          42 2005 3855691.9 0 
          42 2006 3218257.6 0 
          42 2007 6165185.1 0 
          42 2008 4405523.8 0 
          42 2009 4634218.5 0 
          42 2010 1595580 0 
          42 2011 1464526 0 
          42 2012 1593594.9 51491.243 
          43 1999 881.66236 824.41156 
          43 2001 733307.2 695797.88 
          end
          egen firmtag = tag(firm) 
          count if firmtag
          
          list in 1/8, sepby(firm) noobs
          this will produce the following listing
          Code:
          . list in 1/8, sepby(firm) noobs
          
            +-----------------------------------------------+
            | firm   year       sales      export   firmtag |
            |-----------------------------------------------|
            |   38   2000   8381.7595           0         1 |
            |   38   2001   7432.8313           0         0 |
            |   38   2002   4730.7316           0         0 |
            |-----------------------------------------------|
            |   41   2008   1585615.5   989714.24         1 |
            |   41   2009     2635737           0         0 |
            |   41   2010     3050670           0         0 |
            |   41   2011   2464262.4           0         0 |
            |   41   2012   1995193.7           0         0 |
            +-----------------------------------------------+
          So you should not be surprised if you tabulate year and firmtag and you see more ones in the first few years.

          Code:
          . tab year firmtag
          
                     |       tag(firm)
                year |         0          1 |     Total
          -----------+----------------------+----------
                1999 |         0          2 |         2 
                2000 |         0          1 |         1 
                2001 |         3          0 |         3 
                2002 |         1          0 |         1 
                2003 |         1          0 |         1 
                2005 |         1          0 |         1 
                2006 |         1          0 |         1 
                2007 |         1          0 |         1 
                2008 |         1          1 |         2 
                2009 |         2          0 |         2 
                2010 |         2          0 |         2 
                2011 |         2          0 |         2 
                2012 |         2          0 |         2 
          -----------+----------------------+----------
               Total |        17          4 |        21

          Comment


          • #6
            Thank you Robert.. I tried and it says for all the variables ( firm year sales export ) that they are already defined..is there any other solution to count the firms in my dataset? Can you please suggest me.. I already dropped year 2002 and 2001 for the reason that the number of firms was much much higher than in the following years?? And now I have the same situation..thank you

            Comment


            • #7
              Hello again,



              with the firmtag option I am having difficulties because the first year I have a big amount of firms. In the other years the number of firms is in the same levels. here you can see

              Year sum(firmtag)

              2003 27548
              2004 9463
              2005 5241
              2006 5043
              2007 4509
              2008 4311
              2009 4663
              2010 3754
              2011 2732
              2012 1567

              ​you see now that I get strange values which alter my results? can you please help me, what should I do? I have already deleted year 2002 and 2001 for the same reason, but the problem persist..

              Thanks​

              Comment


              • #8
                If you have a firm that starts in business in 2001 and is still active today, your data includes observations for all years for that firm, from 2001 to 2015. If you delete the firm's observations in 2001 and 2002 and then count firms using the first observation they appear in the data, then of course this firm will appear to start in 2003.

                Comment


                • #9
                  Originally posted by Nick Cox View Post
                  "I am having some difficulties with the count command": you don't say what they are.

                  The number of firms is

                  Code:
                  egen firmtag = tag(firm)
                  count if firmtag
                  The number of firms ever exporting is

                  Code:
                  egen totalexports = total(export), by(firm)
                  count if firmtag & totalexports > 0
                  See also http://www.stata-journal.com/sjpdf.h...iclenum=dm0042
                  Thank you Nick Cox for making things easy.
                  Last edited by Ume Salma Akbar; 11 Oct 2020, 07:05.

                  Comment

                  Working...
                  X