Announcement

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

  • Conditional time formula help




    Hi,

    I have the following panel data and I need to generate conditional new variables that equal 1 (yes) or 0 (no), based on the Auditor opinion timing.
    I need to generate a variable that equals 1 if Auditor's opinion is 1 for a firm for the first time (some firms have auditor opinion 1 for multiple years, but I need only the ones that happened first time for every firm).
    Firm year Auditor opinion (Yes or No)
    A 2005 0
    A 2006 0
    A 2007 1
    A 2008 0
    A 2009 0
    B 2005 0
    B 2006 1
    B 2007 0
    B 2008 0
    B 2009 1
    B 2010 0
    C 2005 0
    C 2006 1

    Any help would be greatly appreciated!

  • #2
    Hi,

    I found the solution to this, using help files:

    by Firm (year), sort: gen noccur = sum(Auditor opinion) by id: gen byte first = noccur == 1 & noccur[_n - 1] != noccur

    Thank you all
    Last edited by Sylvia Rosenbaum; 04 Jun 2021, 03:21.

    Comment

    Working...
    X