Code:
clear set obs 3 generate diagnosis_year = 1980 in 1 replace diagnosis_year = 1975 in 2 replace diagnosis_year = 1999 in 3 generate death_year= 2000 in 1 replace death_year = 1985 in 2 replace death_year = 1999 in 3 foreach num of numlist 1981 (5) 1995 { display " ******* " _n "period: " `num' "-" `num'+4 _n count if (diagnosis_year<=(`num'+4) & death_year>=`num') local Alive`num'_``num'+4' = r(N) macro dir } local population1981 55 /* will normlay be drawn from at macro outside the foreach loop*/ local population1982 66 local population1983 77 display `population`num'' display `population `num'+1' display `population =(`num'+4)' display "population" `num'+10 _n _n }
Comment