I'm using the levelsof
command to identify unique values of a variable and stick them into a macro. Then later on I'd like to use those values in the macro to select records from another dataset that I'll load.
What i have in mind is something along the following lines:
keep if inlist(variable, "`macrovariable'")
Does that work? And is there another more efficient option? I could do this easily in R (because vectors are easier to work with than macros), but this project requires Stata.
Clarification:
if I have a variable with three unique values, a
, b
and c
, I want to store those in a macro variable so I can later take another dataset and select observations that match one of those values.
Normally can use the inlist
function to do this manually, but I'd like to soft-code it so I can run the program with different sets of values. And I can't get the inlist
function to work with macros.