Announcement

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

  • number increased or decreased?

    Dear All, I found this question here (in Chinese). The variable x denotes the product.
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input id year str1 x
    1 2011 "a"
    1 2011 "b"
    1 2012 "a"
    1 2012 "d"
    1 2013 "a"
    1 2013 "d"
    1 2013 "c"
    2 2011 "c"
    2 2011 "d"
    2 2012 "c"
    2 2012 "a"
    2 2013 "c"
    2 2013 "b"
    end
    The question is to obtain (1) the number of new added product, and (2) the number of retired product, compared to the situation in the previous year for each firm (id) and each year. Any suggestions are highly appreciated.
    Ho-Chuan (River) Huang
    Stata 19.0, MP(4)

  • #2
    This may help:


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input id year str1 x
    1 2011 "a"
    1 2011 "b"
    1 2012 "a"
    1 2012 "d"
    1 2013 "a"
    1 2013 "d"
    1 2013 "c"
    2 2011 "c"
    2 2011 "d"
    2 2012 "c"
    2 2012 "a"
    2 2013 "c"
    2 2013 "b"
    end
    
    bysort id x (year) : gen first = year[1]
    by id x: gen last = year[_N]
    
    sort id year x 
    
    bysort id year : egen new = total(year == first)
    by id year : egen retiring = total(year == last)
    
    by id : gen retired = retiring[_n-1] if year > year[_n-1]
    by id year : replace retired = retired[1] 
    
    list, sepby(id year)
    
         +---------------------------------------------------------+
         | id   year   x   first   last   new   retiring   retired |
         |---------------------------------------------------------|
      1. |  1   2011   a    2011   2013     2          1         . |
      2. |  1   2011   b    2011   2011     2          1         . |
         |---------------------------------------------------------|
      3. |  1   2012   a    2011   2013     1          0         1 |
      4. |  1   2012   d    2012   2013     1          0         1 |
         |---------------------------------------------------------|
      5. |  1   2013   a    2011   2013     1          3         0 |
      6. |  1   2013   c    2013   2013     1          3         0 |
      7. |  1   2013   d    2012   2013     1          3         0 |
         |---------------------------------------------------------|
      8. |  2   2011   c    2011   2013     2          1         . |
      9. |  2   2011   d    2011   2011     2          1         . |
         |---------------------------------------------------------|
     10. |  2   2012   a    2012   2012     1          1         1 |
     11. |  2   2012   c    2011   2013     1          1         1 |
         |---------------------------------------------------------|
     12. |  2   2013   b    2013   2013     1          2         1 |
     13. |  2   2013   c    2011   2013     1          2         1 |
         +---------------------------------------------------------+

    Comment


    • #3
      Sorry, but I don't read Chinese, so am utterly reliant on translation. I'll just flag that my code flags as new all products in the first year of a panel as retiring in the last year of a panel. If you wanted a stricter definition you'd need stricter code. Also, there is no subtlety about products being withdrawn and then reintroduced.

      Comment


      • #4
        Dear Nick, Thanks a lot. I have transfered your code to the original post.
        Ho-Chuan (River) Huang
        Stata 19.0, MP(4)

        Comment

        Working...
        X