Title: Making a figure with Stata or Excel
1Making a figure with Stata or Excel
- Biostatistics 212
- Lecture 7
2Housekeeping
- Lab 5 issues
- Does your do file run? Make sure!
- Comment correctly
- Final Project questions?
- Print and hand in to Olivia or Allison (5th
floor) by the end of the day on 9/18/07 - 20 points docked for each 1 day late
- Email or call for help!
- PLEASE DO COURSE EVALUATIONS
- Youll get a link by email
3Final Project, grading
- Grading
- 80 (254 out of 317 possible) required to get a
Satisfactory score in the class - Also need to turn in all the Labs, even if they
are late
4Final Project, grading
- Final Project will count for 150/317 points
- Table 75 points
- 35 for do file log
- Housekeeping commands open/close log, use
dataset, etc - Analysis generate numbers in the Table
- 40 for Table itself
- Architecture
- Documentation
- Formatting/appearance
5Final Project, grading
- Final Project will count for 150/317 points
- Figure 75 points
- 35 for do file log
- Housekeeping commands open/close log, use
dataset, etc - Analysis
- 40 for Figure itself
- Design
- Documentation
- Formatting/appearance
6Final Project, grading
- Advice
- Find a classmate, give them your Table and
Figure, and get their critiques. - See if they can understand it without any verbal
explanation -
7Final Project, grading
- Extra credit
- 10 points extra credit and bragging rights for
the most artistic, creative, and clear figure
turned in
8Today...
- Figure basics
- Why make a figure?
- Types of figures
- Elements of a figure
- Steps in making a figure with Excel
- Steps in making a figure with Stata
- Demos
9Figures
- Figures are GOOD for presenting overall effects
- Figure are NOT GOOD for presenting specific
measurements
Browner, W. Publishing and Presenting Clinical
Research
10Figures
- A picture is worth a thousand words
11Figures
- A picture is worth a thousand words
How many words is this picture worth?
12Figures
- A picture is worth a thousand words
48 of CARDIA participants consume alcohol
moderately.
How many words is this picture worth?
Worth 7 words
13Figures
- A picture is worth a thousand words
How many words is this picture worth?
14Figures
- A picture is worth a thousand words
White Black Drinks/day n1935 n1727 0 40 5
7 0.1-0.9 39 26 1-1.9 13 9 2 8 8
How many words is this picture worth?
Worth 1 small table
15Figures
- A picture is worth a thousand words
-
How many words is this picture worth?
16Figures
- A picture is worth a thousand words
-
with CAC Abstainer Mod drinker Black
women .047 .036 White women .054 .049 Black
men .068 .132 White men .180 .167
How many words is this picture worth?
17Figures
- A picture is worth a thousand words
-
How many words is this picture worth?
Worth A thousand words?
18Figures
- A picture is worth a thousand words
-
How many words is this picture worth?
19Figures
- A picture is worth a thousand words
-
How many words is this picture worth?
Worth 968 data points lines gt 1000 words?
20Figures
- A picture is worth a thousand words
- Guidelines
- Figures should have a minimum of 4 data points
- Convey important effects, or interactions
Browner, W. Publishing and Presenting Clinical
Research
21Steps in making an Excel figure
- Sketch the Figure, with title
- Try several versions
- Point should be clear at a glance
- Requires some artistic vision
22Steps in making an Excel figure
- Make a dummy TABLE
- Contains the data for the figure
- Doesnt have to look nice
23Steps in making an Excel figure
- Make a dummy TABLE
- Contains the data for the figure
- Doesnt have to look nice
- Write a .do file to fill in the table
24Steps in making an Excel figure
- Make a dummy TABLE
- Contains the data for the figure
- Doesnt have to look nice
- Write a .do file to fill in the table
- Copy and paste from log file into the Table
25Steps in making an Excel figure
- Make a dummy TABLE
- Contains the data for the figure
- Doesnt have to look nice
- Write a .do file to fill in the table
- Copy and paste from log file into the Table
- Use the Chart Wizard to create the Figure
26Steps in making an Excel figure
- Make a dummy TABLE
- Contains the data for the figure
- Doesnt have to look nice
- Write a .do file to fill in the table
- Copy and paste from log file into the Table
- Use the Chart Wizard to create the Figure
- Format format format til it looks nice
27Stata vs. Excel for Figures
- Excel
- Flexible and intuitive point-and-click figures
- Easy to create and modify
- Flexible, more options, error bars, adjusted
estimates, etc - But
- Requires an extra step copy/pasting to Excel
- Harder to reproduce
- Much harder to do scatter plots
28Stata vs. Excel for Figures
- Stata
- Can create very customizable figures using 1
complex Stata command - Easy to recreate simple do file
- No error
- Scatter plots are MUCH easier with Stata
- But
- Harder to create the first time? - no point and
click - A little less flexible?
29Steps in making a Stata figure
30Steps in making a Stata figure
- Sketch the figure
- Write a do file
31Steps in making a Stata figure
- Sketch the figure
- Write a do file
- Compose the command using the dialog box
- Get the syntax down, multiple iterations
- Transfer to your do file and edit
32Steps in making a Stata figure
- Sketch the figure
- Write a do file
- Compose the command using the dialog box
- Get the syntax down, multiple iterations
- Transfer to your do file and edit
- Produce graph and edit more?
- Graph editor function new feature!
33Steps in making a Stata figure
- Sketch the figure
- Write a do file
- Compose the command using the dialog box
- Get the syntax down, multiple iterations
- Transfer to your do file and edit
- Produce graph and edit more?
- Graph editor function new feature!
- May need additional Stata commands for p-values,
figure legend, etc
34Pay attention to
- Formatting!
- Make it look nice and professional, but not gaudy
35Pay attention to
- Labeling!
- Your figure should be understandable by itself
- Include important p-values
36Pay attention to
- The Figure Legend!
- Title, explanations, extra p-values, etc
- Separate section in manuscript or at bottom of
page depends on journal
37Stata commands intro
- Pie charts
- graph pie, over(catvar)
- Bar graphs
- graph bar (mean) yvar1 yvar2, over(catvar1)
over(catvar2) asyvars - Box plots
- graph box contvar1 contvar2, over(catvar1)
over(catvar2) - Scatter plots
- twoway (graphtype yvar xvar) (graphtype yvar
xvar) - Scatter, line, connect, lowess, lfit, qfit, etc
38Demo
- Pie charts
- Bar charts
- Twoway plots
- Formatting options
39- twoway (scatter dfev1 cumpy10 if menthol11,
msymbol(plus) msize(small) mcolor(black)) /// - (scatter dfev1 cumpy10 if
menthol10, msymbol(circle_hollow)) /// - (line m cumpy10 if menthol11,
sort clcolor(black) clpat(dash) clwidth(thick))
/// - (line nm cumpy10 if menthol10,
sort clcolor(black) clpat(solid) clwidth(thick))
/// - , ytitle(Change in FEV1
(milliliters), size(large)) yscale(titlegap(5))
/// - xtitle(Pack-years of exposure to
tobacco, size(large)) /// - xscale(titlegap(3)) ///
- legend(order(1 "Menthol smokers"
2 "Non-menthol smokers" 3 "Menthol regression"
/// - 4
"Non-menthol regression")) /// - scheme(s1mono) ///
- graphregion(fcolor(none)
lcolor(none) ifcolor(none) ilcolor(none)) /// - plotregion(fcolor(none)
lcolor(none) ifcolor(none) ilcolor(none))
40- graph bar (mean) cac ///
- , over(modalc) ///
- over(racegender) ///
- asyvars ///
- ytitle(Prevalence of coronary
calcification) /// - title("Prevalence of coronary
calcification in moderate drinkers and
abstainers", /// - size(medium) span) ///
- subtitle("By race and gender",
size(medsmall))
41Summary figure tips
- Only use a Figure if
- There is an important message to convey
- The visual will be more compelling and clear
- Try using both Stata and Excel
- Stata will be harder at first, but often worth it
- Browner book, Stata book both helpful
- Document, label, and be creative
42Thats it!
- Thanks for your active participation in the
course.