Announcement

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

  • How to track changes in morbidity status over time in Panel Data

    Hi everyone,
    I am working with panel data that consists of children surveyed over three waves: 3, 4, and 5.I am interested in how the health status of a child (morbid), a categorical variable that takes a value of 1 if the child has a chronic disease and 0 otherwise changes over time. I want to know how this variable varies with time by the child's stunting status (stunted); a categorical variable that takes a value of 1 if the child is stunted and 0 otherwise. Specifically, I want to know the proportion of children who were stunted in wave 3 and went on to develop/report having a chronic disease in waves 4 and 5, conditional on not having a chronic disease in wave 3. The idea is to establish whether there is a correlation between a child being stunted in a previous period and going on to report/develop a chronic disease in subsequent periods. Is there a code I can run to achieve this?

    My example data is as below:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long pid float(wave morbid stunted)
    401011 3 0 0
    401011 4 0 0
    401011 5 0 0
    401013 3 0 0
    401013 4 0 0
    401013 5 0 0
    401014 3 0 0
    401014 4 0 0
    401014 5 0 0
    401016 3 0 0
    401016 4 0 0
    401016 5 0 0
    401017 3 0 1
    401017 4 0 0
    401017 5 0 0
    401018 3 0 0
    401018 4 0 0
    401018 5 0 0
    401019 3 0 1
    401019 4 0 0
    401019 5 0 0
    401020 3 0 0
    401020 4 0 0
    401020 5 0 0
    401021 3 0 1
    401021 4 0 1
    401021 5 0 1
    401022 3 0 0
    401022 4 0 0
    401022 5 0 .
    401023 3 0 .
    401023 4 0 0
    401023 5 0 0
    401024 3 0 0
    401024 4 0 0
    401024 5 0 0
    401026 3 0 1
    401026 4 0 0
    401026 5 0 0
    401028 3 0 0
    401028 4 0 0
    401028 5 0 0
    401030 3 0 1
    401030 4 0 0
    401030 5 0 0
    401031 3 0 1
    401031 4 0 1
    401031 5 0 0
    401032 3 0 1
    401032 4 0 1
    401032 5 0 1
    401034 3 0 .
    401034 4 0 .
    401034 5 0 .
    401035 3 0 .
    401035 4 0 .
    401035 5 0 0
    401036 3 0 .
    401036 4 0 0
    401036 5 0 0
    401037 3 0 .
    401037 4 0 0
    401037 5 0 0
    401038 3 0 .
    401038 4 0 0
    401038 5 0 0
    401039 3 0 1
    401039 4 0 0
    401039 5 0 0
    401040 3 0 0
    401040 4 0 0
    401040 5 0 0
    401041 3 0 1
    401041 4 0 0
    401041 5 0 0
    401042 3 0 0
    401042 4 0 0
    401042 5 0 0
    401043 3 0 0
    401043 4 0 0
    401043 5 0 0
    401044 3 0 1
    401044 4 0 0
    401044 5 0 0
    401045 3 0 0
    401045 4 0 0
    401045 5 0 0
    401046 3 0 1
    401046 4 0 1
    401046 5 0 1
    401047 3 0 0
    401047 4 0 0
    401047 5 0 0
    401048 3 0 0
    401048 4 0 0
    401048 5 0 0
    401050 3 0 0
    401050 4 0 0
    401050 5 0 0
    401052 3 0 .
    401052 4 0 0
    401052 5 0 0
    401056 3 0 0
    401056 4 0 0
    401056 5 0 0
    401060 3 0 0
    401060 4 0 0
    401060 5 0 0
    401064 3 0 0
    401064 4 0 0
    401064 5 0 0
    401065 3 0 0
    401065 4 0 .
    401065 5 0 0
    401066 3 0 1
    401066 4 0 1
    401066 5 0 1
    401068 3 0 0
    401068 4 0 0
    401068 5 0 0
    401069 3 0 0
    401069 4 0 0
    401069 5 0 .
    401070 3 0 0
    401070 4 1 0
    401070 5 1 0
    401073 3 0 0
    401073 4 0 0
    401073 5 0 0
    401075 3 0 0
    401075 4 1 1
    401075 5 0 .
    401076 3 0 .
    401076 4 0 0
    401076 5 0 0
    401077 3 0 0
    401077 4 0 0
    401077 5 0 0
    401079 3 0 0
    401079 4 0 1
    401079 5 0 0
    401080 3 0 0
    401080 4 0 0
    401080 5 0 .
    401083 3 0 0
    401083 4 0 0
    401083 5 0 0
    401084 3 0 0
    401084 4 0 0
    401084 5 0 0
    401085 3 0 0
    401085 4 0 0
    401085 5 0 .
    401087 3 0 1
    401087 4 0 1
    401087 5 0 .
    401088 3 0 0
    401088 4 0 0
    401088 5 0 .
    401089 3 0 0
    401089 4 0 0
    401089 5 0 .
    401091 3 0 1
    401091 4 0 1
    401091 5 0 1
    401092 3 0 0
    401092 4 0 0
    401092 5 0 0
    401095 3 0 1
    401095 4 0 1
    401095 5 0 1
    401097 3 0 0
    401097 4 0 0
    401097 5 0 0
    401101 3 0 0
    401101 4 0 .
    401101 5 0 .
    401102 3 0 0
    401102 4 0 0
    401102 5 0 0
    401104 3 0 0
    401104 4 0 0
    401104 5 0 0
    401105 3 0 0
    401105 4 0 0
    401105 5 0 0
    401106 3 0 0
    401106 4 0 0
    401106 5 0 0
    401108 3 0 0
    401108 4 0 .
    401108 5 0 0
    401111 3 0 0
    401111 4 0 0
    401111 5 0 0
    401112 3 0 0
    401112 4 0 0
    401112 5 0 0
    401114 3 0 .
    401114 4 0 .
    end
    label var pid "Person identifier" 
    label var morbid "RECODE of morbidity_index"

  • #2
    In some ways this kind of question could be handled by a reshape to wide layout.

    Instead an old trick is to calculate a profile over waves for each variable as a string variable. See https://journals.sagepub.com/doi/pdf...36867X20909698 for a write-up.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long pid float(wave morbid stunted)
    401011 3 0 0
    401011 4 0 0
    401011 5 0 0
    401013 3 0 0
    401013 4 0 0
    401013 5 0 0
    401014 3 0 0
    401014 4 0 0
    401014 5 0 0
    401016 3 0 0
    401016 4 0 0
    401016 5 0 0
    401017 3 0 1
    401017 4 0 0
    401017 5 0 0
    401018 3 0 0
    401018 4 0 0
    401018 5 0 0
    401019 3 0 1
    401019 4 0 0
    401019 5 0 0
    401020 3 0 0
    401020 4 0 0
    401020 5 0 0
    401021 3 0 1
    401021 4 0 1
    401021 5 0 1
    401022 3 0 0
    401022 4 0 0
    401022 5 0 .
    401023 3 0 .
    401023 4 0 0
    401023 5 0 0
    401024 3 0 0
    401024 4 0 0
    401024 5 0 0
    401026 3 0 1
    401026 4 0 0
    401026 5 0 0
    401028 3 0 0
    401028 4 0 0
    401028 5 0 0
    401030 3 0 1
    401030 4 0 0
    401030 5 0 0
    401031 3 0 1
    401031 4 0 1
    401031 5 0 0
    401032 3 0 1
    401032 4 0 1
    401032 5 0 1
    401034 3 0 .
    401034 4 0 .
    401034 5 0 .
    401035 3 0 .
    401035 4 0 .
    401035 5 0 0
    401036 3 0 .
    401036 4 0 0
    401036 5 0 0
    401037 3 0 .
    401037 4 0 0
    401037 5 0 0
    401038 3 0 .
    401038 4 0 0
    401038 5 0 0
    401039 3 0 1
    401039 4 0 0
    401039 5 0 0
    401040 3 0 0
    401040 4 0 0
    401040 5 0 0
    401041 3 0 1
    401041 4 0 0
    401041 5 0 0
    401042 3 0 0
    401042 4 0 0
    401042 5 0 0
    401043 3 0 0
    401043 4 0 0
    401043 5 0 0
    401044 3 0 1
    401044 4 0 0
    401044 5 0 0
    401045 3 0 0
    401045 4 0 0
    401045 5 0 0
    401046 3 0 1
    401046 4 0 1
    401046 5 0 1
    401047 3 0 0
    401047 4 0 0
    401047 5 0 0
    401048 3 0 0
    401048 4 0 0
    401048 5 0 0
    401050 3 0 0
    401050 4 0 0
    401050 5 0 0
    401052 3 0 .
    401052 4 0 0
    401052 5 0 0
    401056 3 0 0
    401056 4 0 0
    401056 5 0 0
    401060 3 0 0
    401060 4 0 0
    401060 5 0 0
    401064 3 0 0
    401064 4 0 0
    401064 5 0 0
    401065 3 0 0
    401065 4 0 .
    401065 5 0 0
    401066 3 0 1
    401066 4 0 1
    401066 5 0 1
    401068 3 0 0
    401068 4 0 0
    401068 5 0 0
    401069 3 0 0
    401069 4 0 0
    401069 5 0 .
    401070 3 0 0
    401070 4 1 0
    401070 5 1 0
    401073 3 0 0
    401073 4 0 0
    401073 5 0 0
    401075 3 0 0
    401075 4 1 1
    401075 5 0 .
    401076 3 0 .
    401076 4 0 0
    401076 5 0 0
    401077 3 0 0
    401077 4 0 0
    401077 5 0 0
    401079 3 0 0
    401079 4 0 1
    401079 5 0 0
    401080 3 0 0
    401080 4 0 0
    401080 5 0 .
    401083 3 0 0
    401083 4 0 0
    401083 5 0 0
    401084 3 0 0
    401084 4 0 0
    401084 5 0 0
    401085 3 0 0
    401085 4 0 0
    401085 5 0 .
    401087 3 0 1
    401087 4 0 1
    401087 5 0 .
    401088 3 0 0
    401088 4 0 0
    401088 5 0 .
    401089 3 0 0
    401089 4 0 0
    401089 5 0 .
    401091 3 0 1
    401091 4 0 1
    401091 5 0 1
    401092 3 0 0
    401092 4 0 0
    401092 5 0 0
    401095 3 0 1
    401095 4 0 1
    401095 5 0 1
    401097 3 0 0
    401097 4 0 0
    401097 5 0 0
    401101 3 0 0
    401101 4 0 .
    401101 5 0 .
    401102 3 0 0
    401102 4 0 0
    401102 5 0 0
    401104 3 0 0
    401104 4 0 0
    401104 5 0 0
    401105 3 0 0
    401105 4 0 0
    401105 5 0 0
    401106 3 0 0
    401106 4 0 0
    401106 5 0 0
    401108 3 0 0
    401108 4 0 .
    401108 5 0 0
    401111 3 0 0
    401111 4 0 0
    401111 5 0 0
    401112 3 0 0
    401112 4 0 0
    401112 5 0 0
    401114 3 0 .
    401114 4 0 .
    end
    label var pid "Person identifier" 
    label var morbid "RECODE of morbidity_index"
    
    
    bysort pid (wave) : gen waves = strofreal(wave) if _n == 1 
    by pid : gen shistory = strofreal(stunted) if _n == 1 
    by pid : gen mhistory = strofreal(morbid) if _n == 1 
    
    by pid : replace waves = waves[_n-1] + strofreal(wave) if _n > 1
    by pid : replace shistory = shistory[_n-1] + strofreal(stunted) if _n > 1 
    by pid: replace mhistory = mhistory[_n-1] + strofreal(morbid) if _n > 1 
    
    
    list pid shistory mhistory if waves == "345"
    Now you can ask questions.

    Code:
    . list pid shistory mhistory if waves == "345" & strpos(substr(shistory, 2, 2), "1") & substr(mhistory, 1, 1) == "0"
    
         +------------------------------+
         |    pid   shistory   mhistory |
         |------------------------------|
     27. | 401021        111        000 |
     48. | 401031        110        000 |
     51. | 401032        111        000 |
     90. | 401046        111        000 |
    117. | 401066        111        000 |
         |------------------------------|
    132. | 401075        01.        010 |
    141. | 401079        010        000 |
    156. | 401087        11.        000 |
    165. | 401091        111        000 |
    171. | 401095        111        000 |
         +------------------------------+
    
    . count if waves == "345" & strpos(substr(shistory, 2, 2), "1") & substr(mhistory, 1 , 1) == "0"
      10

    Comment


    • #3
      To be fair, we can ask questions in terms of reshaped variables:

      Code:
      reshape wide morbid stunted, i(pid) j(wave)
      after which we have morbid3 ... morbid5 and stunted3 ... stunted5.

      Comment

      Working...
      X