window push version 8.0 window push set more on window push log using 7.9.4.Framingham.ClassVersion.log, replace window push * 7.9.4.Framingham.ClassVersion.log window push * window push * Plot Kaplan-Meier cumulative CHD morbidity curves as a function of age. window push * Patients from the Framingham Heart Study enter the analysis when they window push * reach the age of their baseline exam. window push * window push use C:\WDDtext\2.20.Framingham.dta, clear window push histogram age, bin(39) fraction ylabel(0(.01).04) xlabel(30(5)65) window push more window push generate time= followup/365.25 window push label variable time "Follow-up in Years" window push generate exitage = age+time window push stset exitage, enter(time age) failure(chdfate) window push sts graph, by(sex) failure ytitle(Cumulative CHD Morbidity) xtitle(Age) /// window push ylabel(0(.1).8, angle(0)) legend(ring(0) position(11) col(1)) /// window push clcolor(blue pink) clwidth(medthick medthick) xlabel(30(10)90) noorigin window push more window push * window push * Calculate the logrank test corresponding to these morbidity functions window push * window push sts test sex window push * window push * Calculate the relative risk of CHD for men relative to women using window push * age as the time variable. window push * window push generate male = sex==1 window push stcox male window push * window push * Perform hazard regression with time dependent covariates for sex window push * window push tabulate chdfate male window push generate records = 1 window push replace records= 2 if age< 57 & exitage > 57 window push expand records window push sort id window push generate enter = age window push replace enter = 57 if id==id[_n-1] window push generate exit = exitage window push replace exit =57 if id==id[_n+1] window push generate fate=chdfate window push replace fate= 0 if id==id[_n+1] window push tabulate fate male window push generate male1 = male*(enter < 57) window push generate male2= male*(exit > 57) window push tabulate male1 male2 window push stset exit, id(id) enter(time enter) failure(fate) window push stcox male1 male2 window push lincom male1 - male2 window push log close