Dear Statalisters,
I am sorting out the database, I post as follows.
It offers firm-year data, including ID, Date of birth, Status(Active/Failed), Date of Status change, and year. For "Date of Status change", taking ID=001 as an example, it means on 10/21/2021, it failed.
I want to generate two variables.
The first is "Month_in_business", for example, for ID=001, it is failed on 10/21/2021, so in end of 2019, Month_in_business=(2019-2018)*12+(12-01)=23; in end of 2020, Month_in_business=(2020-2018)*12+(12-01)=35; in 2021, it failed on 10/21/2021, Month_in_business=(2021-2018)*3+(10-01)=45.
The second is "Failure", for example, for ID=001, it failed in 2021, so in 2019, Failure=0; in 2020, Failure=0; in 2021 Failure=1.
I know it is tricky, but I need to use the Cox model for survival analysis, I need to have these two variables.
I appreciate your help in advance!
Best regards,
Josh
------------------ copy up to and including the previous line ------------------
I am sorting out the database, I post as follows.
It offers firm-year data, including ID, Date of birth, Status(Active/Failed), Date of Status change, and year. For "Date of Status change", taking ID=001 as an example, it means on 10/21/2021, it failed.
I want to generate two variables.
The first is "Month_in_business", for example, for ID=001, it is failed on 10/21/2021, so in end of 2019, Month_in_business=(2019-2018)*12+(12-01)=23; in end of 2020, Month_in_business=(2020-2018)*12+(12-01)=35; in 2021, it failed on 10/21/2021, Month_in_business=(2021-2018)*3+(10-01)=45.
The second is "Failure", for example, for ID=001, it failed in 2021, so in 2019, Failure=0; in 2020, Failure=0; in 2021 Failure=1.
I know it is tricky, but I need to use the Cox model for survival analysis, I need to have these two variables.
I appreciate your help in advance!
Best regards,
Josh
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input long ID str10 Dateofbirth str38 Status int(Date_of_status_change year) 001 "2018-01-04" "Failed" 10/21/2021 2019 001 "2018-01-04" "Failed" 10/21/2021 2020 001 "2018-01-04" "Failed" 10/21/2021 2021 002 "2018-01-04" "Active" . 2018 002 "2018-01-04" "Active" . 2019 002 "2018-01-04" "Active" . 2020 002 "2018-01-04" "Active" . 2021 003 "2018-07-03" "Failed" 11/5/2021 2018 003 "2018-07-03" "Failed" 11/5/2021 2019 003 "2018-07-03" "Failed" 11/5/2021 2020 004 "2018-05-03" "Failed" 11/29/2019 2018 004 "2018-05-03" "Failed" 11/29/2019 2019 end format %tdnn/dd/CCYY Date_of_status_change
Comment