****************************************************************************** *SETTING UP ****************************************************************************** /* A working directory is an address to where your files are stored. Specifing working address in your .do file allows you to access files and data seemlessly every time you open run your .do file Windows uses \ to deliminate paths Mac uses / */ pwd // pwd stands for 'print working directory.' use it to check the current working directory. /* Now lets create a folder for this lab and change the directory to that folder: in Documents (or whatever directory you would like) create a folder for 'Biostat 212', inside 'Biostat 212' create a folder called 'Labs', inside 'Labs' create a folder for 'Lab 1' */ cd "/Users/kristenaiemjoy/Box Sync/_Teaching/Biostat 212/Biostat212.2018/Labs/Lab1" //modify filepath to the folder you just created /* HINT: you can copy and paste the desired filepath by using the drop down menu: File > Change Working Directory > Navigate to the Lab 1 folder */ * clear //clar any open data sets capture log close //close any open log files /* Stata can record your session into a file called a log file. A log file records both commands and output. Stata will not start a log automatically; you must tell Stata to record your session. Logs are recorded in a format called Stata Markup and Control Language (SMCL). The file can be printed or converted to plain text for incorporation into documents you create with your word processor. */ quietly log using biostat212_lab1.smcl, replace /*** # BIOSTAT 212: LAB 1 ###Your Name
__Intructions:__ Questions are in bold. Put your answer in italic. (Remember words surrounded by 2 underscores "__" will be __bold__ when using markDoc and words surrounded by 1 underscore "_" will be _italic_) Fill in you answer inside the _XX_ notation. (Replace the XX with your answer) ***/ /*** #Immediate commands Answer the following questions using immediate commands. Hint: you call immediate commands for math in Stata using "display" or "di" for short Here is an example: __What is 15+38?__ _35_ ***/ di 15+38 /*** __What is 107/8?__ _XX_ ***/ /*** __What is the square root of 863?__ _XX_ ***/ /*** __Find a random number between 1 and 15:__ _XX_ ***/ /*** __Find a random integer between 1 and 100:__ _XX_ ***/ ****************************************************************************** /*** #Opening a data set Start by opening one of Stata's built-in data sets. Check out the data that comes loaded into Stata with this command: ***/ help dta_examples /*** A description of the datasets can be found here: http://www.stata.com/manuals13/u1.pdf the command "sysuse" loads one of these built in data sets. Now, try loading the cancer.dta dataset ***/ sysuse cancer.dta ****************************************************************************** /*** #Exploring a data set: the basics ***/ /*** Start browsing the data set with the command "browse". Remember to type your commands after the end of the comment box so they will run in the MarkDoc __How many study participants are there?__ (count the rows of data) _XX_ ***/ /*** A quicker way to get the number of participants (or obervations we might say) is using the "describe" command. Try it out here: ***/ /*** __How many variables are there (columns)?__ _XX_ hint: describe can help you here too ***/ /*** The command "count" will also count the number of observations. You can also use count to give you the number of participants that meet a certain criteria. For example, this command tells you how many patients are alive: ***/ count count if died==0 /*** __How many study participants died?__ _XX_ hint: "codebook died" gived you informatiion about the "died" variable. From this command we know that 1 means the patient died, 0 means they are alive" ***/ /*** tabulate (tab for short) gives you a 2x2 table for 2 categorical variables. Here is an example: ***/ tab drug died /*** you can get row or column percentages by adding the ",row" or ",col" option: ***/ tab drug died, row /*** __What percent of study particpants died in the placebo drug group?__ _XX_ ***/ /*** __What percent of study particpants who died where in the placebo drug group?__ _XX_ ***/ /*** __What is the average(mean) age?__ _XX_ Hint: use the "summarize" (sum for short) command ***/ /*** __How old is the oldest person in the data set?__ _XX_ Hint: use sum again. ***/ ****************************************************************************** /*** #Generating a dynamic document with MarkDoc The markdoc command creates a PDF or word document from your log file. Make sure the name of the file after the command "markdoc" matches the name of your log file ***/ help markdoc //is a great help file with lots of useful options /*** first close your log file ***/ quietly log close //the quietly prefix will not show the log close output in the markdoc print out *Play around with the different markdoc options. (remove the preceding asteric to run the command) *markdoc biostat212_lab1, replace export(pdf) //exports a pdf file *markdoc biostat212_lab1, replace export(docx) //exports a docx file markdoc biostat212_lab1, replace statax export(pdf) //adds stata syntax highlighting (only works on PDFs) *markdoc biostat212_lab1, replace style(formal) export(docx) //you can change the style with the "style()" option. Look at the markdoc help file for more options. *markdoc biostat212_lab1, replace statax date export(pdf) //the date option includes the data at the top *markdoc biostat212_lab1, replace statax date author(Kristen Aiemjoy) title(Biostat 212: Lab 1) export(pdf) //You can also specify the document title and author in the markdoc command