Announcement

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

  • Testing slopes and intercepts in multi group SEM

    I have an unbalanced panel and have performed a simple FIML SEM multigroup modeling exercise.

    Code:
    ********************************************************************************
    * SIMULATED DATA FOR MULTI-GROUP LATENT GROWTH CURVE MODEL
    ********************************************************************************
    
    clear all
    set seed 12345
    
    * Create 400 observations (200 per group)
    set obs 400
    gen id = _n
    
    * Create two groups (mode: 1=HD, 2=PD)
    gen mode = cond(_n <= 200, 1, 2)
    
    ********************************************************************************
    * SIMULATE LATENT GROWTH TRAJECTORIES
    ********************************************************************************
    
    * Group 1 (HD): Baseline ~15, slight increase over time
    * Group 2 (PD): Baseline ~16, slight decrease over time
    
    * Individual-level random effects
    gen intercept_i = rnormal(0, 2)
    gen slope_i = rnormal(0, 0.1)
    
    * Generate observed scores at each timepoint with measurement error
    * Group 1 (HD): Mean intercept = 15, Mean slope = 0.02
    * Group 2 (PD): Mean intercept = 16, Mean slope = -0.05
    
    gen RAWGH0 = cond(mode==1, 15, 16) + intercept_i + 0*slope_i + rnormal(0, 2)
    gen RAWGH6 = cond(mode==1, 15, 16) + intercept_i + 6*cond(mode==1, 0.02, -0.05) + 6*slope_i + rnormal(0, 2)
    gen RAWGH12 = cond(mode==1, 15, 16) + intercept_i + 12*cond(mode==1, 0.02, -0.05) + 12*slope_i + rnormal(0, 2)
    gen RAWGH18 = cond(mode==1, 15, 16) + intercept_i + 18*cond(mode==1, 0.02, -0.05) + 18*slope_i + rnormal(0, 2)
    
    * Add some missing data to make it realistic
    replace RAWGH6 = . if uniform() < 0.10
    replace RAWGH12 = . if uniform() < 0.15
    replace RAWGH18 = . if uniform() < 0.20
    
    * Clean up intermediate variables
    drop intercept_i slope_i
    
    * Label variables
    label variable id "Patient ID"
    label variable mode "Dialysis modality"
    label define mode_label 1 "HD" 2 "PD"
    label values mode mode_label
    label variable RAWGH0 "General Health at baseline"
    label variable RAWGH6 "General Health at 6 months"
    label variable RAWGH12 "General Health at 12 months"
    label variable RAWGH18 "General Health at 18 months"
    
    ********************************************************************************
    * DESCRIPTIVE STATISTICS
    ********************************************************************************
    
    tabulate mode
    summarize RAWGH0 RAWGH6 RAWGH12 RAWGH18
    
    bysort mode: summarize RAWGH0 RAWGH6 RAWGH12 RAWGH18
    
    ********************************************************************************
    * MULTI-GROUP LATENT GROWTH CURVE MODEL
    ********************************************************************************
    
    sem (Intercept@1 Slope@0 -> RAWGH0) ///
        (Intercept@1 Slope@6 -> RAWGH6) ///
        (Intercept@1 Slope@12 -> RAWGH12) ///
        (Intercept@1 Slope@18 -> RAWGH18), ///
        latent(Intercept Slope) ///
        method(mlmv) ///
        group(mode)
    
    estimates store model_multigroup
    
    * Display the parameter estimates
    matrix list e(b)
    
    * Show the model framework
    estat framework
    .

    QUESTION FOR STATALIST: How do I test whether the latent growth trajectories differ between groups?

    Specifically, I want to test:

    1. Do the mean intercepts differ between mode=1 and mode=2? (i.e., is baseline General Health different between groups?)

    2. Do the mean slopes differ between mode=1 and mode=2? (i.e., is the rate of change different between groups?)

    3. Joint test: Do trajectories differ overall?

    I can see from matrix list e(b) that there are parameters like:

    * mean(Intercept) 1.mode
    * mean(Intercept) 2.mode
    * mean(Slope) 1.mode
    * mean(Slope) 2.mode

    But I cannot figure out the correct test syntax. I've tried:

    Code:
    test [mean(Intercept)]1.mode = [mean(Intercept)]2.mode
    test mean(Intercept):1.mode = mean(Intercept):2.mode
    test _b[mean(Intercept):1.mode] = _b[mean(Intercept):2.mode]
    All give errors. What is the correct syntax?
Working...
X