Hello,

I'm sure someone has posted about this on the forum before but I can't find the exact answer I'm looking for.

As you can see from my dataex example, I have a list of birthdates (birth_date) and a list of encounter dates (date). I am trying to create a variable that represents age at encounter.

1) I tried creating a new formatted birthdate variable by using: gen birthdate=date(birth_date,"MDY") but it turned all of the values to missing. when I tried "MD20Y" it messed up the 1990's dates (eg 2099 instead of 1999). When I tried "MDYY" all of the values are missing again. I'm not sure what I'm doing wrong.
2) When I get the birthdate correctly formatted, is it correct to calculate age using: gen ageyears=int((date-birthdate)/365.25) ?

Thank you!

Sarah


Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str14 birth_date float date
"6/29/66 0:00"  22098
"6/29/66 0:00"  21941
"8/12/09 0:00"  21798
"8/12/09 0:00"  22134
"8/12/09 0:00"  22036
"8/12/09 0:00"  21896
"1/17/96 0:00"  21802
"1/17/96 0:00"  22033
"4/24/91"       21966
"4/24/91"       22043
"4/24/91"       21875
"12/6/65"       22090
"12/6/65"       22083
"5/14/80 0:00"  21935
"8/5/50 0:00"   21852
"9/13/48 0:00"  22019
"9/13/48 0:00"  21984
"12/2/50"       22046
"12/2/50"       21927
"12/2/50"       22175
"4/8/75 0:00"   21928
"4/8/75 0:00"   22096
"4/17/50 0:00"  21808
"4/17/50 0:00"  21969
"4/17/50 0:00"  21871
"10/23/50 0:00" 21878
"8/19/62"       21892
"3/29/57 0:00"  21921
"3/29/57 0:00"  22124
"9/16/63"       21951
"9/16/63"       21980
"11/12/56"      21928
"8/15/61 0:00"  21816
"7/21/53 0:00"  21833
"7/21/53 0:00"  22085
"7/21/53 0:00"  21959
"9/15/99 0:00"  22111
"9/15/99 0:00"  22029
"9/15/99 0:00"  22015
"10/10/98 0:00" 21858
"10/10/98 0:00" 21874
"10/10/98 0:00" 22105
"10/10/98 0:00" 21986
"10/10/98 0:00" 21825
"3/12/92 0:00"  21836
"3/12/92 0:00"  21903
"3/12/92 0:00"  22173
"7/13/49 0:00"  21832
"7/13/49 0:00"  21847
"7/13/49 0:00"  21963
"7/13/49 0:00"  21840
"7/13/49 0:00"  21843
"8/5/98 0:00"   21963
"8/5/98 0:00"   22005
"11/27/59"      21910
"11/27/59"      22008
"8/27/84 0:00"  21936
"8/27/84 0:00"  22172
"11/23/88 0:00" 22131
"11/23/88 0:00" 21977
"11/8/56 0:00"  21832
"11/8/56 0:00"  22154
"6/29/47 0:00"  22110
"5/4/63 0:00"   21836
"5/4/63 0:00"   21928
"5/4/63 0:00"   21956
"5/4/63 0:00"   21893
"5/4/63 0:00"   21838
"5/4/63 0:00"   21830
"5/4/63 0:00"   21858
"5/4/63 0:00"   22061
"5/4/63 0:00"   21837
"8/2/42 0:00"   22057
"8/2/42 0:00"   21889
"7/27/94"       22111
"7/27/94"       21928
"1/5/41 0:00"   21998
"1/5/41 0:00"   22082
"1/5/41 0:00"   21812
"11/10/08 0:00" 22095
"11/10/08 0:00" 21998
"11/10/08 0:00" 21802
"3/30/58 0:00"  21899
"11/9/00 0:00"  22076
"12/2/89 0:00"  22154
"1/23/56 0:00"  21920
"1/3/61 0:00"   21931
"1/3/61 0:00"   21840
"1/23/56 0:00"  21955
"1/3/61 0:00"   22113
"1/3/61 0:00"   22029
"7/21/55"       21857
"2/13/74 0:00"  22109
"2/13/74 0:00"  22183
"2/13/74 0:00"  21949
"2/13/74 0:00"  21921
"2/8/10 0:00"   22039
"2/8/10 0:00"   21829
"4/18/55 0:00"  22035
"12/10/61 0:00" 22047
end
format %td date