* BIOSTAT 212: Introduction to Statistical Computing in Clinical Research * SUMMER 2017, TICR * Commands used in lecture and lab ****************************************************************************** * SESSION 1: Introduction, setting up .do files, basic exploring ****************************************************************************** clear all //clears all open data, variables, labels, matrices, memory and close all open files, graph windows, etc. pwd // 'print working directory.' use it to check the current working directory. cd "/folder/path/here" //change working directory to where you want to save/import files from capture log close // Close any existing log files log using lab1.log//open a log file log using lab1.log, replace //open an exisitng log file and replace it log using lab1.log, append //open an existing log file and append it help dta_examples //information of built-in "system" data sets sysuse "filename.dta" // open a built-in "system" like cancer.dta sysuse "filename.dta", clear // open a built-in "system" like cancer.dta and clear out any open data sets browse // browse data in data editor br // browse shorthand browse "varlist" //browse specific variables describe // describes dataset and variables des //shorthand summarize //summarize data set (CONTINUOUS VARIABLES) sum //shorthand sum "varlist" //summarize specific variables count // counts the number of observations tabulate "varname" // tabulate 1 variable (CATEGORICAL VARIBALES) tab //shorthand tab "varname1" "varname2" // tabulate 2 variables tab "varname1" "varname2", row // tabulate 2 variables with row percentages tab "varname1" "varname2", col // tabulate 2 variables with column percentages log close //save and close log file ****************************************************************************** * SESSION 2: Immediate commands and more exploring ****************************************************************************** di //use stata like a calculator di log(125) di 3+4 di 10000/8 di runiform(1,1000) //random number between 1 and a 1000 webuse "datasetname" //download dataset from the web ds // check out variable names only db "command" //open dialog box for a command db tabulate //for example list "varname1" "varname2" //list specific variables list in 1/3 //list first 3 variables list in -50/l //list last 50 variables gsort- "varname" // sort decending gsort+ "varname" // sort ascending codebook "varname" // shows the contents of the variable, range inspect "varname" //shows mini histogram summarize //summarize data set (CONTINUOUS VARIABLES) sum //shorthand sum "varlist" //summarize specific variables sum "varname", detail //detailed summary with median and percentiles bysort "varname1": sum "varname2" //summarize variable2 by a categorical variable1 duplicates report //report any duplicate observations duplicates report "varname" //report duplicates for a specific variable isid "varname" //does varname uniquely identify variables. no return value means "yes"