Announcement

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

  • Survival analysis: First year the earlier 1 and Last year the later 1

    I need your help for survival study.

    Background:
    I have corporate panel data set as Corporate codes, year, and various ratios.
    For example, PPE/Asset ratio for 10 years and some companies have the ratio over 1 in multiple years.

    Survival Study:
    First year = if PPE/Asset ratio > 1 in the earlier year
    Last year = if PPE/Asset ratio >1 in the later year

    I have no idea how to do the set up above. Please teach me..
    Last edited by Yasutake Homma; 22 Jan 2019, 06:05.

  • #2
    I'm not entirely sure I understand your question. If the year of the current observation is 2001, does "the earlier year" mean 2000 and "the later year" mean 2001? More generally, are you referring to the preceding year and the next year?

    If so, assuming you have a variable corporation that uniquely identifies the different corporations, and another variable year, and there is at most one observation for any corporation in any year, then:

    Code:
    xtset corporation year
    gen first_year = L1.PPE/L1.asset_ratio
    gen last_year = F1.PPE/F1.asset_ratio
    I would add that the variable names first_year and last_year, at least to me, do not seem to mean what the variables actually represent. It is better programming practice to give variables names that describe what information they contain. So I advise you to choose more informative names for these.

    Also, in the future, when looking for help with code, it is important to show example data. The code I have shown above is based on what I imagine your data set to look like. But there are several data organizations that are compatible with your description. If your data are not the way I imagine them, my code will not work: it will either produce error messages, or, worse, just give you wrong answers with no warning. So show example data, and use the -dataex- command to do so.

    If you are running version 15.1 or a fully updated version 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.



    When asking for help with code, always show example data. When showing example data, always use -dataex-.

    Comment


    • #3
      I really appreciate your answer while I gave you the vague question. I will fully understand your comments above.

      Comment

      Working...
      X