I am trying to replace a variable if another variable BEGINS with a certain 2 number character.
CIPrctyrs | Freq. Percent Cum.
-------------------------------+-----------------------------------
010000 | 24 0.16 0.16
010101 | 1 0.01 0.17
010102 | 8 0.05 0.22
010504 | 6 0.04 0.26
010504 510808 | 1 0.01 0.27
010603 | 1 0.01 0.27
010801 | 1 0.01 0.28
010901 | 18 0.12 0.40
011001 | 5 0.03 0.43
011101 | 7 0.05 0.48
011202 | 10 0.07 0.55
018301 | 2 0.01 0.56
030103 | 2 0.01 0.57
030104 | 4 0.03 0.60
030201 | 2 0.01 0.61
030501 | 5 0.03 0.65
030601 | 11 0.07 0.72
040201 | 1 0.01 0.73
040401 | 3 0.02 0.75
040501 | 1 0.01 0.75
040601 | 1 0.01 0.76
090100 | 24 0.16 0.92
090101 | 21 0.14 1.06
Here is my output above.
For instance, anything starting with 01 would change to "Agriculture." Anything starting with a 03 to "Natural Resources."
The code may be something like,
"gen CIPrctyrs_words=""
replace CIPrctyrs_words="Agriculture" if strpos(CIPrctyrs, "01*")
Save for the asterisk, which is not in STATA language, but denotes anything after those numbers.
Thanks!
Anna
0 Response to Help with replacing a variable depending on the value of another variable
Post a Comment