Suppose I have the following data:
1. For variable t, I have 7 categories, e.g., A++ (1), A+ (2), A (3), A- (4), B (5), C (6), and C- (7). Missing data are denoted as "-". I want to recode the string variable t into numerical variable, say t1, with values denoted in the corresponding parenthesis, and "-" are replaced by the standard ".".
2. Similarly, for gz variable, I want to construct a numeric variable gz1 with "N"/"Y" replaced by 0/1, respectively.
Any suggestions?
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str5 t str1 gz "C " "Y" "A++ " "N" "B " "N" "A+ " "N" "C " "Y" "A " "N" "A- " "N" "C " "N" "A " "N" "- " "Y" "C " "N" "B " "N" "C- " "N" end
2. Similarly, for gz variable, I want to construct a numeric variable gz1 with "N"/"Y" replaced by 0/1, respectively.
Any suggestions?
Comment