I am working with NHANES examination data and would like to create a variable that includes the sum from many other variables in the same data set. All 30 are string variables. Example of two below.
. describe ohx02ctc ohx03ctc
storage display value
variable name type format label variable label
----------------------------------------------------------------------
ohx02ctc str1 %9s Coronal Caries: Tooth Count #2
ohx03ctc str1 %9s Coronal Caries: Tooth Count #3
Using tab (below) we can see that the code or value for this variable (ohx03ctc) is a letter, for example the letter Z represents a diseased permanent tooth surface on tooth number 02. Next to the Z is a frequency of 127, meaning that from the whole number of persons examined, 127 had a “Z” or diseased permanent tooth surface02. Using tab on the next tooth 03 will also give me the same series of letters and same meaning (see below).
I would like to create a variable that adds the numerical values of both letters and will provide me with the result, for example, “Z” from tooth 02 is 127, and “Z” from tooth 03 is 125, combined “Z” should add to 127 + 125 = 152
Your help is appreciated,
Victor
. tab ohx02ctc
Coronal |
Caries: |
Tooth Count |
#2 | Freq. Percent Cum.
------------+-----------------------------------
E | 758 9.36 9.36
F | 1,747 21.57 30.93
J | 77 0.95 31.88
M | 23 0.28 32.16
P | 677 8.36 40.52
Q | 30 0.37 40.89
R | 9 0.11 41.00
S | 2,701 33.35 74.35
U | 1,945 24.01 98.36
Y | 6 0.07 98.43
Z | 127 1.57 100.00
------------+-----------------------------------
Total | 8,100 100.00
. tab ohx03ctc
Coronal |
Caries: |
Tooth Count |
#3 | Freq. Percent Cum.
------------+-----------------------------------
D | 1 0.01 0.01
E | 645 7.96 7.98
F | 2,283 28.19 36.16
J | 84 1.04 37.20
M | 16 0.20 37.40
P | 733 9.05 46.44
Q | 31 0.38 46.83
R | 78 0.96 47.79
S | 3,144 38.81 86.60
U | 955 11.79 98.40
X | 2 0.02 98.42
Y | 3 0.04 98.46
Z | 125 1.54 100.00
------------+-----------------------------------
Total | 8,100 100.00
. list ohx02ctc ohx03ctc
+---------------------+
| ohx02ctc ohx03ctc |
|---------------------|
1. | U U |
2. | U U |
3. | F E |
4. | S F |
5. | U S |
|---------------------|
6. | S S |
7. | P P |
8. | S S |
9. | S M |
10. | E E |
|---------------------|
11. | E S |
12. | P P |
13. | F F |
14. | F F |
15. | F F |
|---------------------|
16. | S S |
17. | U U |
--Break--
r(1);
Related Posts with creating a variable from multiple string variables
quarter, month, week variables representing their sequenceHi all I have date variable of the format ----------------------- copy starting from the nex…
How to calculate average value of a variable at each clusterHello, have a look at the below data Code: 360002 0 360020 7 360024 7 360037 0 360041 0 3600…
preparing summary statistics tablehello community members, I have panel data for 6 years and have 54 variables in it. I want to prepar…
Entropy Balancing in Panel Data SettingHi everyone, I want like to quantify a treatment effect in a model by measuring the differential eff…
Combining datesHey, I have the following dataset: Code: * Example generated by -dataex-. To install: ssc install…
Subscribe to:
Post Comments (Atom)
0 Response to creating a variable from multiple string variables
Post a Comment