Hello everyone,

Please I need help here on re-structuring my data (Nigeria Demographic and Health Survey) for survival analysis.

I'm trying to generate time of observation (duration in months) for each child from month of birth till the end of the study observation period in 2018, of which ran the syntax commands below:

*setting ending time of observation
s220bm //child's month of death
s220by //child's year of death
tab1 s220by s220bm
recode s220by (9998=.) //don't know (0.16%)
recode s220bm (97/98=.) //inconsistent (97) = 1%, don't know (98) = 13%

gen mth_death= s220by *12+s220bm //to generate month of death
tab mth_death
order mth_death, after(b7)

//Dec(12) 2018 is the end of the survey month
gen mth_end=.
replace mth_end=mth_death if mth_death!=.
replace mth_end=12 if mth_death==. //child is still alive
tab mth_end, missing
sort mth_end
order mth_end mth_death
*check the browser data file to make sure all is reasonable

gen yr_end=.
replace yr_end= s220by if s220by!=.
replace yr_end= 2018 if s220by==. //end of the survey year if child is still alive (will be censored)
order yr_end, after (mth_death)

tab1 mth_end yr_end, m

b1 //child's month of birth
b2 //child's year of birth

*generate time of observation (duration in months) for each child from month of birth till the end of the study observation period in 2018
replace b1=12 if b1==.
gen mths_birth= b2*12+b1
tab mths_birth
order mths_birth, after(yr_end)

gen mths_observe=yr_end*12+mth_end
tab mths_observe
order mths_observe, after(mths_birth)

gen dur=mths_observe-mths_birth+1
browse if dur==. //no missing variable
tab dur
order dur, after(mths_observe)




Dataex command of the variables created returned the output below:



Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(id mth_death mth_end yr_end mths_birth mths_observe dur)
24696 . 12 2018 24197 24228 32
25986 . 12 2018 24195 24228 34
  496 . 12 2018 24200 24228 29
 7642 . 12 2018 24197 24228 32
30776 . 12 2018 24189 24228 40
 5260 . 12 2018 24181 24228 48
 5966 . 12 2018 24209 24228 20
16389 . 12 2018 24197 24228 32
 2278 . 12 2018 24208 24228 21
10239 . 12 2018 24218 24228 11
22916 . 12 2018 24209 24228 20
19681 . 12 2018 24209 24228 20
15325 . 12 2018 24202 24228 27
12416 . 12 2018 24210 24228 19
25760 . 12 2018 24198 24228 31
20777 . 12 2018 24204 24228 25
24014 . 12 2018 24212 24228 17
32472 . 12 2018 24173 24228 56
 7727 . 12 2018 24187 24228 42
   17 . 12 2018 24220 24228  9
19211 . 12 2018 24170 24228 59
 8561 . 12 2018 24184 24228 45
32324 . 12 2018 24208 24228 21
20246 . 12 2018 24172 24228 57
 3222 . 12 2018 24166 24228 63
 3917 . 12 2018 24187 24228 42
 3838 . 12 2018 24220 24228  9
 2899 . 12 2018 24211 24228 18
32490 . 12 2018 24165 24228 64
 5342 . 12 2018 24202 24228 27
  854 . 12 2018 24199 24228 30
 5289 . 12 2018 24173 24228 56
32329 . 12 2018 24191 24228 38
31267 . 12 2018 24172 24228 57
11971 . 12 2018 24217 24228 12
 2560 . 12 2018 24181 24228 48
11991 . 12 2018 24172 24228 57
32672 . 12 2018 24216 24228 13
31303 . 12 2018 24171 24228 58
 5615 . 12 2018 24183 24228 46
31260 . 12 2018 24203 24228 26
  444 . 12 2018 24218 24228 11
31258 . 12 2018 24202 24228 27
29164 . 12 2018 24185 24228 44
 5369 . 12 2018 24214 24228 15
25160 . 12 2018 24185 24228 44
30031 . 12 2018 24168 24228 61
  955 . 12 2018 24176 24228 53
19429 . 12 2018 24174 24228 55
30973 . 12 2018 24217 24228 12
17152 . 12 2018 24196 24228 33
14551 . 12 2018 24212 24228 17
27428 . 12 2018 24225 24228  4
30139 . 12 2018 24205 24228 24
17610 . 12 2018 24194 24228 35
 7779 . 12 2018 24214 24228 15
31942 . 12 2018 24175 24228 54
10185 . 12 2018 24181 24228 48
 4431 . 12 2018 24190 24228 39
 9942 . 12 2018 24221 24228  8
15298 . 12 2018 24224 24228  5
31239 . 12 2018 24209 24228 20
12379 . 12 2018 24201 24228 28
 7364 . 12 2018 24186 24228 43
 7384 . 12 2018 24183 24228 46
19049 . 12 2018 24193 24228 36
11634 . 12 2018 24213 24228 16
  337 . 12 2018 24174 24228 55
28952 . 12 2018 24205 24228 24
16368 . 12 2018 24212 24228 17
  812 . 12 2018 24217 24228 12
10026 . 12 2018 24225 24228  4
20664 . 12 2018 24174 24228 55
31666 . 12 2018 24177 24228 52
 7855 . 12 2018 24172 24228 57
26979 . 12 2018 24185 24228 44
20907 . 12 2018 24220 24228  9
20642 . 12 2018 24215 24228 14
26260 . 12 2018 24214 24228 15
24653 . 12 2018 24182 24228 47
31487 . 12 2018 24217 24228 12
 5028 . 12 2018 24208 24228 21
13361 . 12 2018 24204 24228 25
30680 . 12 2018 24202 24228 27
32319 . 12 2018 24173 24228 56
31181 . 12 2018 24198 24228 31
 8549 . 12 2018 24170 24228 59
 8597 . 12 2018 24172 24228 57
 6333 . 12 2018 24215 24228 14
22702 . 12 2018 24169 24228 60
31210 . 12 2018 24197 24228 32
17347 . 12 2018 24204 24228 25
25702 . 12 2018 24170 24228 59
25797 . 12 2018 24166 24228 63
31206 . 12 2018 24180 24228 49
 1336 . 12 2018 24171 24228 58
31204 . 12 2018 24199 24228 30
 5881 . 12 2018 24221 24228  8
26365 . 12 2018 24202 24228 27
15413 . 12 2018 24178 24228 51
end
------------------ copy up to and including the previous line ------------------

Please am I on the right track before I stset?

Thank you