I am having trouble when Stata converts a variable from numeric to a string, as it appears to be incrementing the number by 1.
I have two variables that each hold dates. If one holds a date, the other is blank. Both date variables are numeric variables that are not yet converted to function as dates in Stata. I want a single variable that holds the date info from both variables, and use egen rowtotal. I then use tostring to convert the combined variable to a string so that I can use the Stata's date commands.
Code:
. desc EnrollmentEnd GraduationDate Variable Storage Display Value name type format label Variable label ------------------------------------------------------------------------------------------------- EnrollmentEnd long %10.0g Enrollment End GraduationDate long %10.0g Graduation Date . egen date_grad_last=rowtotal(EnrollmentEnd GraduationDate),missing (1,322 missing values generated) . tostring date_grad_last, gen(stdate_grad_last) stdate_grad_last generated as str8 . format %15.0g date_grad_last
Code:
. list EnrollmentEnd GraduationDate date_grad_last stdate_grad_last in 2 +-------------------------------------------+ | Enroll~d Gradua~e date_g~t stdate~t | |-------------------------------------------| 2. | . 20160531 20160532 20160532 | +-------------------------------------------+ +-------------------------------------------+ | Enroll~d Gradua~e date_g~t stdate~t | |-------------------------------------------| 14. | 20100601 . 20100600 20100600 | +-------------------------------------------+
Code:
gen dtdate_grad_last= date(stdate_grad_last, "YMD") format %td dtdate_grad_last . list EnrollmentEnd GraduationDate date_grad_last stdate_grad_last dtdate_grad_last in 2 +------------------------------------------------------+ | Enroll~d Gradua~e date_g~t stdate~t dtdate~t | |------------------------------------------------------| 2. | . 20160531 20160532 20160532 . | +------------------------------------------------------+ . list EnrollmentEnd GraduationDate date_grad_last stdate_grad_last dtdate_grad_last in 14 +------------------------------------------------------+ | Enroll~d Gradua~e date_g~t stdate~t dtdate~t | |------------------------------------------------------| 14. | 20100601 . 20100600 20100600 . | +------------------------------------------------------+
Thanks!
0 Response to Conversion of string to number changes number
Post a Comment