Some one help me write a code to sort out this challenge: I have a dataset containing several appointment dates per ID such that some IDs have three visits and others as many as 30. I have been, unsuccessfully trying to create variables denoting say appointment_date1, appointment_date2......appointment_date_k (like in wide format)
sample dates is pasted below
I would like to create variables like dt_visitdate1 for all dt_visitdate in with newid==1, dt_visitdate2 for all dt_visitdate where newid==2 .............dt_vistdatek for dt_visitdate where newid==k :
I am using stata 16.1 for Mac
Thank you
Mutugi Muriithi
sample dates is pasted below
I would like to create variables like dt_visitdate1 for all dt_visitdate in with newid==1, dt_visitdate2 for all dt_visitdate where newid==2 .............dt_vistdatek for dt_visitdate where newid==k :
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str13 id2 str10 dob int sitecode float(dt_visitdate newid) "1010390" "24/02/1964" 12215 20474 1 "1010390" "24/02/1964" 12215 20478 2 "1010390" "24/02/1964" 12215 20481 3 "1010390" "24/02/1964" 12215 20537 4 "1010390" "24/02/1964" 12215 20626 5 "1010390" "24/02/1964" 12215 20710 6 "1010390" "24/02/1964" 12215 20768 7 "1011343603" "17/06/1969" 12236 20662 1 "1011343603" "17/06/1969" 12236 21493 2 "1011343603" "17/06/1969" 12236 21578 3 "1011343603" "17/06/1969" 12236 21607 4 "1011343603" "17/06/1969" 12236 21636 5 "1011343603" "17/06/1969" 12236 21682 6 "1012011317" "15/06/1963" 11936 20881 1 "10120300223" "10/07/1979" 11936 20536 1 "10120300223" "10/07/1979" 11936 20592 2 "10120300223" "10/07/1979" 11936 20636 3 "1012120323" "13/08/1985" 12215 21671 1 "1012120323" "13/08/1985" 12215 21699 2 "1012120323" "13/08/1985" 12215 21727 3 "1012120323" "13/08/1985" 12215 21759 4 "1012120323" "13/08/1985" 12215 21790 5 "1012120323" "13/08/1985" 12215 21810 6 "1012120323" "13/08/1985" 12215 21839 7 "1012120323" "13/08/1985" 12215 21867 8 "1012120323" "13/08/1985" 12215 21868 9 "1012120323" "13/08/1985" 12215 21899 10 "101288" "05/10/2004" 12291 20488 1 "101288" "05/10/2004" 12291 20544 2 "101288" "05/10/2004" 12291 20597 3 "1013500031" "15/06/1966" 12341 20560 1 "1014" "15/06/1954" 12341 21235 1 "1014" "15/06/1954" 12341 21262 2 "1014" "15/06/1954" 12341 21292 3 "1014" "15/06/1954" 12341 21321 4 "1014" "15/06/1954" 12341 21355 5 "1014" "15/06/1954" 12341 21377 6 "1014" "15/06/1954" 12341 21405 7 "1014" "15/06/1954" 12341 21487 8 "1014" "15/06/1954" 12341 21516 9 "1014" "15/06/1954" 12341 21536 10 "1014" "15/06/1954" 12341 21594 11 "1014" "15/06/1954" 12341 21628 12 "1014" "15/06/1954" 12341 21656 13 "1014" "15/06/1954" 12341 21712 14 "1014" "15/06/1954" 12341 21740 15 "1014" "15/06/1954" 12341 21767 16 "1014" "15/06/1954" 12341 21795 17 "1014" "15/06/1954" 12341 21879 18 "1017101271" "14/12/1986" 12291 21196 1 end format %td dt_visitdate
Thank you
Mutugi Muriithi
Comment