*Biostata 212: lecture 3 * data cleaning notes cd "/Users/kristenaiemjoy/Box Sync/_Teaching/Biostat 212/Biostat212.2018/Lectures/3. Cleaning" *import acupuncture_raw data set import delimited acupuncture_raw.csv, clear ***Rename variable rename f1 hfreq_bl * add a label label variable hfreq_bl "headache score baseline" *label values tab group label define grouplabel 1 "intervention" 0 "control" label values group grouplabel tab group numlabel, add tab group labelbook *Outliers spikeplot age sum age, detail list id sex age if age >120 *one person's age (id = 363) is actually 52, i checked his original file replace age = 52 if id==363 spikeplot age sum age *missing data misstable sum sum posths mvdecode _all, mv(-99) sum posths *Generagte new variables gen one = 1 gen newid = _n, before(id) drop newid gen blank = . gen severemigraine = (migraine==1 & basehs>50) browse migraine basehs severemigraine gen severemigrainepost = (migraine==1 & posths>50) replace severemigrainepost = . if posths==. browse migraine posths severemigrainepost **creating quantiles browse basehs xtile basehsQ = basehs, nq(4) bysort basehsQ: sum basehs **generate row mean egen meanhs = rowmean(basehs posths oneyrhs) egen meanhs2 = mean(basehs) browse basehs posths oneyrhs meanhs **generate new age variable recode age (min/49 = 1 "less than 50") (50/max = 2 "50 and older"), gen(age2) recode age (min/49 = 1 ) (50/max = 2 ), gen(age3) browse age age2 age3 **string to categorical variables browse withdrawal_reason encode withdrawal_reason, gen(dropout) numlabel, add tab dropout