#
1#
foreach v in sppb_total pfs_reverse pfsm_reverse koos_pain koos_sym koos_rec koos_func koos_qual {
// Calculate SD for each variable at Baseline_A
egen temp = sd(`v') if Visit == "1.Baseline_A"
egen sd_base_`v' = min(temp)
drop temp
// Calculate mean for each variable at Baseline_A
egen temp = mean(`v') if Visit == "1.Baseline_A"
egen mean_base_`v' = min(temp)
drop temp
}
foreach v in sppb_total pfs_reverse pfsm_reverse koos_pain koos_sym koos_rec koos_func koos_qual {
// Sort by record_id and Visit, then generate change score
sort record_id Visit
by record_id: gen change_`v' = ((`v'-`v'[1]) / sd_base_`v')
}
// Standardize variables
foreach v in sppb_total pfs_reverse pfsm_reverse koos_pain koos_sym koos_rec koos_func koos_qual {
gen std_`v' = (`v'-mean_base_`v') / sd_base_`v'
}
2#
Can’t share the data to test this code for issues of privacy
Simulating the underlying hierarchical data might help overcome this
Let’s discuss the underlying structure to aid simulation