**Lecture 5: Visualizing data cd "/Users/amandairish/Desktop/Biostat 212/Week 5" use "data/acupuncture.dta", clear * Create a histogram of health_bl histogram health_bl * Create a bar chart showing the mean of health_bl for the treatment vs. control groups graph bar (mean) health_bl, over(group) * Create a box plot for health_bl by group graph box health_bl, over(group) * Create a box plot for health_bl by sex and group graph box health_bl, over(sex) over(group) * Create a dot plot comparing f1, f2, and f5 dotplot f1 f2 f5 * Create a 2-way scatterplot of health_bl and basehs with a lowess line twoway scatter basehs health_bl || /// lowess basehs health_bl * Create a 2-way scatterplot of health_bl and basehs with a linear fit line twoway scatter basehs health_bl || /// lowess basehs health_bl || /// lfit basehs health_bl * Export a graphic as a *.png file (keep graph window open!) graph export "scatter_basehs_healthbl.png", replace //or could use graph export "scatter_basehs_healthbl", as(png) * Put the graphic into a Word document with putdocx putdocx clear putdocx begin putdocx paragraph, halign(center) putdocx image "scatter_basehs_healthbl.png" putdocx save "lecture_5_image", replace **************************************************************************** *Figure 1 twoway /// scatter posths acuptreatments if migraine==0 /// , msize(small) mcolor(black) || /// lfit posths acuptreatments if migraine==0 /// , lcolor(purple) || /// scatter posths acuptreatments if migraine==1 /// , msize(small) mcolor(red) || /// lfit posths acuptreatments if migraine==1 /// , lcolor(green) || /// , title (Figure 1) /// note () /// ytitle(PSH) /// xtitle(# acu) /// scheme(s2color) /// legend(order(2 "No migraine" 4 "Migraine")) /// saving("output/figure1.gph", replace) **************************************************************************** *Figure 2 twoway /// kdensity posths if no_acu==0 /// , lcolor(black) || /// kdensity posths if no_acu==1 /// , lcolor(black) || /// , yscale(on) /// graphregion(fcolor(stone) lcolor(none)) /// legend(order(1 "1 or more acupuncture treatments" /// 2 "No acupuncture treatments")size(medium)) /// ytitle("Density") /// xtitle("Post-study headache score") /// title(Figure 2: Distribution of headache score) /// saving("output/figure2.gph", replace)