Announcement

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

  • Calculating gestational age (weeks and days) at time of delivery

    Sorry, if this is obvious. I am pretty new to STATA

    I have a dataset I collected that includes due date and delivery date for 100 patients. If there a way to have STATA generate the gestational age at delivery for each observation? Gestational age is typically reported as weeks+days (39 weeks and 6 days). If delivery is on the due date, that would be 40 weeks 0 days gestation. Each day before that counts down from 40 weeks. So someone with a due date of 8/18/21 who delivers on 8/17/31 would be 39 weeks and 6 days at delivery. my due date variable is formatted as %dM_d,_CY and my date of delivery variable is %tdNN/DD/CCYY

    thanks!

  • #2
    Code:
    gen weeks = floor((delivery-due+280)/7)
    gen days = mod(delivery-due+280,7)

    Comment


    • #3
      To the elegant answer from Ali Atia let me add some advice, since you're new to Stata.

      Stata's "date and time" variables are complicated and there is a lot to learn. If you have not already read the very detailed Chapter 24 (Working with dates and times) of the Stata User's Guide PDF, do so now. If you have, it's time for a refresher. After that, the help datetime documentation will usually be enough to point the way. You can't remember everything; even the most experienced users end up referring to the help datetime documentation or back to the manual for details. But at least you will get a good understanding of the basics and the underlying principles. An investment of time that will be amply repaid.

      All Stata manuals are included as PDFs in the Stata installation (since version 11) and are accessible from within Stata - for example, through the PDF Documentation section of Stata's Help menu.

      Comment

      Working...
      X