Announcement

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

  • stset use with multiple records per person

    Hi,

    I'm relatively new to Stata and am trying to set up some data for a Cox regression. I have about 500 subjects who have data recorded for either right or left, or both eyes, which will obviously form correlated observations. The 'event' is a pressure rise inside the eye and we are looking for that in any eye that had data recorded (i.e. the fellow eye was not used specifically for some form of matching).

    I'm not sure I understand the difference between using stset with the id option, or just including the vce(cluster id) option following stcox to account for the clustering in the analysis (and not using stset id).

    When specifying id in stset, I receive the following warnings, so the next step is to work out what they mean if I should do this.

    Thank you,

    Paul

    HTML Code:
    686  total observations
             12  multiple records at same instant                   PROBABLE ERROR
                 (NdaysRX[_n-1]==NdaysRX)
              2  observations end on or before enter()
             32  observations begin on or after (first) failure

  • #2
    Paul.
    welcome to this forum.
    As you have multiple observations for the same -id-, you may also want to take a look at shared-frailty models in Cox regression with shared frailty of [ST] stcox (see also -help stcox-).
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Hi there, I am aiming to run the Cox model but I have issues setting my data to survival analysis. I have been playing around and tried many different variations but no success so far.

      My data concerns companies with annual observations from 2010 to 2019 where the event (failure) takes place. So it is multiple-record data (multiple observations per company). I have attached my dataset to show how it is structured, where each observation has a start and stop (e.g. 2010-2011), each company's failure is indicated by Event=1 and the company's incorporation date is when it first became at risk (origin) and the exit date indicated failure, which is censored. Survival days captured the total survival time for each company, which is also censored. LastTransaction is when the company went bankrupt, which is also censored.

      I have tried several variations such as:
      stset SurvivalDays, id(CompanyID) failure(Event) origin(IncorpDate)
      stset Stop, id(CompanyID) failure(Event) origin(IncorpDate)
      stset LastTransaction, id(CompanyID) failure(Event) origin(IncorpDate)
      or even:
      stset Stop, id(CompanyID) failure(Event) origin(IncorpDate) enter(Start)

      Any help in setting my data as survival data correctly would be greatly appreciated so I can finally start running my Cox model!

      Thanks
      Click image for larger version

