Dear stataforum
I am trying to save effect sizes from multiple variables into excel or csv, and I am struggling to make my code save the data I am interested in.
I have tried to make example data that somehow resembles my own data set, except my own data set contains many more "TotalScore"s (and they are not random numbers)
Imaging I want to save Hedge'g and 95CI for all TotalScore_* in excel, with one row corresponding to each TotalScore_
With this code I only get 1 line in my excel, which is the last statistics (TotalScore8).
I would greatly appreciate any help and suggestions
I am using Stata 17 for PC
I am trying to save effect sizes from multiple variables into excel or csv, and I am struggling to make my code save the data I am interested in.
I have tried to make example data that somehow resembles my own data set, except my own data set contains many more "TotalScore"s (and they are not random numbers)
Imaging I want to save Hedge'g and 95CI for all TotalScore_* in excel, with one row corresponding to each TotalScore_
Code:
use https://www.stata-press.com/data/r17/depression ,clear /* Remake example data to resemble that a total of 5 outcome vars were measured on participants. Here they are random numbers, but lets pretend they are real measured outcome vars and we want to know how "sex" may affect each TotalScore_*. */ ren TotalScore TotalScore_5 gen TotalScore_6 = runiform(1,5) gen TotalScore_7 = runiform(100,200) gen TotalScore_8 = runiform(10,20) *Start preparing excel putexcel set "$EXCELDIR/TestTable", sheet("ES with CI") modify //perhaps insert your own local excel path here putexcel A1=("") B1=("Hedge's g") C1=("low 95CI") D1=("high 95CI") *Looping starts foreach var of varlist TotalScore_5-TotalScore_8 { di "`var'" esize twosample `var' , by(sex) scalar `var'_g= r(g) scalar `var'_l= r(lb_g) scalar `var'_u= r(ub_g) foreach x in 1/5 { local row = `x'+1 putexcel A`row'=("`var'") B`row'=(`var'_g) C`row'=(`var'_l) D`row'=(`var'_u) } }
I would greatly appreciate any help and suggestions
I am using Stata 17 for PC
Comment