Hello,
I would like to use a loop creating a lot of cross tables and export the results (Chi2...) to Excel. Therefor I set a new Excel sheet:
putexcel set "crosstabs.xlsx", sheet("cl_1a") replace
putexcel A1=("variable") B1=("label") C1=("Chi2") D1=("p (Chi)") E1=("Fisher exakt") F1=("Cramver V")
Now I'd like to lop through 540 variables and save the crosstab results to Excel, where I need the variable names in column A and the variable labels in column B, all other results following in the columns C to F. The loop beneath provides all I need exept the variable names and labels and of course the change in every row saving the results of each of the cross tabulation. Any idea how to manage that?
foreach x of varlist x1-x540 {
tabulate cl_1a `x', chi2 exact V
putexcel A2=
putexcel B2=
putexcel C2=(r(chi2))
putexcel D2=(r(p))
putexcel E2=(r(p_exact))
putexcel F2=(r(CramersV))
}
Best
-Nick
I would like to use a loop creating a lot of cross tables and export the results (Chi2...) to Excel. Therefor I set a new Excel sheet:
putexcel set "crosstabs.xlsx", sheet("cl_1a") replace
putexcel A1=("variable") B1=("label") C1=("Chi2") D1=("p (Chi)") E1=("Fisher exakt") F1=("Cramver V")
Now I'd like to lop through 540 variables and save the crosstab results to Excel, where I need the variable names in column A and the variable labels in column B, all other results following in the columns C to F. The loop beneath provides all I need exept the variable names and labels and of course the change in every row saving the results of each of the cross tabulation. Any idea how to manage that?
foreach x of varlist x1-x540 {
tabulate cl_1a `x', chi2 exact V
putexcel A2=
putexcel B2=
putexcel C2=(r(chi2))
putexcel D2=(r(p))
putexcel E2=(r(p_exact))
putexcel F2=(r(CramersV))
}
Best
-Nick
Comment