Organizing a project, making a table Biostatistics 212 Lecture 7.

30
Organizing a project, making a table Biostatistics 212 Lecture 7

Transcript of Organizing a project, making a table Biostatistics 212 Lecture 7.

Page 1: Organizing a project, making a table Biostatistics 212 Lecture 7.

Organizing a project, making a table

Biostatistics 212

Lecture 7

Page 2: Organizing a project, making a table Biostatistics 212 Lecture 7.

Housekeeping

• Final project– New instructions (1 file!)– New due date (Thur, December 8th, Midnight)

• Office hours– 12-1pm on 11/17, 11/22, 12/6

• Feedback about last week?

Page 3: Organizing a project, making a table Biostatistics 212 Lecture 7.

Today...

• How do you keep all those datasets, do files, and log files organized?

• Steps in making a Table

• Formatting a Table with Microsoft Word

• Formatting a Table with Microsoft Excel

Page 4: Organizing a project, making a table Biostatistics 212 Lecture 7.

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

Page 5: Organizing a project, making a table Biostatistics 212 Lecture 7.

Organizing your Stata files

• My system (it’s not perfect)1) Import data into Stata, and SAVE raw dataset

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

Page 6: Organizing a project, making a table Biostatistics 212 Lecture 7.

Raw data.xls

Raw data.dta

In Stata

Cut and paste

Clean data.dta

Data prep.do Data prep.log Table 1.do

Table 1.log

Table 1.xls

Cut and paste

My organizational scheme

Table 1.doc

Cut and paste

Page 7: Organizing a project, making a table Biostatistics 212 Lecture 7.

Raw data.xls

Raw data.dta

In Stata

Cut and paste

Clean data.dta

Data prep.do Data prep.log Table 1.doTable 2.do

Table 1.logTable 2.log

Table 1.xls Table 2.xls

Cut and paste

My organizational schemeTable 1.doc Table 2.doc

Cut and paste

Page 8: Organizing a project, making a table Biostatistics 212 Lecture 7.

Organizing your Stata files

• My system, Step 1

• Import data – Minimal pre-processing before importation– Save your raw file – this is the ONLY time you

should save a Stata dataset “manually” (i.e. not from a do file)

Page 9: Organizing a project, making a table Biostatistics 212 Lecture 7.

Organizing your Stata files

• My system, Step 2

• Do file to clean the data should:– Load the RAW data– Generate, modify and label variables as needed– Save the CLEAN data (save command in the do

file)– Log the output

Page 10: Organizing a project, making a table Biostatistics 212 Lecture 7.

Organizing your Stata files

• My system, Step 3

• Analysis do files should– Load the CLEAN data– Do the analysis– Log the output– EVERY number in every table, figure and in the

text should be in the logged output

Page 11: Organizing a project, making a table Biostatistics 212 Lecture 7.

Organizing your Stata files

• You will end up with:– 2 datasets

• Data, from Excel.dta

• Data.dta

– 1 do file used for cleaning• Data prep.do

– “x” do files used for analysis• 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

Page 12: Organizing a project, making a table Biostatistics 212 Lecture 7.

Organizing your Stata files

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

• Example

Page 13: Organizing a project, making a table Biostatistics 212 Lecture 7.
Page 14: Organizing a project, making a table Biostatistics 212 Lecture 7.

Organizing your Stata files

• What do you do if…• You want to try 2 different ways of doing something

– DON’T create more datasets

– DO add more variables in the Data Prep.do (agecat1, agecat2)

Page 15: Organizing a project, making a table Biostatistics 212 Lecture 7.

Organizing your Stata files

• What do you do if…• You can’t remember what you did

– Just look up the correct do file/log file and see

Page 16: Organizing a project, making a table Biostatistics 212 Lecture 7.

Organizing your Stata files

• What do you do if…• You can’t remember why you did it

– DOCUMENT your reasoning with comments in both data prep and analysis do files

– Remember how to insert comments:* Comment on 1 line only

/* Comment on

multiple lines */

Page 17: Organizing a project, making a table Biostatistics 212 Lecture 7.

Organizing your Stata files

• What do you do if…• You need to redo with new data

– Import the new data, save over the RAW dataset

– Rerun your Data Prep.do file

– Rerun your analysis do files

Page 18: Organizing a project, making a table Biostatistics 212 Lecture 7.

Organizing your Stata files

• What do you do if…• You need to redo with new age categories, etc

– Fix your Data Prep.do file

– Rerun your Data Prep.do file

– Rerun your analysis do files

Page 19: Organizing a project, making a table Biostatistics 212 Lecture 7.

Organizing your Stata files

• What do you do if…• You need to redo with new analytic approach

– Fix your analysis do file

– Rerun your analysis do file

Page 20: Organizing a project, making a table Biostatistics 212 Lecture 7.

Organizing your Stata files

• Questions?

Page 21: Organizing a project, making a table Biostatistics 212 Lecture 7.

Tables

• Two main purposes– Present the facts compactly

– Provide side-by-side comparisons

• Six main components:– Title, row heading, column headings

– Rows

– Data

– Footnotes

Browner, W. Publishing and Presenting Clinical Research

Page 22: Organizing a project, making a table Biostatistics 212 Lecture 7.

Steps to making a Table

• Decide what the Table will be about

• Make the dummy table– Do this FIRST!!

• Write a do file that will produce each number you need

• Copy and paste the data in (if possible)

• Format so it looks nice

Page 23: Organizing a project, making a table Biostatistics 212 Lecture 7.

Steps to making a Table

• Deciding what the Table will be about– I like to sketch it out first– Logical flow

• Table 1 describes the sample (stratified by a predictor?)

• Table 2+ explores bivariate relationship of main predictor with the outcome

• Table 3+ explores results of adjusting for confounders

• Other Tables, Figures for interactions, etc.

Page 24: Organizing a project, making a table Biostatistics 212 Lecture 7.

Steps to making a Table

• Make the dummy table first– Makes you specify what you actually want!– Guides the analysis– Excel or Word

Page 25: Organizing a project, making a table Biostatistics 212 Lecture 7.

Steps to making a Table

• Write a do file that will produce each number you need– Iterative process, as you know

Page 26: Organizing a project, making a table Biostatistics 212 Lecture 7.

Steps to making a Table

• 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

Page 27: Organizing a project, making a table Biostatistics 212 Lecture 7.

Steps to making a Table

• Format it so it looks nice– Choose a journal you like, copy the format!

• Note horizontal lines, not vertical ones…

• Double-space your version

• Footnote as you go - *, †, ‡, §, ║, ¶

– Create a template

Page 28: Organizing a project, making a table Biostatistics 212 Lecture 7.

Word vs. Excel for Tables

• Stata Word– Fewer steps, fewer files– But…

• more cells to create

• formatting less flexible

• Cut and Paste doesn’t work so well

Page 29: Organizing a project, making a table Biostatistics 212 Lecture 7.

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)

– EXAMPLE

Page 30: Organizing a project, making a table Biostatistics 212 Lecture 7.

Summary

• It’s worth putting thought into your file organization

• Document everything you do!

• Mock up your table before doing the analysis

• Make your tables clear, and pretty