Announcement

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

  • Creating new dummy

    I have a dataset on companies with distinct id, products they sell, the region they sell their products to, and in which year.

    For example:
    id product region year
    2 87150000 1 2011
    9 65069990 2 2011
    9 65059010 2 2011
    24 94055000 3 2009
    24 94015000 3 2010
    27 84514000 4 2009
    27 95038000 2 2009
    27 84211910 5 2010
    33 63029900 2 2010
    44 39235000 1 2011
    44 42021210 6 2010
    44 42023200 1 2009
    44 95034100 1 2009
    44 63053200 1 2009
    44 39249000 1 2011
    44 83017000 1 2010
    44 61099090 8 2010
    ..........


    I want to create a dummy variable that equals to 1 when a company introduces a new product to a region in a year i.e.: when an -id- sells a new -product- to a -region- in year -t- but did not sell that -product- to that-region- in any of the previous years. This is my dependent variable for my regression later on.

    I have tried:

    Code:
    // Create first occurrence:
    egen id_prod_region = group(id product region)
    egen int introduce =min(year), by(id_prod_region)
    
    // Dummies:
    gen byte new = (year==intro)
    I'm having trouble with this. Is this the correct way to go around it? Could anyone help? Thanks.





  • #2
    HaiPhong:
    welcome to this forum.
    Your code looks fine, although you seemingly have only new introduction in your data excerpt.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment

    Working...
    X