I am using putexcel in Stata/SE 14.2 to compile results of a number of cross-tabulations. Essentially, I would like to have one tab produce an overall summary of a categorical frequency and then a number of additional tabs (~35, each corresponding to a subgroup) with the same categorical frequencies. The code seems to run fine and will generate anywhere from 2 to ~20 of the additional tabs before stating "file organism_frequency.xlsx could not be saved". The information that had been placed in the Excel sheet before the program quit is appearing as intended and with the correct values. I'm wondering if this is a technical issue related to saving and if yes, if there is anyway to simplify the code I am using to allow for this to be generated.
The dataset is structured as one string variable ("service") containing the relevant subgroups and 23 categorical variables containing a 1 if present and missing value if absent.
The code I am using is below:
Again, the code works as intended until it is unable to save the Excel file, but at varying numbers of iterations through the loop. Any information is appreciated.
Sam
The dataset is structured as one string variable ("service") containing the relevant subgroups and 23 categorical variables containing a 1 if present and missing value if absent.
The code I am using is below:
Code:
local orgs achromobacter acinetobacter bacillus candida citrobacter /// corynebacterium ecoli efaecalis efaecium enterobacter groupbstrep kpneumo /// other pseudo proteus rothia saureus sepi smalto smitis spneumo staphspp strepspp afb putexcel set organism_frequency.xlsx, sheet(Overall) replace putexcel A1 = "Organism" putexcel B1 = "Count" local n : word count `orgs' forvalues i = 1/`n' { local a : word `i' of `orgs' local b : variable label `a' tab `a' local c `r(N)' local d = `i'+1 putexcel A`d' = "`b'" putexcel B`d' = `c' } levelsof service, local(dept) foreach service in `dept' { putexcel set organism_frequency.xlsx, sheet("`service'") modify putexcel A1 = "Organism" putexcel B1 = "Count" local n : word count `orgs' forvalues i = 1/`n' { local a : word `i' of `orgs' local b : variable label `a' tab `a' if service=="`service'" local c `r(N)' local d = `i'+1 putexcel A`d' = "`b'" putexcel B`d' = `c' } }
Sam
Comment