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
Relative survival and relative excess risk (RER) using imputed dataHi everyone, Does anyone know how I can calculate relative survival (strs) and relative excess risk…
Estimating the gravity model using PPLM, general adviceHi, For my thesis I am intending to estimate a gravity model, looking at specifically the effect of…
Autocorrelation Diff in DiffHello, I am working on the following Diff in diff model: ln_sales = b0 + b1*treatment + b2*(treat…
Foreach and forevalues loopHi, I have a list of variables that look as follows: max_1 max_2 max_3. All the numbers in the vari…
covert date with two digital yearHi Friend, I need to convert the string date format, such as "22-Apr-18" to date format. It seems th…
Subscribe to:
Post Comments (Atom)
0 Response to Help with replacing a variable depending on the value of another variable
Post a Comment