/**********************************************/ /* Introduction to Stata - 22nd November 2017 */ /**********************************************/ /* The course will start at 10am on */ /* Wednesday 22nd November */ /* We look forward to meeting you then! */ /* The CASC team. */ /* In the meantime, you can check our */ /* website for more courses: */ /* www.ucl.ac.uk/stats-courses */ * this command does 5 times 5 di 5*5 generate gen age_months=age*12 gen bmi_35= bmi>34.99 gen id=_n gen bmi_cat=0 replace bmi_cat=1 if bmi>25.00 & bmi<=30.00 replace bmi_cat=2 if bmi>30.00 & bmi<=35.00 replace bmi_cat=3 if bmi>35.00 drop bmi_35 * or: | ^ ^2 ^3 gen age_2= age^2 * gen anxiety_total= (anxiety_1 + anxiety_2 egen anxiety_total= rowtotal(anxiety_1-anxiety_10) * labels label define bmi 0 "Underweight" 1 "Normal" 2 "Overweight" 3 "Obese" label values bmi_cat bmi label define noyes 0 "No" 1 "Yes" label values smoker noyes label values right_handed noyes * Dates gen new_dob_sibling= date(dob_sibling, "DM19Y") format new_dob_sibling %dD_m_CY *test * Go to: * www.tinyurl.com/statacasc log using "stataclass", append gen ID=_n label define noyes 0 "No" 1 "Yes" label define extrovert 0 "introvert" 1 "extrovert" label values extrovert extrovert gen new_examination_sibling= date(date_of_examination_sibling, "DM20Y") gen age_days= new_examination_sibling-new_dob_sibling gen age_sibling= age_days/365.25 gen height_m= height_sibling/100 gen bmi_sibling= weight_kg_sibling/ (height_m^2) gen anxiety_cat=0 replace anxiety_cat=1 if anxiety_total>15.00 & anxiety_total<=22.00 replace anxiety_cat=2 if anxiety_total>22.00 label define anxiety 0 "Low" 1 "Medium" 2 "High" label values anxiety_cat anxiety capture drop bmi_35 encode gender_strg, gen(newgender) gen body_fat_perc= real(body_fat) * Section 5 summarize sum su sum age sum age bmi su bmi if gender==0 su bmi if gender==1 sort gender by gender: sum bmi by gender, sort: sum bmi centile bmi, centile(25 50 75) tabulate tab tab bmi_cat tab bmi_cat if gender==0 by gender, sort: tab bmi_cat tab gender bmi_cat tab gender bmi_cat, row * Section 5 practicals sum resting_pulse_rate sum pulse_1min_running by smoker, sort: sum pre_intervention_bloodpressure by gender, sort: sum resting_pulse_rate