Hi, I'm very new to Stata and very stuck - would be really grateful for some help!
Here's my code:
matrix varsub_trans_matrix = J(5, 18, .)
matrix var_trans_matrix = J(45, 18, .)
foreach var of varlist vara varb varc va vb vc varx vary varz {
matrix list combo_matrix
Basically, I am trying to calculate ladder scalars for 5 different subgroups of 9 different variables and automatically fill a matrix with the R and p values calculated. I thought if I created some empty matrices and then vertically merged them, it might fill the empty ones, but it doesn't seem to have worked.
I'd be very grateful for your help!
Many thanks,
Liz
Here's my code:
matrix varsub_trans_matrix = J(5, 18, .)
matrix var_trans_matrix = J(45, 18, .)
foreach var of varlist vara varb varc va vb vc varx vary varz {
preserve}
drop if visit != 1
keep `var' subject subgroup
gen subgroup_ = subinstr(subgroup, " ", "_", .)
reshape wide `var' , i(subject) j(subgroup_) string
ds sub* , not
local var_subs `r(varlist)'
foreach var_sub in `var_subs' {
ladder `var_sub'
matrix `var_sub'_matrix = (r(ident), r(P_ident), r(square), r(P_square), r(cube), r(P_cube), r(sqrt), r(P_sqrt), r(inv), r(P_inv), r(invsq), r(P_invsq), r(invcube), r(P_invcube), r(invsqrt), r(P_invsqrt), r(log), r(P_log))
matrix list `var_sub'_matrix
matrix `var'_matrix = varsub_trans_matrix \ `var_sub'_matrix
}
restore
matrix combo_matrix = var_trans_matrix \ `var'_matrix
matrix list combo_matrix
matrix list combo_matrix
Basically, I am trying to calculate ladder scalars for 5 different subgroups of 9 different variables and automatically fill a matrix with the R and p values calculated. I thought if I created some empty matrices and then vertically merged them, it might fill the empty ones, but it doesn't seem to have worked.
I'd be very grateful for your help!
Many thanks,
Liz
Comment