Manipulating Locals
Remove duplicates
Use the
list uniqmacro list functionalitylocal vars state county county loc nodups : list uniq varsdisplay `nodups' . state county
Add/Remove Elements
Removing elements of a local is easy.
Create a local (
minus) with the elements you want to removelocal vars a b c local minus adisplay `vars' . a b cUse the macro list functionality:
listwith a minuslocal vars : list vars - minusdisplay `vars' . b c
Union and intersection
Another useful tool is taking the common and different elements between two locals
local x state county
local y county tract
- For unions use
|(like in x “or” y)local union : list x | ydisplay `union' . state county tract - For intersections use
&(like in x “and” y)local intersection : list x & ydisplay `intersection' . county
Sorting
Sometimes we want to sort elements of a local
Use
sortmacro list functionalitylocal unordered b c a local ordered : list sort unordereddisplay `ordered' . a b c