************************ ** Training 2 do file ** ************************ ** may 26, 2021 ******** ************************ cd "E:\My Drive\Heal STATA Trainings\Training 2\data" use "Training 2 data", clear **************************************** * Objective 1 Conditional Statements ** **************************************** ** use if statement ** sum earnings if male==1 sum earnings if male==0 ** use and statement ** * average hours worked for males that are business majors * sum hours if male==1 & major=="business" ** use or statement ** * average hours worked for those who are men or those who are married * sum hours if married==1 | male==1 ** conditional tabulations ** tab age if education>12 ** conditional count ** count if education >12 ** conditional sum ** sum earnings if major=="business" sum earnings if major~="business" **************************************** * Objective 2 Manipulate the data ** **************************************** * generate new variable * gen lit=1 * generate new variable based on a function of other variables * gen age2=age^2 sum age2 gen hours_year=hours*weeks sum hours_year *replace variable* *dummy variables* gen female=0 replace female=1 if gender=="female" * create missing data * // those that work more than 80 hours per week are miscoded and should be missing values replace hours=. if hours>80 * create a single race variable * gen race=" " replace race="white" if white==1 replace race="black" if black==1 replace race="hispanic" if hispanic==1 replace race="other race" if other_race==1 tab race