# Re: st: Aggregate date to calculate n months

 From Jeph Herrin To statalist@hsphsun2.harvard.edu Subject Re: st: Aggregate date to calculate n months Date Mon, 04 Aug 2008 11:38:39 -0400

```Tips:
1. Work with native Stata date variables. So you will
want to create

. gen start_date = mdy(startm,startd,starty)

be sure "starty" is four digits (eg, 2008, not 08).
Similarly,

. gen survey_date = mdy(surveym,surveyd,surveyy)

and then format them as dates for convenience

. format start_date survey_date %d

2. Then it is easy to convert these to elapsed months:

. gen start_month=mofd(start_date)
. gen survey_month=mofd(survey_date)

will create two variables, each giving the number of months
elapsed since 1/1/1960. After this, it's a small matter
to get the difference in months:

. gen treatment_months = survey_month-start_month

hope this helps,
Jeph

```
```Hi!
I entered dates of patients starting on treatment and date of their
interview under different variables:

startd (for day)
startm (for month)
starty (for year)

surveyd (for day)
surveym (month)
surveyy (year)

Now i want to calculate number of months patients have been on treatment.
I am finding problems in creating
start=startd+startm+starty
survey=surveyd+surveym+surveyy

period=survey-start

Any tips?

Thank you and best regards
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

```
```*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```