Announcement

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

  • Generate dummy if last observation for an individual in panel occurs before time x

    Hello,

    I have a panel of banks from year 1905 to 1910. Some banks have observations for the whole duration of the panel, some fail before the end of the panel (i.e. last observation in year 1907), some are founded after the beginning of the panel (i.e. first observation in 1906).

    Each bank has a unique Id. My time measure is years.

    I want to create a dummy variable called "disappear" - if a bank disappears before the end of the panel.

    The code I have so far is:

    gen disap = 0
    sort Id_Bank Year
    bys Id_Bank (Year): replace disap = 1 if & Year[_N]<1910

    But I am not sure this does what I want - is this the correct way of creating the dummy?

    A separate question: what if I wanted to *not* include banks that are founded after 1907, even if they fail before 1910? what code should I use in that case?

    Thank you very much for your help.


    Beatrice

  • Beatrice Faleri
    replied
    Oh, sorry, that was a typo - but thanks for pointing that out - and thank you for the code.

    Leave a comment:


  • Nick Cox
    replied

    Code:
    bysort Id_Bank (Year) : gen disap = Year[_N] < 1910
    puts it all in one line. The code you give isn't what you want, as the last line is illegal (the ampersand & is the problem).

    Leave a comment:

Working...
X