I have been trying to obtain some descriptive statistics for my project, using one-way tabulations. To save time, I would want to export the results from Stata to excel automatically by using Putexcel loops. However, I am new to Stata, and have no idea how I could do so.
Here is an example of a Putexcel loop I have been trying to run (but in vain):
local workattitude "workattitude_1 workattitude_2 workattitude_3"
putexcel set "Section4_Workattitude_Tab", replace
quietly foreach var in `workattitude' {
tabulate `var' if survey_string == "2f", matcell(results)
putexcel set "Section4_Workattitude_Tab", sheet ("`var'") modify
putexcel A1=("Category") B1=("Freq") C1=("Percent")
putexcel A2=`r(names)'
putexcel B2=`r(freq)'
putexcel C2=`r(freq/r(N))'
}
My goal is to:
Could someone kindly help fix the problems, please?
Millions of thanks in advance!
Here is an example of a Putexcel loop I have been trying to run (but in vain):
local workattitude "workattitude_1 workattitude_2 workattitude_3"
putexcel set "Section4_Workattitude_Tab", replace
quietly foreach var in `workattitude' {
tabulate `var' if survey_string == "2f", matcell(results)
putexcel set "Section4_Workattitude_Tab", sheet ("`var'") modify
putexcel A1=("Category") B1=("Freq") C1=("Percent")
putexcel A2=`r(names)'
putexcel B2=`r(freq)'
putexcel C2=`r(freq/r(N))'
}
My goal is to:
- Export the category names, frequencies and percentages into different columns.
- Create column titles in the first row
- Export the table from tabulation for each variable into a separate spreadsheet in the same excel file
Could someone kindly help fix the problems, please?
Millions of thanks in advance!
Comment