To keep it simple, I've replicated the issue using nlsw88.dta (the categorising is for illustrative purposes only). Tabulating the variable reveals missing categories - categories 1 and 4 in this example. I use inlist() as the preferences on which the new variable are based are not in order of the value labels.
Code:
sysuse nlsw88.dta. (NLSW, 1988 extract) // create categorical variable according to specific industry functions gen bus = 1 if inlist(industry, 1, 2, 4, 5, 6, 10) // all of subset 1 replace bus = 2 if inlist(industry, 1, 2, 4) // part a of subset 1 replace bus = 3 if inlist(industry, 5, 6, 10) // part b of subset 1 replace bus = 4 if inlist(industry, 3, 7, 8, 9, 11, 12) // all of subset 2 replace bus = 5 if inlist(industry, 3, 7, 11) // part a of subset 2 replace bus = 6 if inlist(industry, 8, 9, 12) // part b of subset 2 tab bus, miss
Code:
bus | Freq. Percent Cum. ------------+----------------------------------- 2 | 388 17.28 17.28 3 | 440 19.59 36.87 5 | 1,045 46.53 83.39 6 | 359 15.98 99.38 . | 14 0.62 100.00 ------------+----------------------------------- Total | 2,246 100.00
0 Response to Why do I have missing categories from a newly created categorical variable
Post a Comment