I want to loop over all values of a local varlist and check if a variable of that name is present in the dataset. If it is I want to add it to a second varlist that I can use for my next step. To rephrase: I have a predefined list of possible variable names of which some but not all are present in the dataset and I want to identify only those that are present.
Code:
local vlist0 foo bar dar local vlist1 foreach item of local vlist0 { capture confirm variable `item' if _rc==0 local vlist1 `vlist1' `item' display "`vlist1'" }
0 Response to check if variable is present and append to local varlist
Post a Comment