clear set memory 40m use intuss, clear *indiv = individual identifier *eventday = day on which event occurred *sta = day before the start of the observation period *end = end of the observation period rename cutp1 sta rename cutp2 end *generate the exposure group cut points, *name them excp1, excp2, excp3 etc... generate excp1 = agep3 + 13 generate excp2 = agep3 + 27 generate excp3 = agep3 + 41 drop agep1 agep2 agep3 sex *put (number of exposure group cut points - 1) into a local macro named nexgr *(usually this will be the number of exposure groups) local nexgr = 2 *note that exposure group factors are generated as a list of increasing numbers, *ending with a zero 0,1,2,3,...,0 and you may need to use a recode function to correct them. *data are saved in semipar.dta before fitting the model. *day = list of all the event days by each individual *nevd = number of unique event days set more off generate id = _n compress save semipar, replace keep eventday rename eventday day count local nid = r(N) contract day drop _freq compress save day, replace generate id = 1 forvalues i = 2/`nid'{ app using day replace id = `i' if id>=. } compress joinby id using semipar drop id save semipar, replace erase day.dta *drop event days (in day) before the beginning or after the end of the observation period drop if sta>=day | end excp`i' & day <= excp`j' } *if necessary use a recode function to correct exgr here. *drop exposure group cut points, re-save the data in semipar.dta drop excp* compress save semipar, replace *fit the model xi: xtpoisson nevents i.exgr i.day, fe i(indiv) irr