Hello users, need advice to exporting tables to Excel using matrices.
I have run hundreds of crosstabs with chi-square tests (ta var1 var2, chi2) and exporting them through matrices. Matrix for each cross-tab has 3 columns (N, chi value, p-value). I want to export the result of a cross-tab only if the test is significant i.e. the p-val <=0.05. Please advise if there is a solution.
Below is the loop I have setup to export the values.
Both commands, matrix and putexcel do not support if conditions. However, it is important that i restrict the export only to significant results.
Please help!
I have run hundreds of crosstabs with chi-square tests (ta var1 var2, chi2) and exporting them through matrices. Matrix for each cross-tab has 3 columns (N, chi value, p-value). I want to export the result of a cross-tab only if the test is significant i.e. the p-val <=0.05. Please advise if there is a solution.
Below is the loop I have setup to export the values.
Code:
gl model q30a q30b q30c q30d q30e
foreach i in $model{
putexcel set "$path_output\Section 3 - Q24.xlsx", sheet("`i'") modify
clear matrix
matrix Table =J(12,3,.)
matrix rownames Table = q24a q24b q24c q24d
matrix colnames Table = N chisq p
foreach var of varlist q24a q24b q24c q24d {
ta `i' `var', chi2
matrix Table[rownumb(Table, "`var'"),1] = r(N)
matrix Table[rownumb(Table, "`var'"),2] = r(chi2)
matrix Table[rownumb(Table, "`var'"),3] = r(p)
}
putexcel A1= matrix(Table), names
}
Please help!

Comment