Hello statalist,

I hope everyone are doing good.

I have a question a bout: how to create a categorical variable from another categorical variables? ... and I hope you can help me with this

Let me first explain the main variables that I have, they are 28 in total (
one variable for each tooth). Each of these variables have four categories that summarise the type & number of dental caries in the tooth. e.g.,



HTML Code:
CauseDCaries in 47 | Freq. Percent Cum.
--------------------------------------+-----------------------------------
Visual caries (non cavitated) | 92 33.95 33.95
  Filled, recurrent (cavitated) | 7 2.58 36.53
      Cavitated dentine caries | 167 61.62 98.15
Decayed (Pulp involvement) | 5 1.85 100.00
------------------------------+-----------------------------------
Total | 271 100.00

Again, this is for only one tooth and I have another 27 similar variables.

Now, I need to create a new variable that equals the sum of teeth in each of the four categories of dental caries in all of the 28 teeth that I have.

I have tried:

HTML Code:
​​​​​​egen SUM_CauseDCaries = rowtotal(CauseDCaries17 CauseDCaries16 CauseDCaries15 CauseDCaries14 CauseDCaries13 CauseDCaries12 CauseDCaries11 CauseDCaries21 CauseDCaries22 CauseDCaries23 CauseDCaries24 CauseDCaries25 CauseDCaries26 CauseDCaries27 CauseDCaries37 CauseDCaries36 CauseDCaries35 CauseDCaries34 CauseDCaries33 CauseDCaries32 CauseDCaries31 CauseDCaries41 CauseDCaries42 CauseDCaries43 CauseDCaries44 CauseDCaries45 CauseDCaries46 CauseDCaries47), missing
this would give me total without the categories, as below:


HTML Code:
Sum of
CauseDCarie
s in all
teeth
(rowtotal) Freq. Percent Cum.

3 79 8.40 8.40
4 8 0.85 9.26
5 87 9.26 18.51
6 49 5.21 23.72
7 3 0.32 24.04
8 41 4.36 28.40
9 35 3.72 32.13
10 65 6.91 39.04
11 24 2.55 41.60
12 30 3.19 44.79
13 26 2.77 47.55
14 31 3.30 50.85
15 35 3.72 54.57
16 24 2.55 57.13
17 17 1.81 58.94
18 39 4.15 63.09
19 19 2.02 65.11
20 48 5.11 70.21
21 30 3.19 73.40
22 6 0.64 74.04
23 25 2.66 76.70
24 16 1.70 78.40
25 37 3.94 82.34
26 18 1.91 84.26
27 11 1.17 85.43
28 9 0.96 86.38
29 8 0.85 87.23
30 18 1.91 89.15
31 9 0.96 90.11
32 6 0.64 90.74
33 8 0.85 91.60
34 5 0.53 92.13
35 14 1.49 93.62
36 10 1.06 94.68
37 2 0.21 94.89
38 9 0.96 95.85
40 8 0.85 96.70
41 3 0.32 97.02
42 2 0.21 97.23
43 4 0.43 97.66
44 3 0.32 97.98
45 2 0.21 98.19
47 1 0.11 98.30
48 3 0.32 98.62
49 1 0.11 98.72
50 1 0.11 98.83
51 2 0.21 99.04
53 1 0.11 99.15
54 1 0.11 99.26
55 1 0.11 99.36
56 1 0.11 99.47
57 1 0.11 99.57
58 1 0.11 99.68
62 1 0.11 99.79
66 1 0.11 99.89
94 1 0.11 100.00

Total 940 100.00



I also tried this,

HTML Code:
gen SUM_CauseDCaries1= (CauseDCaries17 + CauseDCaries16 + CauseDCaries15 + CauseDCaries14 + CauseDCaries13 + CauseDCaries12 + CauseDCaries11 + CauseDCaries21 + CauseDCaries22 + CauseDCaries23 + CauseDCaries24 + CauseDCaries25 + CauseDCaries26 + CauseDCaries27 + CauseDCaries37 + CauseDCaries36 + CauseDCaries35 + CauseDCaries34 + CauseDCaries33 + CauseDCaries32 + CauseDCaries31 + CauseDCaries41 + CauseDCaries42 + CauseDCaries43 + CauseDCaries44 + CauseDCaries45 + CauseDCaries46 + CauseDCaries47)
Both did not work I guess I should've define the four categories of dental caries before?

I hope I was able to explain this question well.
p.s. I am using STATS/SE 15.1

Thanx a lot!