Announcement

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

  • generate variables can count the years of financial distress

    Hello everybody,

    I hope you all are doing well,

    I am working on financial distress as a dummy variable that equals one if the firms face financial distress and zero otherwise. I have unbalanced panel data from 1978-2016.

    So, I want to generate a variable that counts how many years the firms has spent in financial distress.plesae, could anyone help me to do that?

    I tried to use the following commands:

    gen year_in_distress=0
    gen dissyear=year* fdistress
    sort id year
    by id: egen minyear= min(dissyear) if dissyear>1
    by id: replace year_in_distress=year-minyear+1 if dissyear>1
    drop dissyear minyear

    These commands gave me these results:

    id year fdistress year_in_distress
    1006 1978 0 0
    1006 1979 1 1
    1006 1980 1 2
    1006 1981 0 0
    1006 1982 1 4



  • #2
    You didn't get a quick answer. You'll increase your chances of a useful answer by following the FAQ on asking questions - provide Stata code in code delimiters, readable Stata output, and sample data using dataex.

    If distress=1 if in distress and 0 otherwise, if you want the total years in distress bysort id: egen yrsdistress=total(fdistress)
    If you want it just previous years of distress, then you'll want to use generate with sum - it does "the running sum of x, treating missing values as zero"
    so you can probably do bysort id: g yrsdistress1=sum(fdistress).

    Comment


    • #3
      Dear Phil,

      Thank you for your comment. So, if I want to apply the following statement with the above: count how many years if the firms in distress ( distress is a dummy variable equals one ). This is measured only in the case in which firm entres distress at some point in time during the time span of the research period.

      Is the following command correct:
      bysort id: g yrsdistress1=sum(fdistress) if fdisttress==1

      Comment

      Working...
      X