Example 1:
Code:
sysuse auto, clear local car = "AMC Pacer" gen x = cond(make == "`car'", 1, 0)
If I want to scale up from here I can do something like:
Example 2:
Code:
sysuse auto, clear local car = "AMC Pacer" gen x = cond(make == "`car'" | make == "Buick Opel", 1, 0)
local car = "AMC Pacer|Buick Opel" or local car = "AMC Pacer" "Buick Opel"
Is it possible to scale my macro?
I can see a way to do with a loop e.g.,
Code:
gen x = 0 foreach i in "AMC Pacer" "Buick Opel"{ replace x = 1 if make == "`i'" }
0 Response to Evaluating whether a vector of strings is in a df
Post a Comment