Announcement

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

  • Mean exposure throughout pregnancy

    Hello, i would like to calculate a mean of the variable exposure for each woman during a whole pregnancy, here between 2 dates (Dateconception and Datebirth). The exposure measurement corresponds to the value measured on the day of Datebirth. The data is centered around Datebirth, so i presume i would need to transform to long format with events conception & birth with the daily values of exposure.
    Could anyone help me figure this out? i have pasted a dataex sample of the main variables child ID exposure level date of conception and date of birth.
    thank you
    Sincerely
    Mathieu



    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str5 ID double Exposure float(Datebirth Dateconception)
    "62316"    8 22281 22008
    "62317"    8 22281 22015
    "62318"    8 22281 22015
    "62321"    8 22281 22008
    "62327"    8 22281 22015
    "62326"    8 22281 22008
    "62328"    8 22281 22113
    "62329"    8 22281 22022
    "62334"  8.6 22282 22016
    "62340"  8.6 22282 22009
    "62344"  8.6 22282 22009
    "62346"  8.6 22282 22009
    "62349" 10.6 22283 22024
    "62348" 10.6 22283 21989
    "62573" 10.6 22283 22010
    "62352" 10.6 22283 22010
    "62369" 10.6 22283 22017
    "62371" 10.6 22283 21996
    "62381" 13.3 22284 22004
    "62392" 13.3 22284 22102
    "62395" 13.3 22284 22018
    "62393" 13.3 22284 21997
    "62405"  8.3 22285 22026
    "62412"  8.3 22285 22012
    "62414" 17.1 22286 22013
    "62421" 17.1 22286 22076
    "62420" 17.1 22286 22020
    "62427" 17.1 22286 22055
    "62429" 17.1 22286 22006
    "62433"  8.8 22287 22014
    end
    format %td Datebirth
    format %td Dateconception

  • #2
    Mathieu:
    I'm not clear with what you're after.
    I guess you meant you want the mean on exposure calculated based on the overall observations included in your data excerpt.
    If that's your goal, you may want to consider -mean- function available from -egen-.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      hello, i have tried egen but it is logically wrong
      by ID, sort : egen float meanexp = mean(Exposure) if Datebirth>(Datebirth-Dateconception)
      what i want to achieve is, for each ID, to have a mean that integrates all exposure measurements from begining to end of pregnancy. so most women will have a different number of measurements used to calculate the mean because their pregnancies have different lengths. the daily exposure measurement is environmental and applies to all women. with seasons it varies so if a women starts pregnancy in first second third or fourth quarter the average of exposure during her pregnancy will change.

      i hope it i am clearer
      sincerely

      Comment


      • #4
        Mathieu:
        the following toy-example includes two waves of data for each -ID- (BTW; your previous excerpt inlcuded one wave of data only and was inconsistent with your research goal. That's why I was unclear with what you were after).
        I do hope that what follows is what you want(ed):
        Code:
        . input str5 ID double Exposure float(Datebirth Dateconception)
        
                    ID    Exposure  Datebirth  Datecon~n
          1. "62316"    8 22281 22008
          2. "62317"    8 22281 22015
          3. "62318"    8 22281 22015
          4. "62321"    8 22281 22008
          5. "62327"    8 22281 22015
          6. "62326"    8 22281 22008
          7. "62328"    8 22281 22113
          8. "62329"    8 22281 22022
          9. "62334"  8.6 22282 22016
         10. "62340"  8.6 22282 22009
         11. "62344"  8.6 22282 22009
         12. "62346"  8.6 22282 22009
         13. "62349" 10.6 22283 22024
         14. "62348" 10.6 22283 21989
         15. "62573" 10.6 22283 22010
         16. "62352" 10.6 22283 22010
         17. "62369" 10.6 22283 22017
         18. "62371" 10.6 22283 21996
         19. "62381" 13.3 22284 22004
         20. "62392" 13.3 22284 22102
         21. "62395" 13.3 22284 22018
         22. "62393" 13.3 22284 21997
         23. "62405"  8.3 22285 22026
         24. "62412"  8.3 22285 22012
         25. "62414" 17.1 22286 22013
         26. "62421" 17.1 22286 22076
         27. "62420" 17.1 22286 22020
         28. "62427" 17.1 22286 22055
         29. "62429" 17.1 22286 22006
         30. "62433"  8.8 22287 22014
         31. end
        
        . format %td Datebirth
        
        . format %td Dateconception
        
        . expand 2
        
        . bysort ID: replace Exposure=Exposure+3 if _n==2
        
        
        . g wanted=Datebirth-Dateconception
        
        . bysort ID: egen float meanexp = mean(Exposure) if Datebirth>(wanted)
        
        .
        Please note that this is a panel dataset with two waves of data per ID.
        If you want to analyse it, see -xt- commands.
        Last edited by Carlo Lazzaro; 10 Dec 2022, 09:09.
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment


        • #5
          Dear Carlo, thank you so much i will try it.
          sincerely
          mathieu

          Comment


          • #6
            hello, unfortunately it does not work.
            i am not sure i understand what expand2 and changing exposure do.
            sincerely
            mathieu

            Comment

            Working...
            X