NOTE: MLwiN V2 macro for setting up full model (duration + covariates) NOTE: Data are in discrete-time format, with 1 record per 6-month interval NOTE: WOMAN and EPISODE are unique identifiers NOTE: DUR is duration of episode in 6-month intervals (time-varying). ATRISK is number of NOTE: months in 6-month interval that woman was at risk of an event. DURSQ is DUR^2. NOTE: DUR0_5-DUR36 are dummy variables for DUR after grouping (see Table 3 for NOTE: groupings. STATE is state identifier (1=use, 2=non-use). NOTE: Y is the multinomial response. For STATE=1: 1=continue use, 2=method switch, NOTE: 3=discontinue. For STATE=2: 1=continue non-use, 2=transition to use. NOTE: All other variables are covariates (see Table 1 for codes). M1-M4 are method dummies. NOTE: BIRTH=1 if episode of non-use follows a live birth, 0=other. URBAN=1 for urban, 0=rural. NOTE: EDUC2 and EDUC3 are dummies for education, AGE2 and AGE3 are dummies for age. NOTE: SOCIO2 and SOCIO3 are dummies for socio-economic status. NOTE: Read in data and name columns. dinp c1-c24 multi.txt name c1 'woman' c2 'episode' c3 'dur' c4 'atrisk' name c5 'dursq' c6 'dur0_5' c7 'dur6_11' c8 'dur12_23' c9 'dur24_35' name c10 'dur36' c11 'state' name c12 'y' c13 'm1' c14 'm2' c15 'm3' c16 'm4' c17 'birth' name c18 'urban' c19 'educ2' c20 'educ3' c21 'age2' c22 'age3' name c23 'socio2' c24 'socio3' NOTE: Create STATE dummies. name c25 's1' c26 's2' calc c25=('state'==1) calc c26=1-c25 NOTE: Create unique ID for each observation. code 109666 1 1 c27 name c27 'lev2id' NOTE: Create interactions between state 1 dummy and duration+covariates. calc c30='s1'*'dur6_11' calc c31='s1'*'dur12_23' calc c32='s1'*'dur24_35' calc c33='s1'*'dur36' calc c34='s1'*'m2' calc c35='s1'*'m3' calc c36='s1'*'m4' calc c37='s1'*'age2' calc c38='s1'*'age3' calc c39='s1'*'urban' calc c40='s1'*'educ2' calc c41='s1'*'educ3' calc c42='s1'*'socio2' calc c43='s1'*'socio3' name c30 's1_d6-11' c31 's1_d12-23' c32 's1_d24-35' c33 's1_d36' name c34 's1_m2' c35 's1_m3' c36 's1_m4' name c37 's1_age2' c38 's1_age3' c39 's1_urb' c40 's1_ed2' c41 's1_ed3' name c42 's1_soc2' c43 's1_soc3' NOTE: Create interactions between state 2 dummy and duration+covariates. calc c44='s2'*'dur' calc c45='s2'*'dursq' calc c46='s2'*'birth' calc c47='s2'*'dur'*'birth' calc c48='s2'*'dursq'*'birth' calc c49='s2'*'age2' calc c50='s2'*'age3' calc c51='s2'*'urban' calc c52='s2'*'educ2' calc c53='s2'*'educ3' calc c54='s2'*'socio2' calc c55='s2'*'socio3' name c44 's2_dur' C45 's2_dursq' name c46 's2_birth' c47 's2_d-bir' c48 's2_dsq-bir' c49 's2_age2' name c50 's2_age3' c51 's2_urb' c52 's2_ed2' c53 's2_ed3' name c54 's2_soc2' c55 's2_soc3' NOTE: Repeat each value in ATRISK twice. (The values of other variables will be NOTE: repeated automatically when the multinomial model is specified.) repe 2 'atrisk' c56 name c56 'atrisk_long' NOTE: Delete any variables that are no longer needed and remove empty columns. erase c3-c11 c17-c24 move NOTE: Declare multinomial response catn 1 'y' 1 'y1' 2 'y2' 3 'y3' mnom 0 'y' c38 c39 1 NOTE: Each multinomial response converted to 2 binary responses, stored in RESP. NOTE: For STATE=2 we only need 1 binary response; the 2nd binary response will be deleted later. NOTE: RESP_IND indexes the responses. name c38 'resp' c39 'resp_ind' NOTE: Divide by ATRISK to obtain proportion of each type of event within 6-month interval. calc c38=c38/'atrisk_long' resp c38 NOTE: Declare multilevel structure. Observation level (time interval) specified as level 2; NOTE: level 1 used to define multivariate structure. iden 1 'resp_ind' 2 'lev2id' 3 'woman' NOTE: Add covariates. The following variables are added to all equations. addt 's1' addt 's1_d6-11' addt 's1_d12-23' addt 's1_d24-35' addt 's1_d36' addt 's1_m2' addt 's1_m3' addt 's1_m4' addt 's1_age2' addt 's1_age3' addt 's1_urb' addt 's1_ed2' addt 's1_ed3' addt 's1_soc2' addt 's1_soc3' addt 's2' NOTE: The following are added only to the equation for transitions from non-use (STATE 2). rpat 1 0 addt 's2_dur' addt 's2_dursq' addt 's2_birth' addt 's2_d-bir' addt 's2_dsq-bir' addt 's2_age2' addt 's2_age3' addt 's2_urb' addt 's2_ed2' addt 's2_ed3' addt 's2_soc2' addt 's2_soc3' NOTE: For STATE=2, delete 2nd record; only 1 binary response needed for this STATE. calc c87=('resp_ind'==3)*('s2.y3'==1) omit 1 c87 c37-c39 c41-c86 c87 c37-c39 c41-c86 calc c88='atrisk_long' name c88 'denom' NOTE: Remove S2.Y3 from fixed part of model (Y cannot equal 3 for STATE=2). fpar 0 's2.y3' NOTE: Specify random part of the model; random intercepts for each transition. setv 3 's1.y2' 's1.y3' 's2.y2' NOTE: Remove covariances. These are added in when model with variances only has been estimated. NOTE: 1st order MQL estimation used by default. After convergence, switch to MCMC. clre 3 's1.y2' 's1.y3' 's1.y2' 's2.y2' 's1.y3' 's2.y2'