Name:	stata.JPG
Views:	1
Size:	127.7 KB
ID:	1761072

      Comment


      • #4
        Looking at your data, it appears that you really have just one informative observation per firm, namely the one in which failure occurs. All the others provide no relevant information. But it seems to me what you need to do is:

        Code:
        keep if Event == 1
        stset LastTransaction, origin(IncorporationDate) failure(Event)
        Now, it is possible that I am misunderstanding your data, or that in the full data set the patterns I see in the example shown break down. So if this isn't right, I suggest you do the following:
        1. Find a relatively small sample of your data which produces incorrect results with what I have suggested.
        2. Post that sample using the -dataex- command. N.B. The use of -dataex- is crucial for this purpose: I will need to work with your example to troubleshoot, and there is no way to import a screenshot into Stata. -dataex- is the most helpful way to share data here. If you are running version 18, 17, 16 or a fully updated version 15.1 or 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.
        3. On your own setup, run my code and then show both that code and the response that you get from Stata by copy/pasting from your Results window into the Forum, and surround it by code delimiters. (If you do not know about code delimiters, see FAQ #12.)
        4. Unless it would be blatantly obvious even to people totally unfamiliar with what you are doing, explain why that response is not what you need, and explain what you would expect the correct response to be.
        Added: I have relied in my code on the pattern that each firm's data ends with an observation where Event == 1. But that would seem to imply that there are no censored observations in your data, whereas you state that there are, even though none appear in the example. So, I think that a correction to the code above would be this:

        Code:
        by CompanyID (Start), sort: keep if _n == _N
        stset LastTransaction, origin(IncorporationDate) failure(Event)
        Last edited by Clyde Schechter; 08 Aug 2024, 11:19.

        Comment


        • #5
          Hi Clyde Schechter,

          Thank you for your help.
          Sorry, I did not copy in the entire dataset as this is quite wide, but I do have time-varying observations (e.g. macroeconomic variables) that are recorded annually. (I have attached a new screenshot of my dataset). So I should keep all observations rather than 'keep if Event==1', right?

          I tried your recommended command stset LastTransaction, origin(IncorporationDate) failure(Event) id(CompanyID)

          I added id(CompanyID) since I have kept all observations and therefore need to sort by Company. Using this command, I get a probable error and the last observed exit t=346 which is incorrect. It appears that this command only captures the companies that failed in 2010 whereas I aim to capture all companies failing from 2010 to 2019.

          Any help would be appreciated!

          Click image for larger version

Name:	stata2.JPG
Views:	1
Size:	171.4 KB
ID:	1761078
          Click image for larger version

Name:	snip.JPG
Views:	1
Size:	85.1 KB
ID:	1761079


          Comment


          • #6
            OK, now I understand why you actually have multiple observations. One of the difficulties with this data is that it seems that the real origin (date of incorporation) is given as a specific day, but each observation's interval from Start to Stop is given only in years. So you can't use -origin(IncorpDate)- in the same -stset- command with Start and Stop to designate the observation's coverage interval, because they are not in compatible units. So one question you face is: what is the actual period of coverage for each observation. Is it from Jan 1 of Start to Dec 31 of that year, or is it from the anniversary of incorporation in year Start to the day before the anniversary of incorporation in year Stop? The code for these would be different.

            As I indicated in #2, I can't work with a screenshot. Please post example data that illustrates the problem by using the -datex- command for further assistance.

            Also, unless you say otherwise in your next post, I will assume you are using Stata version 18 and write code accordingly. That code will not work in an earlier version, so if you are, be sure to state what version of Stata you use.

            Comment


            • #7
              Hi Clyde,

              Thanks again.

              To confirm, yes I am working with Stata 18. I have also tried a variation where Start = 01/01/2010 and End=31/12/2010 to ensure correct formatting but this has not resolved the issue.
              So the coverage is typically the full year, except for cases where incorporation occurred later on (all the firms in my sample were incorporated in 2010) or exit happened midway through the year. This is what I wanted to specify using IncorpDate. Please note variable DOF = date of failure which is censored so it is either 31/12/2019 for firms that survived beyond 2019 or whatever date of failure between 2010 and 2019.

              I have used the dataex command for the first 5 companies, please see below. Let me know if this is sufficient or if you require further information.



              input int(CompanyID Start Stop) byte Event int(IncorpDate LastTransaction SurvivalDays) double(Unemployment HousePrices InterestRates CPI IndustryGrowth NewEntrants) int DOF float(first_fail_year first_failure) byte(_st _d) int(_origin _t) byte _t0
              1 2010 2011 0 18268 21689 3421 7.9 5.7192611664852535 .5 3.2332563510392744 .315471836137533 .10266550841258229 21689 . 2019 0 . 18268 . .
              1 2011 2012 0 18268 21689 3421 8.1 -1.4534650630884298 .5 4.474272930648769 .756443565631244 .10528130963603338 21689 . 2019 0 . 18268 . .
              1 2012 2013 0 18268 21689 3421 8 .3975810358062328 .5 2.8907922912205444 -.43994317400670013 .10501351908711791 21689 . 2019 0 . 18268 . .
              1 2013 2014 0 18268 21689 3421 7.6 2.5711748571913122 .5 2.497398543184189 1.9901630385281095 .12425995081519264 21689 . 2019 0 . 18268 . .
              1 2014 2015 0 18268 21689 3421 6.2 8.02835840481228 .5 1.5228426395939088 -.21016081871344738 .10725054824561403 21689 . 2019 0 . 18268 . .
              1 2015 2016 0 18268 21689 3421 5.4 5.953962989080778 .5 0 -.5662383285569064 .10737727650919848 21689 . 2019 0 . 18268 . .
              1 2016 2017 0 18268 21689 3421 4.9 6.991080092582217 .3975409836065574 .7000000000000028 2.0930074523750193 .12290755883752011 21689 . 2019 0 . 18268 . .
              1 2017 2018 0 18268 21689 3421 4.4 4.571008995035573 .2910958904109589 2.6812313803376395 3.0640852998962345 .13333627673900086 21689 . 2019 0 . 18268 . .
              1 2018 2019 0 18268 21689 3421 4.2 3.1397474428639596 .6041095890410959 2.4177949709864603 4.295443769127985 .14155782576835207 21689 . 2019 0 . 18268 . .
              1 2019 2020 1 18268 21689 3421 3.9 .988768711078791 .75 1.7941454202077352 2.5757164624600932 .13692625602705127 21689 2019 2019 0 . 18268 . .
              2 2010 2011 0 18438 23523 3476 7.9 5.7192611664852535 .5 3.2332563510392744 -.281311936576941 .08548046800076721 21914 . . 0 . 18438 . .
              2 2011 2012 0 18438 23523 3476 8.1 -1.4534650630884298 .5 4.474272930648769 2.035639545944562 .10362102860041854 21914 . . 0 . 18438 . .
              2 2012 2013 0 18438 23523 3476 8 .3975810358062328 .5 2.8907922912205444 2.741301059001529 .11068078668683812 21914 . . 0 . 18438 . .
              2 2013 2014 0 18438 23523 3476 7.6 2.5711748571913122 .5 2.497398543184189 8.537792936516666 .16266916052370997 21914 . . 0 . 18438 . .
              2 2014 2015 0 18438 23523 3476 6.2 8.02835840481228 .5 1.5228426395939088 7.264080100125156 .1508886107634543 21914 . . 0 . 18438 . .
              2 2015 2016 0 18438 23523 3476 5.4 5.953962989080778 .5 0 4.291705498602056 .13602050326188259 21914 . . 0 . 18438 . .
              2 2016 2017 0 18438 23523 3476 4.9 6.991080092582217 .3975409836065574 .7000000000000028 2.2974501784004815 .12570707510225393 21914 . . 0 . 18438 . .
              2 2017 2018 0 18438 23523 3476 4.4 4.571008995035573 .2910958904109589 2.6812313803376395 -1.368018761400151 .10036480500304004 21914 . . 0 . 18438 . .
              2 2018 2019 0 18438 23523 3476 4.2 3.1397474428639596 .6041095890410959 2.4177949709864603 .26242049548548607 .10096517368678558 21914 . . 0 . 18438 . .
              2 2019 2020 0 18438 23523 3476 3.9 .988768711078791 .75 1.7941454202077352 -.502012572927498 .09633214237257473 21914 . . 0 . 18438 . .
              3 2010 2011 0 18571 19131 560 7.9 5.7192611664852535 .5 3.2332563510392744 . . 19131 . 2012 0 . 18571 . .
              3 2011 2012 0 18571 19131 560 8.1 -1.4534650630884298 .5 4.474272930648769 . . 19131 . 2012 0 . 18571 . .
              3 2012 2013 1 18571 19131 560 8 .3975810358062328 .5 2.8907922912205444 . . 19131 2012 2012 0 . 18571 . .
              4 2010 2011 0 18443 19285 842 7.9 5.7192611664852535 .5 3.2332563510392744 . . 19285 . 2012 0 . 18443 . .
              4 2011 2012 0 18443 19285 842 8.1 -1.4534650630884298 .5 4.474272930648769 . . 19285 . 2012 0 . 18443 . .
              4 2012 2013 1 18443 19285 842 8 .3975810358062328 .5 2.8907922912205444 . . 19285 2012 2012 0 . 18443 . .
              5 2010 2011 0 18353 23553 3561 7.9 5.7192611664852535 .5 3.2332563510392744 . . 21914 . . 0 . 18353 . .
              5 2011 2012 0 18353 23553 3561 8.1 -1.4534650630884298 .5 4.474272930648769 . . 21914 . . 0 . 18353 . .
              5 2012 2013 0 18353 23553 3561 8 .3975810358062328 .5 2.8907922912205444 . . 21914 . . 0 . 18353 . .
              5 2013 2014 0 18353 23553 3561 7.6 2.5711748571913122 .5 2.497398543184189 . . 21914 . . 0 . 18353 . .
              5 2014 2015 0 18353 23553 3561 6.2 8.02835840481228 .5 1.5228426395939088 . . 21914 . . 0 . 18353 . .
              5 2015 2016 0 18353 23553 3561 5.4 5.953962989080778 .5 0 . . 21914 . . 0 . 18353 . .
              5 2016 2017 0 18353 23553 3561 4.9 6.991080092582217 .3975409836065574 .7000000000000028 . . 21914 . . 0 . 18353 . .
              5 2017 2018 0 18353 23553 3561 4.4 4.571008995035573 .2910958904109589 2.6812313803376395 . . 21914 . . 0 . 18353 . .
              5 2018 2019 0 18353 23553 3561 4.2 3.1397474428639596 .6041095890410959 2.4177949709864603 . . 21914 . . 0 . 18353 . .
              5 2019 2020 0 18353 23553 3561 3.9 .988768711078791 .75 1.7941454202077352 . . 21914 . . 0 . 18353 . .
              6 2010 2011 0 18494 19369 875 7.9 5.7192611664852535 .5 3.2332563510392744 . . 19369 . 2013 0 . 18494 . .
              6 2011 2012 0 18494 19369 875 8.1 -1.4534650630884298 .5 4.474272930648769 . . 19369 . 2013 0 . 18494 . .
              6 2012 2013 0 18494 19369 875 8 .3975810358062328 .5 2.8907922912205444 . . 19369 . 2013 0 . 18494 . .
              6 2013 2014 1 18494 19369 875 7.6 2.5711748571913122 .5 2.497398543184189 . . 19369 2013 2013 0 . 18494 . .
              7 2010 2011 0 18378 18928 550 7.9 5.7192611664852535 .5 3.2332563510392744 -2.1382235528942175 .09383732534930139 18928 . 2011 0 . 18378 . .
              7 2011 2012 1 18378 18928 550 8.1 -1.4534650630884298 .5 4.474272930648769 .5677230520791312 .10718611223253936 18928 2011 2011 0 . 18378 . .
              8 2010 2011 0 18581 23436 3333 7.9 5.7192611664852535 .5 3.2332563510392744 -2.1382235528942175 .09383732534930139 21914 . . 0 . 18581 . .
              8 2011 2012 0 18581 23436 3333 8.1 -1.4534650630884298 .5 4.474272930648769 .5677230520791312 .10718611223253936 21914 . . 0 . 18581 . .
              8 2012 2013 0 18581 23436 3333 8 .3975810358062328 .5 2.8907922912205444 -.7787770687835973 .10533587901321409 21914 . . 0 . 18581 . .
              8 2013 2014 0 18581 23436 3333 7.6 2.5711748571913122 .5 2.497398543184189 1.9078140256878982 .12278110212563531 21914 . . 0 . 18581 . .
              8 2014 2015 0 18581 23436 3333 6.2 8.02835840481228 .5 1.5228426395939088 2.5862280895837984 .1238291909432849 21914 . . 0 . 18581 . .
              8 2015 2016 0 18581 23436 3333 5.4 5.953962989080778 .5 0 3.792575132586933 .13661756040070713 21914 . . 0 . 18581 . .
              8 2016 2017 0 18581 23436 3333 4.9 6.991080092582217 .3975409836065574 .7000000000000028 3.939706145852 .13089052141193336 21914 . . 0 . 18581 . .
              8 2017 2018 0 18581 23436 3333 4.4 4.571008995035573 .2910958904109589 2.6812313803376395 3.9239886791649923 .13414763901006532 21914 . . 0 . 18581 . .
              8 2018 2019 0 18581 23436 3333 4.2 3.1397474428639596 .6041095890410959 2.4177949709864603 2.7550509266989422 .11790365670395725 21914 . . 0 . 18581 . .
              8 2019 2020 0 18581 23436 3333 3.9 .988768711078791 .75 1.7941454202077352 2.183664315132731 .11715532357378787 21914 . . 0 . 18581 . .
              9 2010 2011 0 18498 19285 787 7.9 5.7192611664852535 .5 3.2332563510392744 1.2120327102803685 .09345794392523364 19285 . 2012 0 . 18498 . .
              9 2011 2012 0 18498 19285 787 8.1 -1.4534650630884298 .5 4.474272930648769 .6178160919540119 .09410919540229885 19285 . 2012 0 . 18498 . .
              9 2012 2013 1 18498 19285 787 8 .3975810358062328 .5 2.8907922912205444 -.3029885690676224 .09544139925630078 19285 2012 2012 0 . 18498 . .
              10 2010 2011 0 18528 23366 3386 7.9 5.7192611664852535 .5 3.2332563510392744 3.2903225806451673 .17161290322580644 21914 . . 0 . 18528 . .
              10 2011 2012 0 18528 23366 3386 8.1 -1.4534650630884298 .5 4.474272930648769 6.790865384615373 .18870192307692307 21914 . . 0 . 18528 . .
              10 2012 2013 0 18528 23366 3386 8 .3975810358062328 .5 2.8907922912205444 4.620462046204608 .1716171617161716 21914 . . 0 . 18528 . .
              10 2013 2014 0 18528 23366 3386 7.6 2.5711748571913122 .5 2.497398543184189 .8138903960933135 .13130765056972327 21914 . . 0 . 18528 . .
              10 2014 2015 0 18528 23366 3386 6.2 8.02835840481228 .5 1.5228426395939088 .2696871628910458 .12081984897518878 21914 . . 0 . 18528 . .
              10 2015 2016 0 18528 23366 3386 5.4 5.953962989080778 .5 0 -.052938062466907354 .12493382742191636 21914 . . 0 . 18528 . .
              10 2016 2017 0 18528 23366 3386 4.9 6.991080092582217 .3975409836065574 .7000000000000028 1.1173184357541999 .1234128999492128 21914 . . 0 . 18528 . .
              10 2017 2018 0 18528 23366 3386 4.4 4.571008995035573 .2910958904109589 2.6812313803376395 .7932573128408507 .12097174020823004 21914 . . 0 . 18528 . .
              10 2018 2019 0 18528 23366 3386 4.2 3.1397474428639596 .6041095890410959 2.4177949709864603 -.3451676528599563 .11686390532544379 21914 . . 0 . 18528 . .
              10 2019 2020 0 18528 23366 3386 3.9 .988768711078791 .75 1.7941454202077352 .29440628066733154 .11923454367026497 21914 . . 0 . 18528 . .
              end
              format %td IncorpDate
              format %tdnn/dd/CCYY LastTransaction
              format %td SurvivalDays
              format %td DOF
              [/CODE]


              Thanks again


              Comment


              • #8
                I think the following will do it:
                Code:
                gen time = max(IncorpDate, mdy(1, 1, Start)), after(CompanyID)
                by CompanyID (Start), sort: gen expander = cond(_n == _N & time != DOF, 2, 1)
                format time %td
                expand expander
                by CompanyID (Start), sort: replace time = DOF if _n == _N
                by CompanyID (Start): replace Event = 0 if time < DOF
                
                stset time, origin(IncorpDate) id(CompanyID) failure(Event)

                Comment


                • #9
                  Hi Clyde,

                  Thank you so much! The setup is now correct.

                  However, I have tried to run the Cox regression and it is posing an issue with the time-varying covariates.
                  In addition to the macroeconomic variables which are time-varying, I also have 2 constant variables: CurrentDirectors, which is a proxy for size and ranges from 0 to 20, and Group which is a binary dummy where '0' indicates an independent company and '1' is a company owned by a corporation.

                  I used command: stcox CurrentDirectors Group, tvc(Unemployment HousePrices InterestRates CPI) which is taking ages to return values (it is currently on the first iteration after waiting 15 minutes). According to my supervisor, this is a sign of model misspecification but I am not sure what since the setup has been corrected. *Please note when only running stcox CurrentDirectors Group, there is no issue and the hazard ratios are shown.

                  I have attached the dataset including the two abovementioned variables below:


                  input int CompanyID float time int(Start Stop) byte Event int(IncorpDate LastTransaction) byte(CurrentDirectors Group) int SurvivalDays double(Unemployment HousePrices InterestRates CPI) int DOF float expander byte(_st _d) int(_origin _t _t0)
                  1 18268 2010 2011 0 18268 21689 0 0 3421 7.9 5.7192611664852535 .5 3.2332563510392744 21689 1 0 . 18268 . .
                  1 18628 2011 2012 0 18268 21689 0 0 3421 8.1 -1.4534650630884298 .5 4.474272930648769 21689 1 1 0 18268 360 0
                  1 18993 2012 2013 0 18268 21689 0 0 3421 8 .3975810358062328 .5 2.8907922912205444 21689 1 1 0 18268 725 360
                  1 19359 2013 2014 0 18268 21689 0 0 3421 7.6 2.5711748571913122 .5 2.497398543184189 21689 1 1 0 18268 1091 725
                  1 19724 2014 2015 0 18268 21689 0 0 3421 6.2 8.02835840481228 .5 1.5228426395939088 21689 1 1 0 18268 1456 1091
                  1 20089 2015 2016 0 18268 21689 0 0 3421 5.4 5.953962989080778 .5 0 21689 1 1 0 18268 1821 1456
                  1 20454 2016 2017 0 18268 21689 0 0 3421 4.9 6.991080092582217 .3975409836065574 .7000000000000028 21689 1 1 0 18268 2186 1821
                  1 20820 2017 2018 0 18268 21689 0 0 3421 4.4 4.571008995035573 .2910958904109589 2.6812313803376395 21689 1 1 0 18268 2552 2186
                  1 21185 2018 2019 0 18268 21689 0 0 3421 4.2 3.1397474428639596 .6041095890410959 2.4177949709864603 21689 1 1 0 18268 2917 2552
                  1 21550 2019 2020 0 18268 21689 0 0 3421 3.9 .988768711078791 .75 1.7941454202077352 21689 2 1 0 18268 3282 2917
                  1 21689 2019 2020 1 18268 21689 0 0 3421 3.9 .988768711078791 .75 1.7941454202077352 21689 2 1 1 18268 3421 3282
                  2 18438 2010 2011 0 18438 23523 2 1 3476 7.9 5.7192611664852535 .5 3.2332563510392744 21914 1 0 . 18438 . .
                  2 18628 2011 2012 0 18438 23523 2 1 3476 8.1 -1.4534650630884298 .5 4.474272930648769 21914 1 1 0 18438 190 0
                  2 18993 2012 2013 0 18438 23523 2 1 3476 8 .3975810358062328 .5 2.8907922912205444 21914 1 1 0 18438 555 190
                  2 19359 2013 2014 0 18438 23523 2 1 3476 7.6 2.5711748571913122 .5 2.497398543184189 21914 1 1 0 18438 921 555
                  2 19724 2014 2015 0 18438 23523 2 1 3476 6.2 8.02835840481228 .5 1.5228426395939088 21914 1 1 0 18438 1286 921
                  2 20089 2015 2016 0 18438 23523 2 1 3476 5.4 5.953962989080778 .5 0 21914 1 1 0 18438 1651 1286
                  2 20454 2016 2017 0 18438 23523 2 1 3476 4.9 6.991080092582217 .3975409836065574 .7000000000000028 21914 1 1 0 18438 2016 1651
                  2 20820 2017 2018 0 18438 23523 2 1 3476 4.4 4.571008995035573 .2910958904109589 2.6812313803376395 21914 1 1 0 18438 2382 2016
                  2 21185 2018 2019 0 18438 23523 2 1 3476 4.2 3.1397474428639596 .6041095890410959 2.4177949709864603 21914 1 1 0 18438 2747 2382
                  2 21550 2019 2020 0 18438 23523 2 1 3476 3.9 .988768711078791 .75 1.7941454202077352 21914 2 1 0 18438 3112 2747
                  2 21914 2019 2020 0 18438 23523 2 1 3476 3.9 .988768711078791 .75 1.7941454202077352 21914 2 1 0 18438 3476 3112
                  3 18571 2010 2011 0 18571 19131 0 0 560 7.9 5.7192611664852535 .5 3.2332563510392744 19131 1 0 . 18571 . .
                  3 18628 2011 2012 0 18571 19131 0 0 560 8.1 -1.4534650630884298 .5 4.474272930648769 19131 1 1 0 18571 57 0
                  3 18993 2012 2013 0 18571 19131 0 0 560 8 .3975810358062328 .5 2.8907922912205444 19131 2 1 0 18571 422 57
                  3 19131 2012 2013 1 18571 19131 0 0 560 8 .3975810358062328 .5 2.8907922912205444 19131 2 1 1 18571 560 422
                  4 18443 2010 2011 0 18443 19285 0 0 842 7.9 5.7192611664852535 .5 3.2332563510392744 19285 1 0 . 18443 . .
                  4 18628 2011 2012 0 18443 19285 0 0 842 8.1 -1.4534650630884298 .5 4.474272930648769 19285 1 1 0 18443 185 0
                  4 18993 2012 2013 0 18443 19285 0 0 842 8 .3975810358062328 .5 2.8907922912205444 19285 2 1 0 18443 550 185
                  4 19285 2012 2013 1 18443 19285 0 0 842 8 .3975810358062328 .5 2.8907922912205444 19285 2 1 1 18443 842 550
                  5 18353 2010 2011 0 18353 23553 1 1 3561 7.9 5.7192611664852535 .5 3.2332563510392744 21914 1 0 . 18353 . .
                  5 18628 2011 2012 0 18353 23553 1 1 3561 8.1 -1.4534650630884298 .5 4.474272930648769 21914 1 1 0 18353 275 0
                  5 18993 2012 2013 0 18353 23553 1 1 3561 8 .3975810358062328 .5 2.8907922912205444 21914 1 1 0 18353 640 275
                  5 19359 2013 2014 0 18353 23553 1 1 3561 7.6 2.5711748571913122 .5 2.497398543184189 21914 1 1 0 18353 1006 640
                  5 19724 2014 2015 0 18353 23553 1 1 3561 6.2 8.02835840481228 .5 1.5228426395939088 21914 1 1 0 18353 1371 1006
                  5 20089 2015 2016 0 18353 23553 1 1 3561 5.4 5.953962989080778 .5 0 21914 1 1 0 18353 1736 1371
                  5 20454 2016 2017 0 18353 23553 1 1 3561 4.9 6.991080092582217 .3975409836065574 .7000000000000028 21914 1 1 0 18353 2101 1736
                  5 20820 2017 2018 0 18353 23553 1 1 3561 4.4 4.571008995035573 .2910958904109589 2.6812313803376395 21914 1 1 0 18353 2467 2101
                  5 21185 2018 2019 0 18353 23553 1 1 3561 4.2 3.1397474428639596 .6041095890410959 2.4177949709864603 21914 1 1 0 18353 2832 2467
                  5 21550 2019 2020 0 18353 23553 1 1 3561 3.9 .988768711078791 .75 1.7941454202077352 21914 2 1 0 18353 3197 2832
                  5 21914 2019 2020 0 18353 23553 1 1 3561 3.9 .988768711078791 .75 1.7941454202077352 21914 2 1 0 18353 3561 3197
                  6 18494 2010 2011 0 18494 19369 0 0 875 7.9 5.7192611664852535 .5 3.2332563510392744 19369 1 0 . 18494 . .
                  6 18628 2011 2012 0 18494 19369 0 0 875 8.1 -1.4534650630884298 .5 4.474272930648769 19369 1 1 0 18494 134 0
                  6 18993 2012 2013 0 18494 19369 0 0 875 8 .3975810358062328 .5 2.8907922912205444 19369 1 1 0 18494 499 134
                  6 19359 2013 2014 0 18494 19369 0 0 875 7.6 2.5711748571913122 .5 2.497398543184189 19369 2 1 0 18494 865 499
                  6 19369 2013 2014 1 18494 19369 0 0 875 7.6 2.5711748571913122 .5 2.497398543184189 19369 2 1 1 18494 875 865
                  7 18378 2010 2011 0 18378 18928 0 0 550 7.9 5.7192611664852535 .5 3.2332563510392744 18928 1 0 . 18378 . .
                  7 18628 2011 2012 0 18378 18928 0 0 550 8.1 -1.4534650630884298 .5 4.474272930648769 18928 2 1 0 18378 250 0
                  7 18928 2011 2012 1 18378 18928 0 0 550 8.1 -1.4534650630884298 .5 4.474272930648769 18928 2 1 1 18378 550 250
                  8 18581 2010 2011 0 18581 23436 2 1 3333 7.9 5.7192611664852535 .5 3.2332563510392744 21914 1 0 . 18581 . .
                  8 18628 2011 2012 0 18581 23436 2 1 3333 8.1 -1.4534650630884298 .5 4.474272930648769 21914 1 1 0 18581 47 0
                  8 18993 2012 2013 0 18581 23436 2 1 3333 8 .3975810358062328 .5 2.8907922912205444 21914 1 1 0 18581 412 47
                  8 19359 2013 2014 0 18581 23436 2 1 3333 7.6 2.5711748571913122 .5 2.497398543184189 21914 1 1 0 18581 778 412
                  8 19724 2014 2015 0 18581 23436 2 1 3333 6.2 8.02835840481228 .5 1.5228426395939088 21914 1 1 0 18581 1143 778
                  8 20089 2015 2016 0 18581 23436 2 1 3333 5.4 5.953962989080778 .5 0 21914 1 1 0 18581 1508 1143
                  8 20454 2016 2017 0 18581 23436 2 1 3333 4.9 6.991080092582217 .3975409836065574 .7000000000000028 21914 1 1 0 18581 1873 1508
                  8 20820 2017 2018 0 18581 23436 2 1 3333 4.4 4.571008995035573 .2910958904109589 2.6812313803376395 21914 1 1 0 18581 2239 1873
                  8 21185 2018 2019 0 18581 23436 2 1 3333 4.2 3.1397474428639596 .6041095890410959 2.4177949709864603 21914 1 1 0 18581 2604 2239
                  8 21550 2019 2020 0 18581 23436 2 1 3333 3.9 .988768711078791 .75 1.7941454202077352 21914 2 1 0 18581 2969 2604
                  8 21914 2019 2020 0 18581 23436 2 1 3333 3.9 .988768711078791 .75 1.7941454202077352 21914 2 1 0 18581 3333 2969
                  9 18498 2010 2011 0 18498 19285 0 0 787 7.9 5.7192611664852535 .5 3.2332563510392744 19285 1 0 . 18498 . .
                  9 18628 2011 2012 0 18498 19285 0 0 787 8.1 -1.4534650630884298 .5 4.474272930648769 19285 1 1 0 18498 130 0
                  9 18993 2012 2013 0 18498 19285 0 0 787 8 .3975810358062328 .5 2.8907922912205444 19285 2 1 0 18498 495 130
                  9 19285 2012 2013 1 18498 19285 0 0 787 8 .3975810358062328 .5 2.8907922912205444 19285 2 1 1 18498 787 495
                  10 18528 2010 2011 0 18528 23366 1 1 3386 7.9 5.7192611664852535 .5 3.2332563510392744 21914 1 0 . 18528 . .
                  10 18628 2011 2012 0 18528 23366 1 1 3386 8.1 -1.4534650630884298 .5 4.474272930648769 21914 1 1 0 18528 100 0
                  10 18993 2012 2013 0 18528 23366 1 1 3386 8 .3975810358062328 .5 2.8907922912205444 21914 1 1 0 18528 465 100
                  10 19359 2013 2014 0 18528 23366 1 1 3386 7.6 2.5711748571913122 .5 2.497398543184189 21914 1 1 0 18528 831 465
                  10 19724 2014 2015 0 18528 23366 1 1 3386 6.2 8.02835840481228 .5 1.5228426395939088 21914 1 1 0 18528 1196 831
                  10 20089 2015 2016 0 18528 23366 1 1 3386 5.4 5.953962989080778 .5 0 21914 1 1 0 18528 1561 1196
                  10 20454 2016 2017 0 18528 23366 1 1 3386 4.9 6.991080092582217 .3975409836065574 .7000000000000028 21914 1 1 0 18528 1926 1561
                  10 20820 2017 2018 0 18528 23366 1 1 3386 4.4 4.571008995035573 .2910958904109589 2.6812313803376395 21914 1 1 0 18528 2292 1926
                  10 21185 2018 2019 0 18528 23366 1 1 3386 4.2 3.1397474428639596 .6041095890410959 2.4177949709864603 21914 1 1 0 18528 2657 2292
                  10 21550 2019 2020 0 18528 23366 1 1 3386 3.9 .988768711078791 .75 1.7941454202077352 21914 2 1 0 18528 3022 2657
                  10 21914 2019 2020 0 18528 23366 1 1 3386 3.9 .988768711078791 .75 1.7941454202077352 21914 2 1 0 18528 3386 3022
                  end
                  format %td time
                  format %td IncorpDate
                  format %tdnn/dd/CCYY LastTransaction
                  format %td DOF
                  [/CODE]

                  Many thanks in advance

                  Comment


                  • #10
                    Normally when I see somebody complaining that 15 minutes have gone by and an iteration is not complete, I counsel patience. You haven't lived until you had an analysis run for weeks or months to complete. But, in this case, you can kill the computation--your model is mis-specified. And if you let it keep running, it will eventually terminate with an error message telling you that it did not converge.

                    The phrase "time-varying covariate" as used in survival analysis is a seriously unfortunate choice of terminology, because its word-by-word meaning is quite contrary to what it actually means and misleads people into mis-structuring models into forms that are impossible to estimate in any case. And this is what has bitten you. The variables you have told Stata to treat as -tvc- are not "time-varying covariate" in the technical sense that has for survival analysis. They are simply variables that are defined at the time level, and they are not constant over time within CompanyID. That is what the words "time" "varying" "covariate" would suggest a time-varying covariate is in survival analysis. Alas, that is far from the case.

                    What in survival analysis is called a time-varying coordinate is actually a variable whose effect on survival varies over time. Put even more technically, it is a variable whose effect must be modeled by incorporating an interaction term between the variable and (possibly transformed) _t. But it is always a mis-specification to have an interaction between time and a variable that is defined at the time level--such a model is inherently unidentifiable. (This last sentence is not confined to survival analysis but applies to any multi-level regression model, and it refers to any level in such a model, not just time.) And that unidentifiability is usually recognized as very long iteration times leading, ultimately, to failure to converge to a solution.

                    So these variables are not "time varying covariates" as the term is used in survival analysis, and any attempt to use them as such will lead to exactly the kind of computational failure you are getting. Just leave out the -tvc()- from your model and you will have it right.

                    I wish that the use of the phrase "time varying covariate" were abandoned and replaced by "time-interacting covariate" or "time-effect-modifier." But, unfortunately, the term is deeply entrenched in the literature and will continue to entrap the unwary for decades to come.

                    Comment


                    • #11
                      Hi Clyde,

                      Thank you so much for clarifying! I agree that the term 'time-varying covariate' is rather confusing in this context.
                      If I have understood you correctly, you are suggesting I use command stcox CurrentDirectors Group Unemployment HousePrices InterestRates CPI without tvc() and I presume this will still capture the different periods over which the different macroeconomic variables apply since this is set in the stset command?

                      When using this command, the first 29 iterations are run quickly and smoothly, but after this I get error 'flat region resulting in a missing likelihood, r(430)'
                      I have tried adding vce(robust CompanyID) with no success and also limited the iterations to 29 to identify any potential issues, but this returns plausible hazard ratios, therefore I have not identified the issue. I know r430 is quite a generic error. Do you have any suggestions what the cause of this error may be?

                      Thanks

                      Comment


                      • #12
                        If I have understood you correctly, you are suggesting I use command stcox CurrentDirectors Group Unemployment HousePrices InterestRates CPI without tvc() and I presume this will still capture the different periods over which the different macroeconomic variables apply since this is set in the stset command?
                        Correct.

                        With regard to the flat region in the likelihood, that is a troublesome problem with no easy solution. You will have to, by trial and error, discover the variables that underlie the problem. Probably best is to start with a model containing only your single most important predictor variable and see if that will run to completion. Then add in your next most important and see if that runs to completion. Eventually you will hit at least one variable that, when added to the last good model, leads to this failure. Then drop that variable but continue adding one more variable at a time, and, again, anytime adding a new variable breaks the computation, remove that. You will then be left with the maximum subset of your model variables that can be run without this difficulty.

                        Then take a look at those variables. Are there data errors that need to be fixed? Are they scaled in a way that is not similar to other variables in the model--if so you could try rescaling them to be more similar in range to the successful model variables and see if that makes a difference.

                        Comment


                        • #13
                          Thanks so much for your ongoing help Clyde!

                          I have tried as you said and luckily it appears the only variable causing issues is Unemployment. All other variables run fine and do not give this error.
                          However, this is weird as my Unemployment variable is the UK-wide unemployment rate in the UK recorded annually from 2010 to 2019, in the same way that the interest rate is recorded annually (the interest rate is not posing an issue).

                          I have looked at this variable but I am not sure why unemployment would be causing any issues.
                          It is structured as follows:
                          Year Unemployment
                          input int Start double Unemployment
                          2010 7.9
                          2011 8.1
                          2012 8
                          2013 7.6
                          2014 6.2
                          2015 5.4
                          2016 4.9
                          2017 4.4
                          2018 4.2
                          2019 3.9

                          However, whilst analysing this, I have identified another issue in the data, which is that the final observation (2019-2020) is repreated twice in the case of some companies. I retraced my steps and it occurs when running this command (which is part of organising the setup before running stset)
                          by CompanyID (Start), sort: replace time = DOF if _n == _N See the data below: input int CompanyID float time int(Start Stop) byte Event int(IncorpDate LastTransaction) byte(CurrentDirectors Group) int SurvivalDays double(Unemployment HousePrices InterestRates CPI) int DOF byte(_st _d) int(_origin _t) byte _t0 float expander 1 18268 2010 2011 0 18268 21689 0 0 3421 7.9 5.7192611664852535 .5 3.2332563510392744 21689 0 . 18268 . . 1 1 18628 2011 2012 0 18268 21689 0 0 3421 8.1 -1.4534650630884298 .5 4.474272930648769 21689 0 . 18268 . . 1 1 18993 2012 2013 0 18268 21689 0 0 3421 8 .3975810358062328 .5 2.8907922912205444 21689 0 . 18268 . . 1 1 19359 2013 2014 0 18268 21689 0 0 3421 7.6 2.5711748571913122 .5 2.497398543184189 21689 0 . 18268 . . 1 1 19724 2014 2015 0 18268 21689 0 0 3421 6.2 8.02835840481228 .5 1.5228426395939088 21689 0 . 18268 . . 1 1 20089 2015 2016 0 18268 21689 0 0 3421 5.4 5.953962989080778 .5 0 21689 0 . 18268 . . 1 1 20454 2016 2017 0 18268 21689 0 0 3421 4.9 6.991080092582217 .3975409836065574 .7000000000000028 21689 0 . 18268 . . 1 1 20820 2017 2018 0 18268 21689 0 0 3421 4.4 4.571008995035573 .2910958904109589 2.6812313803376395 21689 0 . 18268 . . 1 1 21185 2018 2019 0 18268 21689 0 0 3421 4.2 3.1397474428639596 .6041095890410959 2.4177949709864603 21689 0 . 18268 . . 1 1 21550 2019 2020 1 18268 21689 0 0 3421 3.9 .988768711078791 .75 1.7941454202077352 21689 0 . 18268 . . 2 1 21689 2019 2020 1 18268 21689 0 0 3421 3.9 .988768711078791 .75 1.7941454202077352 21689 0 . 18268 . . 2 2 18438 2010 2011 0 18438 23523 2 1 3476 7.9 5.7192611664852535 .5 3.2332563510392744 21914 0 . 18438 . . 1 2 18628 2011 2012 0 18438 23523 2 1 3476 8.1 -1.4534650630884298 .5 4.474272930648769 21914 0 . 18438 . . 1 2 18993 2012 2013 0 18438 23523 2 1 3476 8 .3975810358062328 .5 2.8907922912205444 21914 0 . 18438 . . 1 2 19359 2013 2014 0 18438 23523 2 1 3476 7.6 2.5711748571913122 .5 2.497398543184189 21914 0 . 18438 . . 1 2 19724 2014 2015 0 18438 23523 2 1 3476 6.2 8.02835840481228 .5 1.5228426395939088 21914 0 . 18438 . . 1 2 20089 2015 2016 0 18438 23523 2 1 3476 5.4 5.953962989080778 .5 0 21914 0 . 18438 . . 1 2 20454 2016 2017 0 18438 23523 2 1 3476 4.9 6.991080092582217 .3975409836065574 .7000000000000028 21914 0 . 18438 . . 1 2 20820 2017 2018 0 18438 23523 2 1 3476 4.4 4.571008995035573 .2910958904109589 2.6812313803376395 21914 0 . 18438 . . 1 2 21185 2018 2019 0 18438 23523 2 1 3476 4.2 3.1397474428639596 .6041095890410959 2.4177949709864603 21914 0 . 18438 . . 1 2 21550 2019 2020 0 18438 23523 2 1 3476 3.9 .988768711078791 .75 1.7941454202077352 21914 0 . 18438 . . 2 2 21914 2019 2020 0 18438 23523 2 1 3476 3.9 .988768711078791 .75 1.7941454202077352 21914 0 . 18438 . . 2 3 18571 2010 2011 0 18571 19131 0 0 560 7.9 5.7192611664852535 .5 3.2332563510392744 19131 0 . 18571 . . 1 3 18628 2011 2012 0 18571 19131 0 0 560 8.1 -1.4534650630884298 .5 4.474272930648769 19131 0 . 18571 . . 1 3 18993 2012 2013 1 18571 19131 0 0 560 8 .3975810358062328 .5 2.8907922912205444 19131 0 . 18571 . . 2 3 19131 2012 2013 1 18571 19131 0 0 560 8 .3975810358062328 .5 2.8907922912205444 19131 0 . 18571 . . 2 4 18443 2010 2011 0 18443 19285 0 0 842 7.9 5.7192611664852535 .5 3.2332563510392744 19285 0 . 18443 . . 1 4 18628 2011 2012 0 18443 19285 0 0 842 8.1 -1.4534650630884298 .5 4.474272930648769 19285 0 . 18443 . . 1 4 18993 2012 2013 1 18443 19285 0 0 842 8 .3975810358062328 .5 2.8907922912205444 19285 0 . 18443 . . 2 4 19285 2012 2013 1 18443 19285 0 0 842 8 .3975810358062328 .5 2.8907922912205444 19285 0 . 18443 . . 2 5 18353 2010 2011 0 18353 23553 1 1 3561 7.9 5.7192611664852535 .5 3.2332563510392744 21914 0 . 18353 . . 1 5 18628 2011 2012 0 18353 23553 1 1 3561 8.1 -1.4534650630884298 .5 4.474272930648769 21914 0 . 18353 . . 1 5 18993 2012 2013 0 18353 23553 1 1 3561 8 .3975810358062328 .5 2.8907922912205444 21914 0 . 18353 . . 1 5 19359 2013 2014 0 18353 23553 1 1 3561 7.6 2.5711748571913122 .5 2.497398543184189 21914 0 . 18353 . . 1 5 19724 2014 2015 0 18353 23553 1 1 3561 6.2 8.02835840481228 .5 1.5228426395939088 21914 0 . 18353 . . 1 5 20089 2015 2016 0 18353 23553 1 1 3561 5.4 5.953962989080778 .5 0 21914 0 . 18353 . . 1 5 20454 2016 2017 0 18353 23553 1 1 3561 4.9 6.991080092582217 .3975409836065574 .7000000000000028 21914 0 . 18353 . . 1 5 20820 2017 2018 0 18353 23553 1 1 3561 4.4 4.571008995035573 .2910958904109589 2.6812313803376395 21914 0 . 18353 . . 1 5 21185 2018 2019 0 18353 23553 1 1 3561 4.2 3.1397474428639596 .6041095890410959 2.4177949709864603 21914 0 . 18353 . . 1 5 21550 2019 2020 0 18353 23553 1 1 3561 3.9 .988768711078791 .75 1.7941454202077352 21914 0 . 18353 . . 2 5 21914 2019 2020 0 18353 23553 1 1 3561 3.9 .988768711078791 .75 1.7941454202077352 21914 0 . 18353 . . 2 6 18494 2010 2011 0 18494 19369 0 0 875 7.9 5.7192611664852535 .5 3.2332563510392744 19369 0 . 18494 . . 1 6 18628 2011 2012 0 18494 19369 0 0 875 8.1 -1.4534650630884298 .5 4.474272930648769 19369 0 . 18494 . . 1 6 18993 2012 2013 0 18494 19369 0 0 875 8 .3975810358062328 .5 2.8907922912205444 19369 0 . 18494 . . 1 6 19359 2013 2014 1 18494 19369 0 0 875 7.6 2.5711748571913122 .5 2.497398543184189 19369 0 . 18494 . . 2 6 19369 2013 2014 1 18494 19369 0 0 875 7.6 2.5711748571913122 .5 2.497398543184189 19369 0 . 18494 . . 2 7 18378 2010 2011 0 18378 18928 0 0 550 7.9 5.7192611664852535 .5 3.2332563510392744 18928 0 . 18378 . . 1 7 18628 2011 2012 1 18378 18928 0 0 550 8.1 -1.4534650630884298 .5 4.474272930648769 18928 0 . 18378 . . 2 7 18928 2011 2012 1 18378 18928 0 0 550 8.1 -1.4534650630884298 .5 4.474272930648769 18928 0 . 18378 . . 2 8 18581 2010 2011 0 18581 23436 2 1 3333 7.9 5.7192611664852535 .5 3.2332563510392744 21914 0 . 18581 . . 1 8 18628 2011 2012 0 18581 23436 2 1 3333 8.1 -1.4534650630884298 .5 4.474272930648769 21914 0 . 18581 . . 1 8 18993 2012 2013 0 18581 23436 2 1 3333 8 .3975810358062328 .5 2.8907922912205444 21914 0 . 18581 . . 1 8 19359 2013 2014 0 18581 23436 2 1 3333 7.6 2.5711748571913122 .5 2.497398543184189 21914 0 . 18581 . . 1 8 19724 2014 2015 0 18581 23436 2 1 3333 6.2 8.02835840481228 .5 1.5228426395939088 21914 0 . 18581 . . 1 8 20089 2015 2016 0 18581 23436 2 1 3333 5.4 5.953962989080778 .5 0 21914 0 . 18581 . . 1 8 20454 2016 2017 0 18581 23436 2 1 3333 4.9 6.991080092582217 .3975409836065574 .7000000000000028 21914 0 . 18581 . . 1 8 20820 2017 2018 0 18581 23436 2 1 3333 4.4 4.571008995035573 .2910958904109589 2.6812313803376395 21914 0 . 18581 . . 1 8 21185 2018 2019 0 18581 23436 2 1 3333 4.2 3.1397474428639596 .6041095890410959 2.4177949709864603 21914 0 . 18581 . . 1 8 21550 2019 2020 0 18581 23436 2 1 3333 3.9 .988768711078791 .75 1.7941454202077352 21914 0 . 18581 . . 2 8 21914 2019 2020 0 18581 23436 2 1 3333 3.9 .988768711078791 .75 1.7941454202077352 21914 0 . 18581 . . 2 9 18498 2010 2011 0 18498 19285 0 0 787 7.9 5.7192611664852535 .5 3.2332563510392744 19285 0 . 18498 . . 1 9 18628 2011 2012 0 18498 19285 0 0 787 8.1 -1.4534650630884298 .5 4.474272930648769 19285 0 . 18498 . . 1 9 18993 2012 2013 1 18498 19285 0 0 787 8 .3975810358062328 .5 2.8907922912205444 19285 0 . 18498 . . 2 9 19285 2012 2013 1 18498 19285 0 0 787 8 .3975810358062328 .5 2.8907922912205444 19285 0 . 18498 . . 2 10 18528 2010 2011 0 18528 23366 1 1 3386 7.9 5.7192611664852535 .5 3.2332563510392744 21914 0 . 18528 . . 1 10 18628 2011 2012 0 18528 23366 1 1 3386 8.1 -1.4534650630884298 .5 4.474272930648769 21914 0 . 18528 . . 1 10 18993 2012 2013 0 18528 23366 1 1 3386 8 .3975810358062328 .5 2.8907922912205444 21914 0 . 18528 . . 1 10 19359 2013 2014 0 18528 23366 1 1 3386 7.6 2.5711748571913122 .5 2.497398543184189 21914 0 . 18528 . . 1 10 19724 2014 2015 0 18528 23366 1 1 3386 6.2 8.02835840481228 .5 1.5228426395939088 21914 0 . 18528 . . 1 10 20089 2015 2016 0 18528 23366 1 1 3386 5.4 5.953962989080778 .5 0 21914 0 . 18528 . . 1 10 20454 2016 2017 0 18528 23366 1 1 3386 4.9 6.991080092582217 .3975409836065574 .7000000000000028 21914 0 . 18528 . . 1 10 20820 2017 2018 0 18528 23366 1 1 3386 4.4 4.571008995035573 .2910958904109589 2.6812313803376395 21914 0 . 18528 . . 1 10 21185 2018 2019 0 18528 23366 1 1 3386 4.2 3.1397474428639596 .6041095890410959 2.4177949709864603 21914 0 . 18528 . . 1 10 21550 2019 2020 0 18528 23366 1 1 3386 3.9 .988768711078791 .75 1.7941454202077352 21914 0 . 18528 . . 2 10 21914 2019 2020 0 18528 23366 1 1 3386 3.9 .988768711078791 .75 1.7941454202077352 21914 0 . 18528 . . 2 end format %td time format %td IncorpDate format %tdnn/dd/CCYY LastTransaction format %td DOF [/CODE] As you can see, each companyID should have a maximum of 10 observations but whenever the year 2019 appears as 'time' it is repeated twice, therefore skewing the dataset. I know it occurred when running command 'by CompanyID (Start), sort: replace time = DOF if _n == _N ' but I don't know how to resolve this or if it is what is causing Unemployment to trigger error r430. If you are able to help this would be greatly appreciated!

                          Comment


                          • #14
                            Apologies, the data did not copy in with a clear structure. Let's try again:


                            input int CompanyID float time int(Start Stop) byte Event int(IncorpDate LastTransaction) byte(CurrentDirectors Group) int SurvivalDays double(Unemployment HousePrices InterestRates CPI) int DOF byte(_st _d) int(_origin _t) byte _t0 float expander
                            1 18268 2010 2011 0 18268 21689 0 0 3421 7.9 5.7192611664852535 .5 3.2332563510392744 21689 0 . 18268 . . 1
                            1 18628 2011 2012 0 18268 21689 0 0 3421 8.1 -1.4534650630884298 .5 4.474272930648769 21689 0 . 18268 . . 1
                            1 18993 2012 2013 0 18268 21689 0 0 3421 8 .3975810358062328 .5 2.8907922912205444 21689 0 . 18268 . . 1
                            1 19359 2013 2014 0 18268 21689 0 0 3421 7.6 2.5711748571913122 .5 2.497398543184189 21689 0 . 18268 . . 1
                            1 19724 2014 2015 0 18268 21689 0 0 3421 6.2 8.02835840481228 .5 1.5228426395939088 21689 0 . 18268 . . 1
                            1 20089 2015 2016 0 18268 21689 0 0 3421 5.4 5.953962989080778 .5 0 21689 0 . 18268 . . 1
                            1 20454 2016 2017 0 18268 21689 0 0 3421 4.9 6.991080092582217 .3975409836065574 .7000000000000028 21689 0 . 18268 . . 1
                            1 20820 2017 2018 0 18268 21689 0 0 3421 4.4 4.571008995035573 .2910958904109589 2.6812313803376395 21689 0 . 18268 . . 1
                            1 21185 2018 2019 0 18268 21689 0 0 3421 4.2 3.1397474428639596 .6041095890410959 2.4177949709864603 21689 0 . 18268 . . 1
                            1 21550 2019 2020 1 18268 21689 0 0 3421 3.9 .988768711078791 .75 1.7941454202077352 21689 0 . 18268 . . 2
                            1 21689 2019 2020 1 18268 21689 0 0 3421 3.9 .988768711078791 .75 1.7941454202077352 21689 0 . 18268 . . 2
                            2 18438 2010 2011 0 18438 23523 2 1 3476 7.9 5.7192611664852535 .5 3.2332563510392744 21914 0 . 18438 . . 1
                            2 18628 2011 2012 0 18438 23523 2 1 3476 8.1 -1.4534650630884298 .5 4.474272930648769 21914 0 . 18438 . . 1
                            2 18993 2012 2013 0 18438 23523 2 1 3476 8 .3975810358062328 .5 2.8907922912205444 21914 0 . 18438 . . 1
                            2 19359 2013 2014 0 18438 23523 2 1 3476 7.6 2.5711748571913122 .5 2.497398543184189 21914 0 . 18438 . . 1
                            2 19724 2014 2015 0 18438 23523 2 1 3476 6.2 8.02835840481228 .5 1.5228426395939088 21914 0 . 18438 . . 1
                            2 20089 2015 2016 0 18438 23523 2 1 3476 5.4 5.953962989080778 .5 0 21914 0 . 18438 . . 1
                            2 20454 2016 2017 0 18438 23523 2 1 3476 4.9 6.991080092582217 .3975409836065574 .7000000000000028 21914 0 . 18438 . . 1
                            2 20820 2017 2018 0 18438 23523 2 1 3476 4.4 4.571008995035573 .2910958904109589 2.6812313803376395 21914 0 . 18438 . . 1
                            2 21185 2018 2019 0 18438 23523 2 1 3476 4.2 3.1397474428639596 .6041095890410959 2.4177949709864603 21914 0 . 18438 . . 1
                            2 21550 2019 2020 0 18438 23523 2 1 3476 3.9 .988768711078791 .75 1.7941454202077352 21914 0 . 18438 . . 2
                            2 21914 2019 2020 0 18438 23523 2 1 3476 3.9 .988768711078791 .75 1.7941454202077352 21914 0 . 18438 . . 2
                            3 18571 2010 2011 0 18571 19131 0 0 560 7.9 5.7192611664852535 .5 3.2332563510392744 19131 0 . 18571 . . 1
                            3 18628 2011 2012 0 18571 19131 0 0 560 8.1 -1.4534650630884298 .5 4.474272930648769 19131 0 . 18571 . . 1
                            3 18993 2012 2013 1 18571 19131 0 0 560 8 .3975810358062328 .5 2.8907922912205444 19131 0 . 18571 . . 2
                            3 19131 2012 2013 1 18571 19131 0 0 560 8 .3975810358062328 .5 2.8907922912205444 19131 0 . 18571 . . 2
                            4 18443 2010 2011 0 18443 19285 0 0 842 7.9 5.7192611664852535 .5 3.2332563510392744 19285 0 . 18443 . . 1
                            4 18628 2011 2012 0 18443 19285 0 0 842 8.1 -1.4534650630884298 .5 4.474272930648769 19285 0 . 18443 . . 1
                            4 18993 2012 2013 1 18443 19285 0 0 842 8 .3975810358062328 .5 2.8907922912205444 19285 0 . 18443 . . 2
                            4 19285 2012 2013 1 18443 19285 0 0 842 8 .3975810358062328 .5 2.8907922912205444 19285 0 . 18443 . . 2
                            5 18353 2010 2011 0 18353 23553 1 1 3561 7.9 5.7192611664852535 .5 3.2332563510392744 21914 0 . 18353 . . 1
                            5 18628 2011 2012 0 18353 23553 1 1 3561 8.1 -1.4534650630884298 .5 4.474272930648769 21914 0 . 18353 . . 1
                            5 18993 2012 2013 0 18353 23553 1 1 3561 8 .3975810358062328 .5 2.8907922912205444 21914 0 . 18353 . . 1
                            5 19359 2013 2014 0 18353 23553 1 1 3561 7.6 2.5711748571913122 .5 2.497398543184189 21914 0 . 18353 . . 1
                            5 19724 2014 2015 0 18353 23553 1 1 3561 6.2 8.02835840481228 .5 1.5228426395939088 21914 0 . 18353 . . 1
                            5 20089 2015 2016 0 18353 23553 1 1 3561 5.4 5.953962989080778 .5 0 21914 0 . 18353 . . 1
                            5 20454 2016 2017 0 18353 23553 1 1 3561 4.9 6.991080092582217 .3975409836065574 .7000000000000028 21914 0 . 18353 . . 1
                            5 20820 2017 2018 0 18353 23553 1 1 3561 4.4 4.571008995035573 .2910958904109589 2.6812313803376395 21914 0 . 18353 . . 1
                            5 21185 2018 2019 0 18353 23553 1 1 3561 4.2 3.1397474428639596 .6041095890410959 2.4177949709864603 21914 0 . 18353 . . 1
                            5 21550 2019 2020 0 18353 23553 1 1 3561 3.9 .988768711078791 .75 1.7941454202077352 21914 0 . 18353 . . 2
                            5 21914 2019 2020 0 18353 23553 1 1 3561 3.9 .988768711078791 .75 1.7941454202077352 21914 0 . 18353 . . 2
                            6 18494 2010 2011 0 18494 19369 0 0 875 7.9 5.7192611664852535 .5 3.2332563510392744 19369 0 . 18494 . . 1
                            6 18628 2011 2012 0 18494 19369 0 0 875 8.1 -1.4534650630884298 .5 4.474272930648769 19369 0 . 18494 . . 1
                            6 18993 2012 2013 0 18494 19369 0 0 875 8 .3975810358062328 .5 2.8907922912205444 19369 0 . 18494 . . 1
                            6 19359 2013 2014 1 18494 19369 0 0 875 7.6 2.5711748571913122 .5 2.497398543184189 19369 0 . 18494 . . 2
                            6 19369 2013 2014 1 18494 19369 0 0 875 7.6 2.5711748571913122 .5 2.497398543184189 19369 0 . 18494 . . 2
                            7 18378 2010 2011 0 18378 18928 0 0 550 7.9 5.7192611664852535 .5 3.2332563510392744 18928 0 . 18378 . . 1
                            7 18628 2011 2012 1 18378 18928 0 0 550 8.1 -1.4534650630884298 .5 4.474272930648769 18928 0 . 18378 . . 2
                            7 18928 2011 2012 1 18378 18928 0 0 550 8.1 -1.4534650630884298 .5 4.474272930648769 18928 0 . 18378 . . 2
                            8 18581 2010 2011 0 18581 23436 2 1 3333 7.9 5.7192611664852535 .5 3.2332563510392744 21914 0 . 18581 . . 1
                            8 18628 2011 2012 0 18581 23436 2 1 3333 8.1 -1.4534650630884298 .5 4.474272930648769 21914 0 . 18581 . . 1
                            8 18993 2012 2013 0 18581 23436 2 1 3333 8 .3975810358062328 .5 2.8907922912205444 21914 0 . 18581 . . 1
                            8 19359 2013 2014 0 18581 23436 2 1 3333 7.6 2.5711748571913122 .5 2.497398543184189 21914 0 . 18581 . . 1
                            8 19724 2014 2015 0 18581 23436 2 1 3333 6.2 8.02835840481228 .5 1.5228426395939088 21914 0 . 18581 . . 1
                            8 20089 2015 2016 0 18581 23436 2 1 3333 5.4 5.953962989080778 .5 0 21914 0 . 18581 . . 1
                            8 20454 2016 2017 0 18581 23436 2 1 3333 4.9 6.991080092582217 .3975409836065574 .7000000000000028 21914 0 . 18581 . . 1
                            8 20820 2017 2018 0 18581 23436 2 1 3333 4.4 4.571008995035573 .2910958904109589 2.6812313803376395 21914 0 . 18581 . . 1
                            8 21185 2018 2019 0 18581 23436 2 1 3333 4.2 3.1397474428639596 .6041095890410959 2.4177949709864603 21914 0 . 18581 . . 1
                            8 21550 2019 2020 0 18581 23436 2 1 3333 3.9 .988768711078791 .75 1.7941454202077352 21914 0 . 18581 . . 2
                            8 21914 2019 2020 0 18581 23436 2 1 3333 3.9 .988768711078791 .75 1.7941454202077352 21914 0 . 18581 . . 2
                            9 18498 2010 2011 0 18498 19285 0 0 787 7.9 5.7192611664852535 .5 3.2332563510392744 19285 0 . 18498 . . 1
                            9 18628 2011 2012 0 18498 19285 0 0 787 8.1 -1.4534650630884298 .5 4.474272930648769 19285 0 . 18498 . . 1
                            9 18993 2012 2013 1 18498 19285 0 0 787 8 .3975810358062328 .5 2.8907922912205444 19285 0 . 18498 . . 2
                            9 19285 2012 2013 1 18498 19285 0 0 787 8 .3975810358062328 .5 2.8907922912205444 19285 0 . 18498 . . 2
                            10 18528 2010 2011 0 18528 23366 1 1 3386 7.9 5.7192611664852535 .5 3.2332563510392744 21914 0 . 18528 . . 1
                            10 18628 2011 2012 0 18528 23366 1 1 3386 8.1 -1.4534650630884298 .5 4.474272930648769 21914 0 . 18528 . . 1
                            10 18993 2012 2013 0 18528 23366 1 1 3386 8 .3975810358062328 .5 2.8907922912205444 21914 0 . 18528 . . 1
                            10 19359 2013 2014 0 18528 23366 1 1 3386 7.6 2.5711748571913122 .5 2.497398543184189 21914 0 . 18528 . . 1
                            10 19724 2014 2015 0 18528 23366 1 1 3386 6.2 8.02835840481228 .5 1.5228426395939088 21914 0 . 18528 . . 1
                            10 20089 2015 2016 0 18528 23366 1 1 3386 5.4 5.953962989080778 .5 0 21914 0 . 18528 . . 1
                            10 20454 2016 2017 0 18528 23366 1 1 3386 4.9 6.991080092582217 .3975409836065574 .7000000000000028 21914 0 . 18528 . . 1
                            10 20820 2017 2018 0 18528 23366 1 1 3386 4.4 4.571008995035573 .2910958904109589 2.6812313803376395 21914 0 . 18528 . . 1
                            10 21185 2018 2019 0 18528 23366 1 1 3386 4.2 3.1397474428639596 .6041095890410959 2.4177949709864603 21914 0 . 18528 . . 1
                            10 21550 2019 2020 0 18528 23366 1 1 3386 3.9 .988768711078791 .75 1.7941454202077352 21914 0 . 18528 . . 2
                            10 21914 2019 2020 0 18528 23366 1 1 3386 3.9 .988768711078791 .75 1.7941454202077352 21914 0 . 18528 . . 2
                            end
                            format %td time
                            format %td IncorpDate
                            format %tdnn/dd/CCYY LastTransaction
                            format %td DOF
                            [/CODE]


                            As you can see, each companyID should have a maximum of 10 observations but whenever the year 2019 appears as 'time' it is repeated twice, therefore skewing the dataset. I know it occurred when running command 'by CompanyID (Start), sort: replace time = DOF if _n == _N ' but I don't know how to resolve this or if it is what is causing Unemployment to trigger error r430. If you are able to help this would be greatly appreciated!As you can see, each companyID should have a maximum of 10 observations but whenever the year 2019 appears as 'time' it is repeated twice, therefore skewing the dataset. I know it occurred when running command 'by CompanyID (Start), sort: replace time = DOF if _n == _N ' but I don't know how to resolve this or if it is what is causing Unemployment to trigger error r430. If you are able to help this would be greatly appreciated!
                            Last edited by Roos Schyns; 08 Aug 2024, 16:03.

                            Comment


                            • #15
                              Yes, but the year 2019 never appears as time. It appears as Start, but time itself is a full date. And, apart from being one ingredient in the recipe for the time variable, Start is never used again in the code. Note that the -stset- command uses time as the _t variable, not Start. And you can confirm that there are no instances of duplicate values of time for a given CompanyID by running -duplicates report CompanyID time-. Actually, you already know it from the results of the -stset- command: had there been any observations of the same CompanyID with the same value of time, there would have been a line in the -stset- output mentioning that as a probable error.

                              So this is not a problem.

                              Comment

                              Working...
                              X