Code:
foreach x of varlist var1-var6 { local RowVar = "`x'" tabulate `RowVar' , missing matcell(cellcounts) mata: st_matrix("total", colsum(st_matrix("cellcounts"))) putexcel set file.xlsx, sheet(`x') modify open putexcel A2="strongly agree" A3="agree" A4="neither agree nor disagree" A5="disagree" A6="strongy disagree" putexcel B1="`x'" local B2=string(cellcounts[1,1]/total[1,1],"%9.3f") putexcel B2=`B2' local B3=string(cellcounts[2,1]/total[1,1],"%9.3f") putexcel B3=`B3' local B4=string(cellcounts[3,1]/total[1,1],"%9.3f") putexcel B4=`B4' local B5=string(cellcounts[4,1]/total[1,1],"%9.3f") putexcel B5=`B5' local B6=string(cellcounts[5,1]/total[1,1],"%9.3f") putexcel B6=`B6' putexcel close }
0 Response to Building table with multiple variables using putexcel
Post a Comment