Quantcast
Channel: The Stata Blog - Latest Comments
Viewing all articles
Browse latest Browse all 1129

Re: Export tables to Excel

$
0
0

Hi Kevin,

I am using putexcel to tabulate a number of variables on a number of subsets of my data. Some of those subsets do not contain all potential values on certain variables. An easy example is a number of subsamples have males and females, while others others have only males. I am using code like that pasted below to do this within a macro across the different subsamples (districts), but the missing cells in the matrices cause my labels to be incorrect.

I am just wondering what you think the best solution would be here, whether it is tab2xl with the 'missing' option or if my code can be modified here. Thanks for your time!


levelsof district_name, local(districts)
foreach d of local districts {

tab sex, matcell(sexcounts)
matlist sexcounts
putexcel A4 = "Sex" ///
B4 = "Female" ///
B5 = "Male"
putexcel C4 = matrix(sexcounts), hcenter nformat(number_d2)
putexcel D4 = formula(=C4/`r(N)') ///
D5 = formula(=C5/`r(N)'), nformat(percent_d2)
}


Viewing all articles
Browse latest Browse all 1129

Trending Articles