[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Aggregate date to calculate n months

From   Jeph Herrin <[email protected]>
To   [email protected]
Subject   Re: st: Aggregate date to calculate n months
Date   Mon, 04 Aug 2008 11:38:39 -0400

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).

    . 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,

Ziad El-Khatib wrote:
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


Any tips?

Thank you and best regards
*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index