I have a long data set containing college enrollment data by term, multiple instances per student ID. If a student enrolled 10 terms in college, there will be 10 date rows per ID. The date data variables include high school graduate date, enrollment begin (college) enrollment (end) college and graduation date (college). Each date is in a separate column, my issue is occurring specifically in graduation_date.
The graduated variable is marked N or Y if a student graduated college. I created a variable (degree) to note N = 0 and Y = 1. Then ran code
Code:
by randomid, sort: egen college_grad = max(degree)
I want to now carry over graduation_date by each observation where college_grad is 1. I did this with code
Code:
bys randomid: egen degree_date=max(graduation_date)
I also formatted the dates using
Code:
foreach var of varlist enrollment_begin enrollment_end graduation_date high_school_grad_date degree_date { replace `var' = date(string(`var' ,"%08.0f"),"YMD") format %td `var' }
Essentially what I am trying to do is convert the different dates to terms in order to run length of time between each date, over time
Code:
* Example generated by -dataex-. For more info, type help dataex clear input double randomid long(high_school_grad_date enrollment_begin enrollment_end) str1 graduated long graduation_date float(degree college_grad degree_date) 2103300231 22804 22886 22997 "N" . 0 0 . 2103300237 22804 . . "N" . 0 0 . 2103300243 22804 . . "N" . 0 0 . 2103300255 22069 22886 22997 "N" . 0 0 . 2103300255 22069 22312 22408 "N" . 0 0 . 2103300255 22069 22522 22633 "N" . 0 0 . 2103300255 22069 22432 22497 "N" . 0 0 . 2103300255 22069 22432 22505 "N" . 0 0 . 2103300255 22069 22662 22773 "N" . 0 0 . 2103300255 22069 22158 22262 "N" . 0 0 . 2103300264 22069 22508 22631 "N" . 0 0 . 2103300264 22069 22144 22267 "N" . 0 0 . 2103300264 22069 22872 22995 "N" . 0 0 . 2103300264 22069 22872 22996 "N" . 0 0 . 2103300264 22069 22663 22789 "N" . 0 0 . 2103300264 22069 22872 22995 "N" . 0 0 . 2103300264 22069 22872 22996 "N" . 0 0 . 2103300267 21705 22817 22836 "N" . 0 0 . 2103300267 21705 22067 22074 "N" . 0 0 . 2103300267 21705 22515 22630 "N" . 0 0 . 2103300267 21705 21780 21903 "N" . 0 0 . 2103300267 21705 22879 22996 "N" . 0 0 . 2103300267 21705 22144 22210 "N" . 0 0 . 2103300267 21705 21927 22056 "N" . 0 0 . 2103300267 21705 22690 22806 "N" . 0 0 . 2103300282 21341 . . "N" . 0 0 . 2103300291 20977 . . "N" . 0 0 . 2103300321 22804 . . "N" . 0 0 . 2103300336 21340 22676 22792 "N" . 0 0 . 2103300336 21340 22883 22995 "N" . 0 0 . 2103300426 22440 . . "N" . 0 0 . 2103300477 21341 21409 21532 "N" . 0 0 . 2103300477 21341 21927 22056 "N" . 0 0 . 2103300477 21341 21563 21692 "N" . 0 0 . 2103300477 21341 22872 22995 "N" . 0 0 . 2103300477 21341 22299 22425 "N" . 0 0 . 2103300477 21341 22144 22267 "N" . 0 0 . 2103300477 21341 21780 21903 "N" . 0 0 . 2103300477 21341 22879 22995 "N" . 0 0 . 2103300477 21341 22872 22996 "N" . 0 0 . 2103300477 21341 22515 22631 "N" . 0 0 . 2103300477 21341 22797 22873 "N" . 0 0 . 2103300477 21341 22067 22141 "N" . 0 0 . 2103300477 21341 22669 22785 "N" . 0 0 . 2103300477 21341 22872 22996 "N" . 0 0 . 2103300477 21341 22872 22995 "N" . 0 0 . 2103300495 20977 21409 21431 "N" . 0 0 . 2103300495 20977 21200 21328 "N" . 0 0 . 2103300552 21705 22515 22626 "N" . 0 0 . 2103300552 21705 21927 22056 "N" . 0 0 . 2103300552 21705 22879 22990 "N" . 0 0 . 2103300552 21705 22319 22437 "N" . 0 0 . 2103300552 21705 21780 21903 "N" . 0 0 . 2103300552 21705 22151 22262 "N" . 0 0 . 2103300552 21705 22683 22801 "N" . 0 0 . 2103300552 21705 22144 22267 "N" . 0 0 . 2103300552 21705 22067 22141 "N" . 0 0 . 2103300552 21705 22879 22994 "N" . 0 0 . 2103300561 22069 22144 22267 "N" . 0 0 . 2103300561 22069 22879 22995 "N" . 0 0 . 2103300561 22069 22648 22778 "N" . 0 0 . 2103300561 22069 22284 22407 "N" . 0 0 . 2103300561 22069 22781 22868 "N" . 0 0 . 2103300561 22069 22515 22631 "N" . 0 0 . 2103300585 22440 22522 22632 "N" . 0 0 . 2103300585 22440 22669 22784 "N" . 0 0 . 2103300585 22440 22796 22861 "N" . 0 0 . 2103300585 22440 22796 22869 "N" . 0 0 . 2103300591 22440 . . "N" . 0 0 . 2103300594 22804 . . "N" . 0 0 . 2103300600 22804 . . "N" . 0 0 . 2103300603 22656 . . "N" . 0 0 . 2103300855 22804 22900 22991 "N" . 0 0 . 2103300861 22440 22872 22996 "N" . 0 0 . 2103300861 22440 22872 22995 "N" . 0 0 . 2103300861 22440 22796 22861 "N" . 0 0 . 2103300861 22440 22872 22995 "N" . 0 0 . 2103300861 22440 22796 22869 "N" . 0 0 . 2103300861 22440 22508 22631 "N" . 0 0 . 2103300861 22440 22663 22789 "N" . 0 0 . 2103300861 22440 22872 22996 "N" . 0 0 . 3333004638 20248 . . "N" . 0 0 . 3333004845 20248 20472 20600 "N" . 0 0 . 3333004845 20248 20318 20440 "N" . 0 0 . 3333004845 20248 22524 22704 "N" . 0 0 . 3333004845 20248 22705 22888 "N" . 0 0 . 3333004845 20248 22889 23069 "N" . 0 0 . 3333005328 20248 21409 21456 "N" . 0 0 . 3333005328 20248 20682 20804 "N" . 0 0 . 3333005340 20248 22515 22631 "N" . 0 1 22078 3333005340 20248 21818 21889 "N" . 0 1 22078 3333005340 20248 . . "Y" 22078 1 1 22078 3333005340 20248 21556 21623 "N" . 0 1 22078 3333005340 20248 21818 21896 "N" . 0 1 22078 3333005340 20248 22305 22420 "N" . 0 1 22078 3333005340 20248 22151 22267 "N" . 0 1 22078 3333005340 20248 22879 22995 "N" . 0 1 22078 3333005340 20248 . . "Y" 22078 1 1 22078 3333005340 20248 21916 21994 "N" . 0 1 22078 3333005340 20248 21999 22078 "N" . 0 1 22078 end format %td high_school_grad_date format %td enrollment_begin format %td enrollment_end format %td graduation_date format %td degree_date
Thank you.
0 Response to Bysort and egen code not carrying over correct data
Post a Comment