I am aiming to do a simulation analysis to calculate the sample size for a stepped-wedged randomized control trial. The trial is designed such that there are repeated measures (Level 1) of a continuous outcome from individuals (Level 2) that are nested in clusters (Level 3). In a stepped-wedged context, each block represents a different time sequence during which a cluster will start the intervention (e.g. Block 1 clusters start the intervention at time 2). Below I have included a sample dataset that shows 1 individual out of 25 from each cluster.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str6 id float(Calendartime block clusters intervention continuousoutcome) "01C1" 1 1 1 0 67.21 "01C1" 2 1 1 1 2.777778 "01C1" 3 1 1 1 8.333333 "01C1" 4 1 1 1 5.555555 "01C1" 5 1 1 1 104.23 "01C2" 1 2 2 0 45.96 "01C2" 2 2 2 0 38.88889 "01C2" 3 2 2 1 47.22222 "01C2" 4 2 2 1 30.35 "01C2" 5 2 2 1 5.555555 "01C3" 1 3 3 0 67.21 "01C3" 2 3 3 0 2.777778 "01C3" 3 3 3 0 8.333333 "01C3" 4 3 3 1 5.555555 "01C3" 5 3 3 1 104.23 end label values block block label def block 1 "Block 1", modify label def block 2 "Block 2", modify label def block 3 "Block 3", modify label values clusters fht
How would I amend the following code to generate this data structure, noting that the continuousoutcome will be the sum of all the random effects parameters (u_3, u_2, error) defined below?
capture program drop swcrt
program define swcrt, rclass
version 15.1
preserve
clear
syntax,
drop _all
/*Generate simulated multi—level data*/
qui
set seed 12345
clear
set obs
qui gen cluster = _n
qui gen u_3 = rnormal(0,s)
expand
bysort cluster: qui gen individual= _n
qui gen u_2 = rnormal(0,s)
expand
bysort cluster individual: qui gen test = _n
qui gen error = rnormal(0,s) //Generate residual errors
qui gen y_swcrt = (intercept) + (intervention) + (time) + u_3 + u_2 + error //Generate outcome y
/*Fit multi-level model to simulated dataset*/
mixed y_swrt int time ||cluster: ||individual:, covariance(unstructured) reml dfmethod(kroger)
return scalar p = r(p)
drop _all
end swcrt
*Run the simulation iteratively
global srep 1000
simulate p=r(p), reps($srep) seed(12345) nodots : swcrt, ///
alpha(0.05) ///Add the other parameters///
gen p05 = p<0.05
sum p05 //Estimate of power
0 Response to Simulating multi-level data for a stepped-wedged design
Post a Comment