1 / 55

Making Tables and Figures with Stata

Making Tables and Figures with Stata. Biostatistics 212 Lecture 6. Housekeeping. Brackets indicate optional parts of a command (usually!) use vs. insheet Low p-value for heterogeneity ≠ important interaction “The strata never lie” Final projects Read 1-page directions closely. Today.

kevyn
Download Presentation

Making Tables and Figures with Stata

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Making Tables and Figures with Stata Biostatistics 212 Lecture 6

  2. Housekeeping • Brackets indicate optional parts of a command (usually!) • use vs. insheet • Low p-value for heterogeneity ≠ important interaction • “The strata never lie” • Final projects • Read 1-page directions closely

  3. Today • Organizing your Stata files • Making a table • Making a figure

  4. Today • Organizing your Stata files • Making a table  Lab practice = Final Project • Making a figure  Lab practice = Lab 6

  5. Organizing your Stata files • Pitfalls • Proliferating dataset • Can’t remember what you did • Can’t remember why you did it • Can’t easily redo with new data

  6. Organizing your Stata files My system (it’s not perfect) • Import data into Stata • Using a Stata command (e.g., insheet or import) within a do file • Using other method (e.g., StatTransfer?) outside a do file, then SAVE the “raw” Stata file immediately 2) Write a do file that “cleans” your data, and saves it as a new clean dataset 3) Write do files for each component of your analysis

  7. My organizational scheme Raw data

  8. My organizational scheme Raw data Pre-process Raw data.csv

  9. My organizational scheme Raw data Pre-process Raw data.csv In Stata

  10. My organizational scheme Raw data Pre-process Raw data.csv Clean data.dta In Stata Data prep.do Data prep.log

  11. My organizational scheme Raw data Pre-process Raw data.csv Clean data.dta Table 1.log In Stata Data prep.do Data prep.log Table 1.do

  12. My organizational scheme Raw data Table 1.xls Pre-process Cut and paste Raw data.csv Clean data.dta Table 1.log In Stata Data prep.do Data prep.log Table 1.do

  13. My organizational scheme Table 1.doc Raw data Cut and paste Table 1.xls Pre-process Cut and paste Raw data.csv Clean data.dta Table 1.log In Stata Data prep.do Data prep.log Table 1.do

  14. My organizational scheme Table 1.doc Table 2.doc Raw data Cut and paste Table 1.xls Table 2.xls Pre-process Cut and paste Raw data.csv Clean data.dta Table 1.log Table 2.log In Stata Data prep.do Data prep.log Table 1.do Table 2.do

  15. Organizing your Stata files • You will end up with: • 1 or 2 Stata datasets • Data, from Excel.dta (only if you import outside your do file) • Data.dta • 1 do file used for cleaning • Data prep.do • 1 do file to create each Table and Figure • Table 1.do, Figure 1.do, Text data.do, etc • Matching log files (with the same names) for each do file • Data prep.log, Table 1.log, Figure 2.log, Text data.log, etc

  16. Organizing your Stata files • Put them all in one folder called, “Stata files”, sort by file type. • Example

  17. Any questions? Table 1.doc Table 2.doc Raw data Cut and paste Table 1.xls Table 2.xls Pre-process Cut and paste Raw data.csv Clean data.dta Table 1.log Table 2.log In Stata Data prep.do Data prep.log Table 1.do Table 2.do

  18. My organizational scheme Table 1.doc Table 2.doc Raw data Cut and paste Table 1.xls Table 2.xls Pre-process Lecture 3 Cut and paste Raw data.csv Clean data.dta Table 1.log Table 2.log In Stata Data prep.do Data prep.log Table 1.do Table 2.do

  19. My organizational scheme Table 1.doc Table 2.doc Raw data Cut and paste Table 1.xls Table 2.xls Pre-process Lecture 3 Lecture 5 Cut and paste Raw data.csv Clean data.dta Table 1.log Table 2.log In Stata Data prep.do Data prep.log Table 1.do Table 2.do

  20. Lecture 7 My organizational scheme Table 1.doc Table 2.doc Raw data Cut and paste Table 1.xls Table 2.xls Pre-process Lecture 3 Lecture 5 Cut and paste Raw data.csv Clean data.dta Table 1.log Table 2.log In Stata Data prep.do Data prep.log Table 1.do Table 2.do

  21. Tables • Two main purposes • Present the facts in a compact format • Provide side-by-side comparisons • Six main components: • Data • Title, row heading, column headings • Row names • Footnotes Browner, W. Publishing and Presenting Clinical Research

  22. 5 Steps to Making a Table • Step 1: Decide what the Table will be about • Sketch it out on paper • Title, column headings, etc

  23. 5 Steps to Making a Table • Step 2: Make the dummy table • Excel or Word • Makes you specify what you actually want! • Row headings • Decide on category cut-offs, labels • Decide on reference categories for regression, etc • Footnote liberally • Leave data cells blank

  24. 5 Steps to Making a Table • Step 3: Write a do file that will produce each number you need • Iterative process, as you know

  25. 5 Steps to Making a Table • Step 4: Copy and Paste the data in • Copy and Paste each number, or • “Copy Table” (under the “Edit” menu) • http://www.stata.com/support/faqs/data/copytable.html • Minimize manual retyping, rounding • Use Excel to calculate and round for you

  26. 5 Steps to Making a Table • Step 5: Format it so it looks nice • Standard, plain style – usually: • Horizontal lines, not vertical • Double-spaced • Footnotes - *, †, ‡, §, ║, ¶ (or a,b,c,d,…) • Create a template for yourself

  27. Word vs. Excel for Tables • Stata  Word • Fewer steps, fewer files • But… • Can’t cut and paste full tables • Doesn’t do any calculations for you • Formatting can become “corrupted”

  28. Word vs. Excel for Tables • Stata  Excel  Word • Can cut and paste values or whole tables • Set rounding, do calculations easily • Formatting easier? • Copy and Paste into Word (extra step)

  29. Demo • Table 1 for “Moderate drinking and coronary calcium in young adults: The CARDIA Study” • Basic content • Sketch • Generate numbers in Stata • Copy and paste into Word • Show final table • Demonstrate pasting a full table into Excel

  30. Figures • When use a figure? • Making a figure with Excel • Making a figure with Stata

  31. When use a figure? • When a graphical display of information more effectively conveys the intended message than words. • “A picture is worth a thousand words”

  32. Figures • “A picture is worth a thousand words” How many words is this picture worth?

  33. Figures • “A picture is worth a thousand words” 48% of CARDIA participants consume alcohol moderately. How many words is this picture worth? Worth = 7 words

  34. Figures • “A picture is worth a thousand words” How many words is this picture worth?

  35. Figures • “A picture is worth a thousand words” White Black Drinks/day n=1935 n=1727 0 40% 57% 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? (and avoid pie charts in general…)

  36. Figures • “A picture is worth a thousand words” How many words is this picture worth?

  37. Figures • “A picture is worth a thousand words” Proportion 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? Can you see the interaction in this table without a figure? (Figures are good for illustrating interactions)

  38. Figures • “A picture is worth a thousand words” How many words is this picture worth?

  39. Figures • “A picture is worth a thousand words” How many words is this picture worth? Worth = 968 data points? Nice to show actual data points along with main effect, if possible!

  40. Making a figure • With Excel • First make a TABLE in Excel! • Use Stata to generate numbers for the table • Create a figure from the Table using Excel tools • With Stata • Use Stata commands to create the figure directly

  41. Steps in making an Excel figure Sketch your figure Make a dummy TABLE Write a .do file to fill in the table Copy and paste from the log file or the results window into the Table Use the Chart Wizard to create the Figure Format, format, format until it looks nice

  42. Example • Figure 2 from Lipids paper

  43. Steps in making an Excel figure Sketch your figure Make a dummy TABLE Write a .do file to fill in the table Copy and paste from the log file or the results window into the Table Use the Chart Wizard to create the Figure Format, format, format until it looks nice

  44. Steps in making a Stata figure Sketch your figure Make a dummy TABLE Write a .do file with a graph command Copy and paste from the log file or the results window into the Table Use the Chart Wizard to create the Figure Format, format, format until it looks nice

  45. Pay attention to… • Formatting • Make it look nice and professional, but not gaudy • Black and white, usually • The time-consuming part of making a figure is usually related to formatting.

  46. Pay attention to… • Labeling • Your figure should be understandable by itself, without the rest of the manuscript • All axes should be labeled. • Include important p-values

  47. Pay attention to… • The Figure Legend • Title, explanations, extra p-values, etc • Separate section in manuscript or at bottom of page – depends on journal

  48. Stata vs. Excel for Figures • Excel • Flexible and intuitive point-and-click figures • Easy to create and modify • Flexible, more options, error bars, adjusted estimates, good for bar graphs, etc • But… • Requires an extra step – copy/pasting to Excel • Harder to reproduce • Much harder to do scatter plots

  49. Stata 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? • Difficult to format: Graphic Editor helps address this

More Related