[Stata/SE 8] - How to calculate the age

momo

New Member
#1
actually, I have a problem on stata/SE 8:confused::confused:

first, date of incorporation for big sample, some examples as fellows:

1880
9/1950
01/01/2005

and I need to calculate the age of these companies how can I do it please where the variable str10.
I mean 2010- the date


Thanks in advance:D:D:D

momo
 
Last edited:
#2
Hey there,

If I were you, first I would recode the variable to obtain the same format "dd/mm/yyyy". So you need to handle different cases. For instance with the examples that you mention here, you should write smtg like :

replace date = "01/01/"+date if length(date) == 4
replace date = "0"+date if length(date) == 5
etc.

Next, if you want to calculate the age in years, you should write:

gen age = 2010 - real(substr(date,-4,.))

and adapt this if you want to calculate the age in months, days, etc.

Hope this helps!

Etienne