Embedding Stata results
and graphs in
Excel, PDF, and Word
October 17, 2019
11:00 AM
Run this do-file
use low, clear
putdocx begin
putdocx textblock begin, style(Title)
Analysis of birthweights
putdocx textblock end
putdocx textblock begin
We have data on birthweights from Hosmer,
Lemeshow, and Sturdivant (2013, 24).
putdocx textblock end
graph hbar bwt, over(ht) over(smoke) asyvars ///
title(Baby birthweights)
graph export bweight.png, replace
putdocx image bweight.png, width(4)
regress bwt i.smoke age, noheader cformat(%9.2f)
putdocx table bweight = etable
putdocx save bwreport, replace
Run this do-file
use low, clear
putdocx begin
putdocx textblock begin, style(Title)
Analysis of birthweights
putdocx textblock end
putdocx textblock begin
We have data on birthweights from Hosmer,
Lemeshow, and Sturdivant (2013, 24).
putdocx textblock end
graph hbar bwt, over(ht) over(smoke) asyvars ///
title(Baby birthweights)
graph export bweight.png, replace
putdocx image bweight.png, width(4)
regress bwt i.smoke age, noheader cformat(%9.2f)
putdocx table bweight = etable
putdocx save bwreport, replace
Obtain this Word document
Run this do-file
use low, clear
putexcel set low.xlsx, replace
putexcel A1 = "Analysis of birthweights", bold
putexcel A3 = "We have data on birthweights from Hosmer, "
putexcel A4 = "Lemeshow, and Sturdivant(2013, 24). "
graph hbar bwt, over(ht) over(smoke) asyvars
graph export bweight.png, replace height(300)
putexcel A7 = image(bweight.png)
regress bwt i.smoke age, cformat(%9.2f)
putexcel A24 = etable
putexcel F24:G24, merge
putexcel save
Run this do-file
use low, clear
putexcel set low.xlsx, replace
putexcel A1 = "Analysis of birthweights", bold
putexcel A3 = "We have data on birthweights from Hosmer, "
putexcel A4 = "Lemeshow, and Sturdivant(2013, 24). "
graph hbar bwt, over(ht) over(smoke) asyvars
graph export bweight.png, replace height(300)
putexcel A7 = image(bweight.png)
regress bwt i.smoke age, cformat(%9.2f)
putexcel A24 = etable
putexcel F24:G24, merge
putexcel save
Obtain this Excel file
Overview
Create reproducible reports with formatted results
Summary statistics, estimation results, and graphs
Create reports in Word, Excel, and PDF format
putdocx, putexcel, and docx2pdf
Create a Word document with a header, footer, and page numbers
Append multiple Word documents, and interact Stata’s features with
Word’s features
Create automated reports
Overview
Create reproducible reports with formatted results
Summary statistics, estimation results, and graphs
Create reports in Word, Excel, and PDF format
putdocx, putexcel, and docx2pdf
Create a Word document with a header, footer, and page numbers
Append multiple Word documents, and interact Stata’s features with
Word’s features
Create automated reports
Data on birthweights
Analysis on birthweights
use low, clear
/* 1. How many observations in our dataset ? */
summarize bwt
/* 2. How many mothers in this dataset smoked during
pregnancy? */
count if smoke==1
/* 3. How many didn't? */
display `total'-r(N)
/* 4. How does birthweight vary across mothers' smoking
habits while pregnant, and their history of hypertension
? */
graph hbar bwt, over(ht) over(smoke) asyvars ///
title(Baby birthweights) ///
ytitle(Average birthweight (grams))
/* 5. Model birthweight as a function of smoking and
maternal age */
regress bwt i.smoke age, noheader cformat(%9.2f)
Analysis on birthweights
use low, clear
/* 1. How many observations in our dataset ? */
summarize bwt
local total = r(N)
/* 2. How many mothers in this dataset smoked during
pregnancy? */
count if smoke==1
/* 3. How many didn't? */
display `total'-r(N)
/* 4. How does birthweight vary across mothers' smoking
habits while pregnant, and their history of hypertension
? */
graph hbar bwt, over(ht) over(smoke) asyvars ///
title(Baby birthweights) ///
ytitle(Average birthweight (grams))
/* 5. Model birthweight as a function of smoking and
maternal age */
regress bwt i.smoke age, noheader cformat(%9.2f)
Analysis on birthweights
use low, clear
/* 1. How many observations in our dataset ? */
summarize bwt
local total = r(N)
/* 2. How many mothers in this dataset smoked during
pregnancy? */
count if smoke==1
/* 3. How many didn't? */
display `total'-r(N)
/* 4. How does birthweight vary across mothers' smoking
habits while pregnant, and their history of hypertension
? */
graph hbar bwt, over(ht) over(smoke) asyvars ///
title(Baby birthweights) ///
ytitle(Average birthweight (grams))
/* 5. Model birthweight as a function of smoking and
maternal age */
regress bwt i.smoke age, noheader cformat(%9.2f)
Analysis on birthweights
use low, clear
/* 1. How many observations in our dataset ? */
summarize bwt
local total = r(N)
/* 2. How many mothers in this dataset smoked during
pregnancy? */
count if smoke==1
/* 3. How many didn't? */
display `total'-r(N)
/* 4. How does birthweight vary across mothers' smoking
habits while pregnant, and their history of hypertension
? */
graph hbar bwt, over(ht) over(smoke) asyvars ///
title(Baby birthweights) ///
ytitle(Average birthweight (grams))
/* 5. Model birthweight as a function of smoking and
maternal age */
regress bwt i.smoke age, noheader cformat(%9.2f)
Analysis on birthweights
use low, clear
/* 1. How many observations in our dataset ? */
summarize bwt
local total = r(N)
/* 2. How many mothers in this dataset smoked during
pregnancy? */
count if smoke==1
/* 3. How many didn't? */
display `total'-r(N)
/* 4. How does birthweight vary across mothers' smoking
habits while pregnant, and their history of hypertension
? */
graph hbar bwt, over(ht) over(smoke) asyvars
/* 5. Model birthweight as a function of smoking and
maternal age */
regress bwt i.smoke age, noheader cformat(%9.2f)
Analysis on birthweights
use low, clear
/* 1. How many observations in our dataset ? */
summarize bwt
local total = r(N)
/* 2. How many mothers in this dataset smoked during
pregnancy? */
count if smoke==1
/* 3. How many didn't? */
display `total'-r(N)
/* 4. How does birthweight vary across mothers' smoking
habits while pregnant, and their history of hypertension
? */
graph hbar bwt, over(ht) over(smoke) asyvars
/* 5. Model birthweight as a function of smoking and
maternal age */
regress bwt i.smoke age, cformat(%9.2f)
Creating a Word document in Stata
putdocx begin
putdocx textblock begin
Hello my webinar friends.
putdocx textblock end
putdocx image emoji.png
putdocx table mytable = etable
putdocx save myfile
Creating a Word document in Stata
putdocx begin
putdocx paragraph
putdocx text (“ Hello my webinar friends.”)
putdocx text (“ How are you doing today? ”)
putdocx image emoji.png
your_estimation_command
putdocx table mytable = etable
putdocx save myfile
Creating a Word document in Stata
putdocx begin
putdocx textblock begin
Hello my webinar friends. How are you
doing today?
putdocx textblock end
putdocx image emoji.png
your_estimation_command
putdocx table mytable = etable
putdocx save myfile
Creating a Word document in Stata
putdocx begin
putdocx textblock begin
Hello my webinar friends. How are you
doing today?
putdocx textblock end
putdocx image emoji.png
your_estimation_command
putdocx table mytable = etable
putdocx save myfile
Creating a Word document in Stata
putdocx begin
putdocx textblock begin
Hello my webinar friends. How are you
doing today?
putdocx textblock end
putdocx image emoji.png
your_estimation_command
putdocx table mytable = etable
putdocx save myfile
Creating a Word document in Stata
putdocx begin
putdocx textblock begin
Hello my webinar friends. How are you
doing today?
putdocx textblock end
putdocx image emoji.png
your_estimation_command
putdocx table mytable = etable
putdocx save myfile
Analysis on birthweights
use low, clear
/* 1. How many observations in our dataset ? */
summarize bwt
local total = r(N)
/* 2. How many mothers in this dataset smoked during
pregnancy? */
count if smoke==1
/* 3. How many didn't? */
display `total'-r(N)
/* 4. How does birthweight vary across mothers' smoking
habits while pregnant, and their history of hypertension
? */
graph hbar bwt, over(ht) over(smoke) asyvars
/* 5. Model birthweight as a function of smoking and
maternal age */
regress bwt i.smoke age, cformat(%9.2f)
Creating a reproducible Word document
version 16
putdocx clear
use low, clear
putdocx begin
summarize bwt
local total = r(N)
putdocx textblock begin
We have the recorded weight for <<dd_docx_display: `total'>> babies with an
average birthweight of <<dd_docx_display: %5.2f r(mean)>> grams.
putdocx textblock end
putdocx textblock append
There are <<dd_docx_display: r(N)>> mothers who smoked during pregnancy,
and <<dd_docx_display: `total'-r(N)>> who did not.
putdocx textblock end
graph hbar bwt, over(ht) over(smoke) asyvars title(Baby birthweights) ///
ytitle(Average birthweight (grams)) ///
graph export bweight.png
putdocx image bweight.png
regress bwt i.smoke age, cformat(%9.2f)
putdocx table bweight = etable
putdocx textblock begin
We find that on average, infants whose mothers smoked tend to weigh less, and
the mother's age is not a statistically significant factor.
putdocx textblock end
putdocx save bwreport, replace
Create a document in memory
version 16
putdocx clear
use low, clear
putdocx begin
summarize bwt
local total = r(N)
putdocx textblock begin
We have the recorded weight for <<dd_docx_display: `total'>> babies with an
average birthweight of <<dd_docx_display: %5.2f r(mean)>> grams.
putdocx textblock end
putdocx textblock append
There are <<dd_docx_display: r(N)>> mothers who smoked during pregnancy,
and <<dd_docx_display: `total'-r(N)>> who did not.
putdocx textblock end
graph hbar bwt, over(ht) over(smoke) asyvars title(Baby birthweights) ///
ytitle(Average birthweight (grams)) ///
graph export bweight.png
putdocx image bweight.png
regress bwt i.smoke age, cformat(%9.2f)
putdocx table bweight = etable
putdocx textblock begin
We find that on average, infants whose mothers smoked tend to weigh less, and
the mother's age is not a statistically significant factor.
putdocx textblock end
Embed text and results in a Word document
version 16
putdocx clear
use low, clear
putdocx begin
summarize bwt
local total = r(N)
putdocx textblock begin
We have the recorded weight for <<dd_docx_display: `total'>> babies with an
average birthweight of <<dd_docx_display: %5.2f r(mean)>> grams.
putdocx textblock end
putdocx textblock append
There are <<dd_docx_display: r(N)>> mothers who smoked during pregnancy,
and <<dd_docx_display: `total'-r(N)>> who did not.
putdocx textblock end
graph hbar bwt, over(ht) over(smoke) asyvars title(Baby birthweights) ///
ytitle(Average birthweight (grams)) ///
graph export bweight.png
putdocx image bweight.png
regress bwt i.smoke age, cformat(%9.2f)
putdocx table bweight = etable
putdocx textblock begin
We find that on average, infants whose mothers smoked tend to weigh less, and
the mother's age is not a statistically significant factor.
putdocx textblock end
Embed text and results in a Word document
version 16
putdocx clear
use low, clear
putdocx begin
summarize bwt
local total = r(N)
putdocx textblock begin
We have the recorded weight for <<dd_docx_display: `total'>> babies with an
average birthweight of <<dd_docx_display: %5.2f r(mean)>> grams.
putdocx textblock end
putdocx textblock append
There are <<dd_docx_display: r(N)>> mothers who smoked during pregnancy,
and <<dd_docx_display: `total'-r(N)>> who did not.
putdocx textblock end
graph hbar bwt, over(ht) over(smoke) asyvars title(Baby birthweights) ///
ytitle(Average birthweight (grams)) ///
graph export bweight.png
putdocx image bweight.png
regress bwt i.smoke age, cformat(%9.2f)
putdocx table bweight = etable
putdocx textblock begin
We find that on average, infants whose mothers smoked tend to weigh less, and
the mother's age is not a statistically significant factor.
putdocx textblock end
Embed text and results in a Word document
version 16
putdocx clear
use low, clear
putdocx begin
summarize bwt
local total = r(N)
putdocx textblock begin
We have the recorded weight for <<dd_docx_display: `total'>> babies with an
average birthweight of <<dd_docx_display: %5.2f r(mean)>> grams.
putdocx textblock end
count if smoke==1
putdocx textblock append
There are <<dd_docx_display: r(N)>> mothers who smoked during pregnancy,
and <<dd_docx_display: `total'-r(N)>> who did not.
putdocx textblock end
graph hbar bwt, over(ht) over(smoke) asyvars title(Baby birthweights) ///
ytitle(Average birthweight (grams)) ///
graph export bweight.png
putdocx image bweight.png
regress bwt i.smoke age, cformat(%9.2f)
putdocx table bweight = etable
putdocx textblock begin
We find that on average, infants whose mothers smoked tend to weigh less, and
the mother's age is not a statistically significant factor.
putdocx textblock end
putdocx save bwreport, replace
Embed text and results in a Word document
version 16
putdocx clear
use low, clear
putdocx begin
summarize bwt
local total = r(N)
putdocx textblock begin
We have the recorded weight for <<dd_docx_display: `total'>> babies with an
average birthweight of <<dd_docx_display: %5.2f r(mean)>> grams.
putdocx textblock end
count if smoke==1
putdocx textblock append
There are <<dd_docx_display: r(N)>> mothers who smoked during pregnancy,
and <<dd_docx_display: `total'-r(N)>> who did not.
putdocx textblock end
graph hbar bwt, over(ht) over(smoke) asyvars title(Baby birthweights) ///
ytitle(Average birthweight (grams)) ///
graph export bweight.png
putdocx image bweight.png
regress bwt i.smoke age, cformat(%9.2f)
putdocx table bweight = etable
putdocx textblock begin
We find that on average, infants whose mothers smoked tend to weigh less, and
the mother's age is not a statistically significant factor.
putdocx textblock end
Embed a Stata graph in a Word document
version 16
putdocx clear
use low, clear
putdocx begin
summarize bwt
local total = r(N)
putdocx textblock begin
We have the recorded weight for <<dd_docx_display: `total'>> babies with an
average birthweight of <<dd_docx_display: %5.2f r(mean)>> grams.
putdocx textblock end
putdocx textblock append
There are <<dd_docx_display: r(N)>> mothers who smoked during pregnancy,
and <<dd_docx_display: `total'-r(N)>> who did not.
putdocx textblock end
graph hbar bwt, over(ht) over(smoke) asyvars
graph export bweight.png
putdocx image bweight.png
Embed a Stata graph in a Word document
version 16
putdocx clear
use low, clear
putdocx begin
summarize bwt
local total = r(N)
putdocx textblock begin
We have the recorded weight for <<dd_docx_display: `total'>> babies with an
average birthweight of <<dd_docx_display: %5.2f r(mean)>> grams.
putdocx textblock end
putdocx textblock append
There are <<dd_docx_display: r(N)>> mothers who smoked during pregnancy,
and <<dd_docx_display: `total'-r(N)>> who did not.
putdocx textblock end
graph hbar bwt, over(ht) over(smoke) asyvars
graph export bweight.png
putdocx image bweight.png
Embed a table of estimation results
version 16
putdocx clear
use low, clear
putdocx begin
summarize bwt
local total = r(N)
putdocx textblock begin
We have the recorded weight for <<dd_docx_display: `total'>> babies with an
average birthweight of <<dd_docx_display: %5.2f r(mean)>> grams.
putdocx textblock end
count if smoke==1
putdocx textblock append
There are <<dd_docx_display: r(N)>> mothers who smoked during pregnancy,
and <<dd_docx_display: `total'-r(N)>> who did not.
putdocx textblock end
graph hbar bwt, over(ht) over(smoke) asyvars
graph export bweight.png
putdocx image bweight.png
regress bwt i.smoke age, cformat(%9.2f)
putdocx table bweight = etable
putdocx textblock begin
We find that on average, infants whose mothers smoked tend to weigh less, and
the mother's age is not a statistically significant factor.
putdocx textblock end
Embed a table of estimation results
version 16
putdocx clear
use low, clear
putdocx begin
summarize bwt
local total = r(N)
putdocx textblock begin
We have the recorded weight for <<dd_docx_display: `total'>> babies with an
average birthweight of <<dd_docx_display: %5.2f r(mean)>> grams.
putdocx textblock end
count if smoke==1
putdocx textblock append
There are <<dd_docx_display: r(N)>> mothers who smoked during pregnancy,
and <<dd_docx_display: `total'-r(N)>> who did not.
putdocx textblock end
graph hbar bwt, over(ht) over(smoke) asyvars
graph export bweight.png
putdocx image bweight.png
regress bwt i.smoke age, cformat(%9.2f)
putdocx table bweight = etable
putdocx textblock begin
We find that on average, infants whose mothers smoked tend to weigh less, and
the mother's age is not a statistically significant factor.
putdocx textblock end
Add comments on the output
version 16
putdocx clear
use low, clear
putdocx begin
summarize bwt
local total = r(N)
putdocx textblock begin
We have the recorded weight for <<dd_docx_display: `total'>> babies with an
average birthweight of <<dd_docx_display: %5.2f r(mean)>> grams.
putdocx textblock end
count if smoke==1
putdocx textblock append
There are <<dd_docx_display: r(N)>> mothers who smoked during pregnancy,
and <<dd_docx_display: `total'-r(N)>> who did not.
putdocx textblock end
graph hbar bwt, over(ht) over(smoke) asyvars
graph export bweight.png
putdocx image bweight.png
regress bwt i.smoke age, cformat(%9.2f)
putdocx table bweight = etable
putdocx textblock begin
We find that on average, infants whose mothers smoked tend to weigh less, and
the mother's age is not a statistically significant factor.
putdocx textblock end
putdocx save bwreport, replace
Create a report in Word
version 16
putdocx clear
use low, clear
putdocx begin
summarize bwt
local total = r(N)
putdocx textblock begin
We have the recorded weight for <<dd_docx_display: `total'>> babies with an
average birthweight of <<dd_docx_display: %5.2f r(mean)>> grams.
putdocx textblock end
count if smoke==1
putdocx textblock append
There are <<dd_docx_display: r(N)>> mothers who smoked during pregnancy,
and <<dd_docx_display: `total'-r(N)>> who did not.
putdocx textblock end
graph hbar bwt, over(ht) over(smoke) asyvars
graph export bweight.png
putdocx image bweight.png
regress bwt i.smoke age, cformat(%9.2f)
putdocx table bweight = etable
putdocx textblock begin
We find that on average, infants whose mothers smoked tend to weigh less, and
the mother's age is not a statistically significant factor.
putdocx textblock end
putdocx save bwreport, replace
Create a report in Excel
Create a report in Excel
putexcel set myfile
putexcel A2 =Hello webinar friends.
putexcel A3 = `r(mean)’
putexcel A5 = image(emoji.png)
putexcel B7 = formula(Excel_formula)
your_estimation_command
putexcel A9 = etable
putexcel save
Create a report in Excel
putexcel set myfile
putexcel A2 =Hello webinar friends.
putexcel A3 = `r(mean)’
putexcel A5 = image(emoji.png)
putexcel B7 = formula(Excel_formula)
your_estimation_command
putexcel A9 = etable
putexcel save
Create a report in Excel
putexcel set myfile
putexcel A2 =Hello webinar friends.
putexcel A3 = `r(mean)’
putexcel A5 = image(emoji.png)
putexcel B7 = formula(Excel_formula)
your_estimation_command
putexcel A9 = etable
putexcel save
Create a report in Excel
putexcel set myfile
putexcel A2 =Hello webinar friends.
putexcel A3 = `r(mean)’
putexcel A5 = image(emoji.png)
putexcel B7 = formula(Excel_formula)
your_estimation_command
putexcel A9 = etable
putexcel save
Set an Excel workbook for export
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="20's" A11="30's" A12="40's"
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", border(bottom,double)
putexcel A15:B15, merge
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
Write expressions to an Excel workbook
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="20's" A11="30's" A12="40's"
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", border(bottom,double)
putexcel A15:B15, merge
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
Write expressions to an Excel workbook
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="20's" A11="30's" A12="40's"
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", border(bottom,double)
putexcel A15:B15, merge
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 matrix with summary statistics
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="20's" A11="30's" A12="40's"
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", border(bottom,double)
putexcel A15:B15, merge
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 matrix with summary statistics
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="20's" A11="30's" A12="40's"
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", border(bottom,double)
putexcel A15:B15, merge
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
Use Excel formulas with putexcel
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", border(bottom,double)
putexcel A15:B15, merge
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
Use Excel formulas with putexcel
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", border(bottom,double)
putexcel A15:B15, merge
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
Use Excel formulas with putexcel
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", border(bottom,double)
putexcel A15:B15, merge
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
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="20's" A11="30's" A12="40's"
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", border(bottom,double)
putexcel A15:B15, merge
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
Use Excel formulas with putexcel
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="20's" A11="30's" A12="40's"
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)))save
Use Excel formulas with putexcel
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="20's" A11="30's" A12="40's"
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)))save
Use Excel formulas with putexcel
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="20's" A11="30's" A12="40's"
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)
foreach x in B C D {
putexcel `x'13 = formula(SUM(`x'9:`x'12))
}
save
Use Excel formulas with putexcel
Export a table of estimation results
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
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
Create a report in Excel
Today we learned how to
Embed Stata results and graphs in Excel, Word, and PDF
Customize Word documents with footers, page numbers, and headings
Add hyperlinks in Word documents
Append multiple files
Generalize do-files for automated reporting
There is more you can do
Organize Word documents into sections, each with their own page layout
Format page numbers
Format blocks of text, and insert paragraph breaks
Create tables in Word documents from matrices and the dataset in memory
Nest tables and images within tables
Learn more about reporting in the Stata Reporting Reference Manual
Thank you!