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


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

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


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

Last edited:
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

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!