Created
June 10, 2019 15:37
-
-
Save michaelewens/d45cef2b8b34d551d843e6d58d815434 to your computer and use it in GitHub Desktop.
Stata quotes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| clear | |
| * Dummy data | |
| set obs 4 | |
| gen name = "" | |
| replace name = "John a." if _n == 1 | |
| replace name = "Sarah b." if _n == 2 | |
| replace name = "Samuel c." if _n == 3 | |
| replace name = "Mike" if _n == 4 | |
| * Alterative variable for check | |
| gen name2 = name | |
| ************************ | |
| * NOPE! (ignores the first element b/c quotes are weird) | |
| local vlist "a." "b." "c." | |
| foreach v of local vlist { | |
| replace name = trim(subinstr(name, `"`v'"', "", .)) | |
| } | |
| * YUP! | |
| local vlist `" "a." "b." "c." "' | |
| foreach v of local vlist { | |
| replace name2 = trim(subinstr(name2, `"`v'"', "", .)) | |
| } | |
| count if name ~= name2 | |
| assert r(N) == 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment