use low, clear
putexcel set low.xlsx, replace
putexcel A1 = "Analysis of birthweights", bold
putexcel A1:E1, border(bottom, thick) merge hcenter
putexcel A3 = "We have data on birthweights from Hosmer, "
putexcel A4 = "Lemeshow, and Sturdivant(2013, 24). "
putexcel A6 = "Summary statistics: Birth weights by age group"
putexcel A6:E6, merge border(bottom,double)
tabulate agegrp low, matcell(freq)
putexcel A9 = matrix(freq), rownames
putexcel A9="Teens" A10="20s" A11="30s" A12="40s"
putexcel D9 = formula(B9 + C9)
putexcel D10 = formula(B10 + C10)
putexcel D11 = formula(B11 + C11)
putexcel D12 = formula(B12 + C12)
putexcel A8="Age group" B8=">= 2500g" C8="< 2500g" D8="Total" A13="Total"
putexcel A8:D8, shrinkfit border(bottom) right
putexcel A12:D12, border(bottom)
putexcel B13 = formula(SUM(B9:B12))
putexcel C13 = formula(SUM(C9:C12))
putexcel D13 = formula(SUM(D9:D12))
putexcel A15 = "Regression results"
putexcel A15:B15, merge border(bottom,double)
regress bwt i.smoke age, cformat(%9.2f)
putexcel A16 = etable
putexcel F16:G16, merge
graph hbar bwt, over(ht) over(smoke) asyvars
graph export bweight.png, replace height(300)
putexcel I4 = image(bweight.png)
putexcel save
Export a Stata graph to Excel