Hi all
Currently working with a dataset where the date of birth is a string variable (str6). The original date of birth has been replaced with figures, each figure representing the number of weeks from the first full week in 1960. Thus subject X with date of birth coded as 2480, would actually be born in mid 2007 (1960 + 2480 weeks ahead in time).
So far, in order to be able to work with this variable in an easy way I would like to convert it to a numeric variable that reads as a date with the format mm/dd/yyyy.
I started with:
destring dateofbirth, gen (dob)
format dob %tw
Now the date of birth for subject X above looks like: 2007w37
Since I lack the actual day of birth in the given week of birth, I would like to choose the middle of each week as the date of birth which could be the fourth day of the given week of birth for all subjects.
I've used the 'substr' option previously to generate dates, months and years separately before combining them together to generate one single date variable.
gen by=substr(dob,1,4)
gen bm=substr(dob,5,2)
gen bd=substr(dob,7,2)
gen byr=real(by)
gen bmo=real(bm)
gen bda=real(bd)
gen bdate=mdy(bmo,bda,byr)
format bdate %d
But I'm not aware of a way to tackle my issue above where I have only the year and week but not the actual day.
Thanks
/Amal
Currently working with a dataset where the date of birth is a string variable (str6). The original date of birth has been replaced with figures, each figure representing the number of weeks from the first full week in 1960. Thus subject X with date of birth coded as 2480, would actually be born in mid 2007 (1960 + 2480 weeks ahead in time).
So far, in order to be able to work with this variable in an easy way I would like to convert it to a numeric variable that reads as a date with the format mm/dd/yyyy.
I started with:
destring dateofbirth, gen (dob)
format dob %tw
Now the date of birth for subject X above looks like: 2007w37
Since I lack the actual day of birth in the given week of birth, I would like to choose the middle of each week as the date of birth which could be the fourth day of the given week of birth for all subjects.
I've used the 'substr' option previously to generate dates, months and years separately before combining them together to generate one single date variable.
gen by=substr(dob,1,4)
gen bm=substr(dob,5,2)
gen bd=substr(dob,7,2)
gen byr=real(by)
gen bmo=real(bm)
gen bda=real(bd)
gen bdate=mdy(bmo,bda,byr)
format bdate %d
But I'm not aware of a way to tackle my issue above where I have only the year and week but not the actual day.
Thanks
/Amal
Comment