Skip to content

Instantly share code, notes, and snippets.

@michaelewens
Created June 10, 2019 15:37
Show Gist options
  • Select an option

  • Save michaelewens/d45cef2b8b34d551d843e6d58d815434 to your computer and use it in GitHub Desktop.

Select an option

Save michaelewens/d45cef2b8b34d551d843e6d58d815434 to your computer and use it in GitHub Desktop.
Stata quotes
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