Announcement

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

  • Dealing with Product wise and Year wise firm data

    I am working on a data that consists the following variables - firms, years and the product codes of the goods produced by these firms during their reported years. So, for example, firm A produces goods 1, 2 and 3 in 2004, goods 2 and 4 in 2005 and so on.Now I want to create a variable - that indicates the number of products added by a firm during each reported year. Howevwer, there are instances that a firm introduce a product then drop it and reintroduce it. Here i don't want to consider the ''reintroduction'' of the product. i just want to see the first appearance of a product. can anyone help regarding this ? sample data is attached. thanks a lot
    Attached Files

  • #2
    Code:
    clear all
    cls
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input long co_code str20 products_product_code int year
     3 "21010300000000000000" 2000
     3 "21010300000000000000" 2001
     3 "21010300000000000000" 2002
     3 "21010300000000000000" 2003
     3 "21000000000000000000" 2003
     3 "21000000000000000000" 2004
     3 "21010300000000000000" 2004
     3 "21010300000000000000" 2005
     3 "21000000000000000000" 2005
     3 "21000000000000000000" 2006
     3 "21010300000000000000" 2006
     3 "21010300000000000000" 2007
     3 "21000000000000000000" 2007
     3 "21000000000000000000" 2008
     3 "21010300000000000000" 2008
     3 "21000000000000000000" 2009
     3 "21010300000000000000" 2009
     3 "21000000000000000000" 2010
     3 "21010300000000000000" 2010
     3 "21000000000000000000" 2011
     3 "21010300000000000000" 2011
     3 "21000000000000000000" 2012
     3 "21010300000000000000" 2012
     3 "21010300000000000000" 2013
     3 "21000000000000000000" 2013
     3 "21000000000000000000" 2014
     3 "21010300000000000000" 2014
     3 "21010300000000000000" 2015
     3 "21000000000000000000" 2015
    11 "03000000000000000000" 1997
    11 "12000000000000000000" 1997
    11 "21010112000000000000" 1997
    11 "12000000000000000000" 1998
    11 "03000000000000000000" 1998
    11 "21010112000000000000" 1998
    11 "21010112000000000000" 1999
    11 "03000000000000000000" 1999
    11 "03000000000000000000" 2000
    11 "12000000000000000000" 2000
    11 "03010701000000000000" 2000
    11 "12000000000000000000" 2001
    11 "03000000000000000000" 2001
    11 "03010701000000000000" 2001
    11 "12000000000000000000" 2002
    11 "03000000000000000000" 2002
    11 "03010701000000000000" 2002
    11 "12000000000000000000" 2003
    11 "03000000000000000000" 2003
    11 "10060000000000000000" 2003
    11 "03010701000000000000" 2003
    11 "10060000000000000000" 2004
    11 "12000000000000000000" 2004
    11 "03010701000000000000" 2004
    11 "03000000000000000000" 2004
    11 "03010701000000000000" 2005
    11 "99999999999999999999" 2005
    11 "03000000000000000000" 2005
    11 "10139900000000000000" 2005
    11 "99999999999999999999" 2006
    11 "03000000000000000000" 2006
    11 "10139900000000000000" 2006
    11 "03010701000000000000" 2006
    11 "03010701000000000000" 2007
    11 "99999999999999999999" 2007
    11 "03000000000000000000" 2007
    11 "10139900000000000000" 2007
    11 "03000000000000000000" 2008
    11 "10139900000000000000" 2008
    11 "03010701000000000000" 2008
    11 "99999999999999999999" 2008
    11 "99999999999999999999" 2009
    11 "03000000000000000000" 2009
    11 "10139900000000000000" 2009
    11 "03010701000000000000" 2009
    11 "03010701000000000000" 2010
    11 "99999999999999999999" 2010
    11 "10139900000000000000" 2010
    11 "03000000000000000000" 2010
    11 "99999999999999999999" 2011
    11 "03010701000000000000" 2011
    11 "03000000000000000000" 2011
    11 "10139900000000000000" 2011
    11 "99999999999999999999" 2012
    11 "03000000000000000000" 2012
    11 "10139900000000000000" 2012
    11 "03010701000000000000" 2012
    11 "99999999999999999999" 2013
    11 "03010701000000000000" 2013
    11 "03000000000000000000" 2013
    11 "03000000000000000000" 2014
    11 "99999999999999999999" 2014
    11 "03010701000000000000" 2014
    11 "03010701000000000000" 2015
    11 "99999999999999999999" 2015
    11 "03000000000000000000" 2015
    11 "03010701000000000000" 2016
    11 "99999999999999999999" 2016
    11 "21000000000000000000" 2016
    11 "03000000000000000000" 2016
    end
    bysort co_code products_product_code (year): generate added = 1 if _n==1
    bysort co_code year (products_product_code): egen newprodyear = total(added)
    // just list the years where products were added
    list if newprodyear>0, noobs sepby(co_code year)
    Code:
    . // just list the years where products were added
    . list if newprodyear>0, noobs sepby(co_code year)
    
      +----------------------------------------------------------+
      | co_code   products_product_c~e   year   added   newpro~r |
      |----------------------------------------------------------|
      |       3   21010300000000000000   2000       1          1 |
      |----------------------------------------------------------|
      |       3   21000000000000000000   2003       1          1 |
      |       3   21010300000000000000   2003       .          1 |
      |----------------------------------------------------------|
      |      11   03000000000000000000   1997       1          3 |
      |      11   12000000000000000000   1997       1          3 |
      |      11   21010112000000000000   1997       1          3 |
      |----------------------------------------------------------|
      |      11   03000000000000000000   2000       .          1 |
      |      11   03010701000000000000   2000       1          1 |
      |      11   12000000000000000000   2000       .          1 |
      |----------------------------------------------------------|
      |      11   03000000000000000000   2003       .          1 |
      |      11   03010701000000000000   2003       .          1 |
      |      11   10060000000000000000   2003       1          1 |
      |      11   12000000000000000000   2003       .          1 |
      |----------------------------------------------------------|
      |      11   03000000000000000000   2005       .          2 |
      |      11   03010701000000000000   2005       .          2 |
      |      11   10139900000000000000   2005       1          2 |
      |      11   99999999999999999999   2005       1          2 |
      |----------------------------------------------------------|
      |      11   03000000000000000000   2016       .          1 |
      |      11   03010701000000000000   2016       .          1 |
      |      11   21000000000000000000   2016       1          1 |
      |      11   99999999999999999999   2016       .          1 |
      +----------------------------------------------------------+

    Comment


    • #3
      Thank you so much William

      Comment


      • #4
        I have one more question. How can we identify the products that has appeared in the data set for the first time. Here firms are not taken into consideration. Once a product is introduced and then got dropped and reappear, i dont want to consider it. more specifically i want to consider only the first event of the appearance of that product. Thank you vey much

        Comment


        • #5
          George:
          do you mean something along the following lines?
          Code:
           bysort products_product_code (year): g wanted=1 if _n==1
          Kind regards,
          Carlo
          (Stata 18.0 SE)

          Comment


          • #6
            yes. it works for me. thanks Carlo

            Comment

            Working...
            X