Hi all,
I am trying to replicate recode results using floor, int or ceil function, my focus is recode a big data base with age variable, for this reason I would like use this function, lamentably i get differents results in frequency, example:
I am trying to replicate recode results using floor, int or ceil function, my focus is recode a big data base with age variable, for this reason I would like use this function, lamentably i get differents results in frequency, example:
Code:
clear all set more off sysuse auto #delimit ; recode mpg (12/16= 1 12-16) (17/21= 2 17-21) (22/26= 3 22-26) (27/31= 4 27-31) (32/36= 5 32-36) (37/41= 6 37-41) (42/max= 7 34-max), gen(recodempg) ; #delimit cr tab recodempg RECODE of | mpg | (Mileage | (mpg)) | Freq. Percent Cum. ------------+----------------------------------- 12-16 | 14 18.92 18.92 17-21 | 29 39.19 58.11 22-26 | 20 27.03 85.14 27-31 | 7 9.46 94.59 32-36 | 3 4.05 98.65 37-41 | 1 1.35 100.00 ------------+----------------------------------- Total | 74 100.00 gen flormpg =4 * floor(mpg/4) tab flormpg flormpg | Freq. Percent Cum. ------------+----------------------------------- 12 | 10 13.51 13.51 16 | 25 33.78 47.30 20 | 16 21.62 68.92 24 | 12 16.22 85.14 28 | 7 9.46 94.59 32 | 3 4.05 98.65 40 | 1 1.35 100.00 ------------+----------------------------------- Total | 74 100.00 gen intempg =4 * int(mpg/4) tab intempg intempg | Freq. Percent Cum. ------------+----------------------------------- 12 | 10 13.51 13.51 16 | 25 33.78 47.30 20 | 16 21.62 68.92 24 | 12 16.22 85.14 28 | 7 9.46 94.59 32 | 3 4.05 98.65 40 | 1 1.35 100.00 ------------+----------------------------------- Total | 74 100.00 gen ceilmpg =4 * ceil(mpg/4) tab ceilmpg ceilmpg | Freq. Percent Cum. ------------+----------------------------------- 12 | 2 2.70 2.70 16 | 12 16.22 18.92 20 | 24 32.43 51.35 24 | 17 22.97 74.32 28 | 11 14.86 89.19 32 | 4 5.41 94.59 36 | 3 4.05 98.65 44 | 1 1.35 100.00 ------------+----------------------------------- Total | 74 100.00
Comment