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
I want to regress the cumulative returns for each month, using*the most recent available data for all other variables.This is what my data looks like for one particular stock with the id 10104 (id variable is PERMNO): …
Suest after a list?Dear all I have a list of coefficient and standard error averages (following my previous post 15766…
Age calculated from months and yearsHi, I know that many questions have been posted about working with dates in Stata. I have not been …
How can I convert Variable names into the value of a new variable - in Stata?Dear All, I have a dataset that looks like this: year a b c ... 2000 value value value 20…
Store variable names for specific conditionHi all, I wonder if its possible save or store a list of variable names with a specific condition, …
Subscribe to:
Post Comments (Atom)
0 Response to creating a variable from multiple string variables
Post a Comment