Announcement

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

  • create an indicator variable that is 1 if the other indicator variable has ever been 1 during the sample period

    Hello again statalist

    My data are panel data with firm and year variables, I have an indicator variable, breach_event, it equals 1 if the firm breaches a covenant in a year, and 0 otherwise. I want to create another indicator variable, breach, that equals 1 if the firm has a data breach event during the sample period 2014-2020, and 0 otherwise. e.g. frim A has breach_event==1 in 2017, then all the years (2014-2020) should have breach==1.

    How can I achieve this? Thanks!

    Edit:
    The code I tried is the following, it only gets breach==1 for the year of and the years after the breach event, but not years before that. How it can be revised?
    Code:
    by firm(year), sort: gen breach = min(sum(breach_event == 1), 1)
    Last edited by Alice Yang; 26 Mar 2022, 22:52.

  • #2
    Code:
     
     by firm(year), sort: egen breach = max(breach_event)
    See https://www.stata.com/support/faqs/d...ble-recording/

    Comment


    • #3
      Thanks a lot for the code. And the website is very useful, there is a lot to learn in stata.

      Comment

      Working...
      X