Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Month of birth

    Hi all,

    I want to find out the month of birth of each child in my dataset. I have two variables from which I believe that I can extract the information of month of birth.
    The date of interview (dint) and age in month (agemon). I have tried the following codes:

    gen mnth = month(dint)
    gen mnthborn = (agemon-mnth)/12
    format mnthborn %12.0f
    label var mnthborn "Child's month of birth"

    But there is codes missing in between but I cannot figure out how to solve it.


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(round year) double dint float agemon
    1 2002 15637  92.67945
    2 2006     0 145.08493
    1 2002 15642  98.20274
    2 2006     0 150.50958
    1 2002 15641  96.72329
    end
    format %tdD_m_Y dint
    Thanks !

  • #2
    Does month mean "monthly date" e.g. March 1999 or "month of year" e.g. March?

    If you need both or just the second, I see two steps needed here:

    1. monthly date of birth = monthly date of interview - age in months.

    2. month of year of birth can then be extracted from that

    Your age in months has a fractional part, so you need to round. I chose to round down.

    Here is my attempt:


    Code:
    clear
    input float(round year) double dint float agemon
    1 2002 15637 92.67945
    2 2006   0 145.08493
    1 2002 15642 98.20274
    2 2006   0 150.50958
    1 2002 15641 96.72329
    end
    
    gen mdate = floor(mofd(dint) - agemon)
    gen mofy = month(dofm(mdate))
    format %tm mdate
    format %td dint
    sort dint
    l dint agemon mdate mofy
    Code:
         +---------------------------------------+
         |      dint     agemon     mdate   mofy |
         |---------------------------------------|
      1. | 01jan1960   150.5096    1947m6      6 |
      2. | 01jan1960   145.0849   1947m11     11 |
      3. | 24oct2002   92.67945    1995m1      1 |
      4. | 28oct2002   96.72329    1994m9      9 |
      5. | 29oct2002   98.20274    1994m7      7 |
         +---------------------------------------+


    Notes:

    0. I guess your zeros for date of interview (which Stata takes as 1 Jan 1960) are really missings.

    1.
    month() extracts month as 1 to 12 from a daily date. You need to use mofd().first for your problem.

    2. You divide your months by 12. That pushes you in the wrong direction. At best, the result would have units of years, but the result could not be a month of birth.

    Comment


    • #3
      Thanks !

      I am interested in month of year.

      The "0" are my other concern that I don't know how to solve. The data set is a longitudinal panel data that follows children across waves. In the 2end wave, the dint is miss recorded (from the raw data) which I have to correct for myself, instead of year 2007, it has to change to year 2006 keeping everything else, i.e months as it is. I used the following codes which came to 01jan1960 instead of only changing 2007 into 2006.

      gen DINT2=dofc(DINT)
      format DINT2 %td

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input long DINT int agechild
      17231 145
      17233 150
      17227 148
      17227 147
      17237 148
      end
      format %tdD_m_Y DINT
      label values agechild agechild
      I need to change the dint variable in wave 2 in order to extract the month of year children were born, however, I realized that this information can also be extracted from dint variable from wave 1 because if everything is recoded correctly both of year should result into the same month because I have information of childs' age in month for wave two. Of course, having the correct dint for wave 2, I can double check and validate that it is in fact the same month irrespective which wave I use for dint variable.

      Comment


      • #4
        Sorry, but I can't follow most of this.

        First, I am optimistic that #2 solves the problem in #1 but you don't seem even to discuss it and say whether it does solve the problem.

        Second, I can't follow your new post at all easily.

        For example, if dint is a daily variable, then pushing it through dofc() just produces a new variable that treats the original as a clock time. in milliseconds after midnight on 1 January 1960. That sounds utterly nonsensical to me.

        Your Stata strategy appears to be to guess wildly at what might be an answer and then be puzzled at length at what happens. Frankly, this strategy is doomed to slow your work down and engender disappointment and frustration.

        In the case of dates and times, there is no short cut. Dates and times are complicated. You just have to read the help again and again and to experiment with examples where you can check where you know the answer. I know something about dates and times. The only reason I do is that I read the help again and again and experiment.

        Here's that better strategy. Work with simple examples interactively and think through what your code implies.

        What's today's date?

        Code:
        di mdy(3, 23, 2017)
        20901
        If we say that's a clock time then it is 20901 ms, nearly 21 seconds, after midnight on 1 January 1960. All your daily dates will be, if you instruct Stata that they are clock-times, be times that are some time on 1 January 1960.

        Implication: Whatever your problem, it is nothing to do with time of day, so keep clear of all functions that take clock times as input or produce them as output.




        Comment


        • #5
          Let me try to be more clear.

          1. Yes, #2 does solve #1 perfectly ! Thanks !

          2. dint is indeed a daily variable, dint = date of interview

          In the case of dates and times, there is no short cut.
          yes, I fully agree that date and time is complicated and I have put sometime to figure out without any success but I'll see if I manage to do it with your suggestions in #4

          Comment

          Working...
          X