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
Related Posts with Help with replacing a variable depending on the value of another variable
Merge mulitple .csv filesI am using Stata 16.1 MP to merge six .csv files on neonatal, infant, and child mortality. I would l…
Remove part of a Text in observationHi guys, Below is a sample of my data. I would like to remove the "-TOT RETURN IND" in all the obser…
Number of timepoints for person fixed effectsIs there some sort of arbitrary number of timepoints needed in order to estimate person fixed effect…
xtivreg2 export first and second stage resultsAs the description of xtivreg2 says, it is the wrapper of ivreg2. But the "savefirst“ option of ivre…
Creating categorical summary values for cities annually, weighted/unweightedHi guys. New to running Stata for large groups. I'm working with IPUMs American Community Survey Da…
Subscribe to:
Post Comments (Atom)
0 Response to Help with replacing a variable depending on the value of another variable
Post a Comment